Skip to content

Commit 6d56327

Browse files
authored
Update tests and Jackson dependency version (#72)
1 parent ee0ce6e commit 6d56327

File tree

4 files changed

+69
-40
lines changed

4 files changed

+69
-40
lines changed

Tests/FilewatcherTests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>com.fasterxml.jackson.core</groupId>
3030
<artifactId>jackson-databind</artifactId>
31-
<version>2.9.10.3</version>
31+
<version>[2.9.10.4,)</version>
3232
</dependency>
3333
<dependency>
3434
<groupId>junit</groupId>

Tests/FilewatcherTests/src/org/eclipse/codewind/filewatchers/test/tests/AbstractTest.java

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public void after() {
9696
}
9797

9898
int filesToDeleteTotal = filesToDelete.size();
99+
log.out("* Deleting " + filesToDeleteTotal + " files. ");
99100

100101
int attempts = 0;
101102
while (filesToDelete.size() > 0 && attempts < 50) {
@@ -113,8 +114,10 @@ public void after() {
113114
attempts++;
114115
}
115116

116-
log.out("* Deleting " + filesToDeleteTotal + " files. ");
117-
117+
// Wait 10 seconds after a test run to allow cleanup operations in the
118+
// filewatcher to occur (this causes issues when running on Jenkins due to
119+
// presumed slower I/O vs a laptop SSD).
120+
CodewindTestUtils.sleep(10 * 1000);
118121
}
119122

120123
final PostRequestListFromWatcher changeList = CodewindTestState.getInstance().getChangeListFromWatcher();
@@ -353,24 +356,7 @@ void createRandomDirectoryStructure(List<File> directories, List<File> files, Lo
353356
Collections.shuffle(directories);
354357

355358
// Sort ascending by the number of / in the path
356-
Collections.sort(directories, (a, b) -> {
357-
int slashCountA = 0;
358-
int slashCountB = 0;
359-
360-
for (int x = 0; x < a.getPath().length(); x++) {
361-
if (a.getPath().charAt(x) == File.separator.charAt(0)) {
362-
slashCountA++;
363-
}
364-
}
365-
366-
for (int x = 0; x < b.getPath().length(); x++) {
367-
if (b.getPath().charAt(x) == File.separator.charAt(0)) {
368-
slashCountB++;
369-
}
370-
}
371-
372-
return slashCountA - slashCountB;
373-
});
359+
sortDirectoriesAscendingBySlashes(directories);
374360

375361
for (File dir : directories) {
376362
if (!dir.exists() && !dir.mkdirs()) {
@@ -410,6 +396,29 @@ void createRandomDirectoryStructure(List<File> directories, List<File> files, Lo
410396

411397
}
412398

399+
/** Sort ascending by the number of / in the path */
400+
void sortDirectoriesAscendingBySlashes(List<File> dirList) {
401+
Collections.sort(dirList, (a, b) -> {
402+
int slashCountA = 0;
403+
int slashCountB = 0;
404+
405+
for (int x = 0; x < a.getPath().length(); x++) {
406+
if (a.getPath().charAt(x) == File.separator.charAt(0)) {
407+
slashCountA++;
408+
}
409+
}
410+
411+
for (int x = 0; x < b.getPath().length(); x++) {
412+
if (b.getPath().charAt(x) == File.separator.charAt(0)) {
413+
slashCountB++;
414+
}
415+
}
416+
417+
return slashCountA - slashCountB;
418+
});
419+
420+
}
421+
413422
void buildRandomDirectoryStructure(int numFiles, float newDirPercent, long randomNumberSeed, File parent,
414423
List<File> outDirectories, List<File> outFiles) {
415424

Tests/FilewatcherTests/src/org/eclipse/codewind/filewatchers/test/tests/FilewatcherTests.java

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,27 +309,49 @@ public void testCanDeleteAfterUnWatch() {
309309

310310
waitForEventsFromFileList(files, EventType.CREATE, p1);
311311

312-
for (File f : files) {
313-
deleteFile(f);
314-
optionalArtificialDelay();
312+
while (files.size() > 0) {
313+
314+
// Delete files 10 at a time
315+
List<File> filesRemovedInIteration = new ArrayList<>();
316+
int count = 10;
317+
while (count > 0 && files.size() > 0) {
318+
File f = files.remove(0);
319+
filesRemovedInIteration.add(f);
320+
deleteFile(f);
321+
count--;
322+
}
323+
324+
if (filesRemovedInIteration.size() > 0) {
325+
waitForEventsFromFileList(filesRemovedInIteration, EventType.DELETE, p1);
326+
optionalArtificialDelay();
327+
}
328+
315329
}
316-
waitForEventsFromFileList(files, EventType.DELETE, p1);
317330

318331
List<File> dirsToDelete = new ArrayList<>(excludeParentDirFromList(dirs, p1));
332+
sortDirectoriesAscendingBySlashes(dirsToDelete);
333+
Collections.reverse(dirsToDelete); // Flip to descending by number of slashes
334+
319335
while (dirsToDelete.size() > 0) {
320336

321-
for (Iterator<File> it = dirsToDelete.iterator(); it.hasNext();) {
322-
File f = it.next();
323-
f.delete();
324-
if (!f.exists()) {
337+
// Delete at most 10 directories at a time
338+
List<File> filesRemovedInIteration = new ArrayList<>();
339+
for (Iterator<File> it = dirsToDelete.iterator(); it.hasNext() && filesRemovedInIteration.size() < 10;) {
340+
File dir = it.next();
341+
dir.delete();
342+
if (!dir.exists()) {
343+
filesRemovedInIteration.add(dir);
325344
it.remove();
326-
optionalArtificialDelay();
327345
}
328346
}
329347

330-
}
348+
// After each set of 10, wait for them
349+
if (filesRemovedInIteration.size() > 0) {
350+
waitForEventsFromFileList(excludeParentDirFromList(filesRemovedInIteration, p1), EventType.DELETE, p1);
351+
optionalArtificialDelay();
352+
}
331353

332-
waitForEventsFromFileList(excludeParentDirFromList(dirs, p1), EventType.DELETE, p1);
354+
}
333355

334356
boolean canDelete = p1.getLocalPathToMonitor().delete();
335357
assertTrue(canDelete);
@@ -637,7 +659,7 @@ public void testRandomFileWritesAcrossMultipleSimultaneousProjects() {
637659

638660
List<File> filesDeleted = new ArrayList<>();
639661

640-
while (fileListInProject.size() > 0 && filesDeleted.size() < 20) {
662+
while (fileListInProject.size() > 0 && filesDeleted.size() < 10) {
641663
Collections.shuffle(fileListInProject);
642664
File fileToDelete = fileListInProject.remove(0);
643665
filesDeleted.add(fileToDelete);
@@ -646,10 +668,11 @@ public void testRandomFileWritesAcrossMultipleSimultaneousProjects() {
646668
projectToFiles.remove(ptw.getProjectID());
647669
}
648670

649-
assertTrue(fileToDelete.delete());
671+
deleteFile(fileToDelete);
650672
}
651673

652674
waitForEventsFromFileList(filesDeleted, EventType.DELETE, ptw);
675+
optionalArtificialDelay();
653676

654677
}
655678

Tests/MockCwctlSync/src/org/eclipse/codewind/mockcwctl/MockCwctlMain.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ private static void innerMain(String[] args) throws JsonbException, IOException,
201201
for (String watchedFile : pwJson.getFilesToWatch()) {
202202
Path watchedFilePath = Paths.get(watchedFile);
203203
if (Files.exists(watchedFilePath)) {
204-
System.out.println("added:" + watchedFilePath); // TODO: REMOVE
205204
allFiles.add(new WalkEntry(watchedFilePath, Files.getLastModifiedTime(watchedFilePath).toMillis()));
206205
}
207206
}
@@ -429,9 +428,9 @@ private static void writeJsonDB(List<WalkEntry> allFiles, Path previousStateJson
429428
try {
430429
fe.setModification(Files.getLastModifiedTime(e.path).toMillis());
431430
} catch (IOException e1) {
432-
System.err.println("Exception on get modificiation - " + e1.getClass().getSimpleName() + ": "
433-
+ e1.getMessage() + ". Ignoring file.");
434-
return null;
431+
System.err.println("Exception on get modification - " + e1.getClass().getSimpleName() + ": "
432+
+ e1.getMessage() + ". Not updating the modification time.");
433+
fe.setModification(e.modificationTime);
435434
}
436435
fe.setPath(e.path.toString());
437436
return fe;
@@ -459,8 +458,6 @@ private static List<WalkEntry> walkDirectory(Path directoryParam) throws IOExcep
459458
Files.list(curr).forEach(e -> {
460459
try {
461460

462-
// TODO: REmove me
463-
System.out.println("thing: " + e);
464461
result.add(new WalkEntry(e, Files.getLastModifiedTime(e).toMillis()));
465462
} catch (IOException e1) {
466463
throw new RuntimeException(e1);

0 commit comments

Comments
 (0)