Skip to content

Commit

Permalink
Fixed test failures related to file watcher and corrected logic in fi…
Browse files Browse the repository at this point in the history
…le watcher (eclipse-che#2097)

* che#2006: added recursive setting up directory watchers

Signed-off-by: Dmitry Kuleshov <dkuleshov@codenvy.com>

* che#2006: corrected thread pool size in test


Signed-off-by: Dmitry Kuleshov <dkuleshov@codenvy.com>
  • Loading branch information
Dmitry Kuleshov authored Aug 15, 2016
1 parent 42457f4 commit 839f2f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ private void setupDirectoryWatcher(Path directory) throws IOException {
for (Path entry : entries) {
watchedDirectory
.addItem(new DirectoryItem(entry.getFileName(), Files.isDirectory(entry), getLastModifiedInMillis(entry)));

if (Files.isDirectory(entry)) {
setupDirectoryWatcher(entry);
}
}
}
watchedDirectories.put(directory, watchedDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ public void testDeleteProject() throws Exception {

@Test
public void testDeleteProjectsConcurrently() throws Exception {
int threadNumber = 100;
int threadNumber = 5 * (Runtime.getRuntime().availableProcessors() + 1);
ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
CountDownLatch countDownLatch = new CountDownLatch(threadNumber);
List<Future<ContainerResponse>> futures = new LinkedList<>();
Expand Down Expand Up @@ -981,6 +981,8 @@ public void testDeleteProjectsConcurrently() throws Exception {
for (Future<ContainerResponse> future : futures) {
assertEquals(future.get().getStatus(), 204, "Error: " + future.get().getEntity());
}

executor.shutdown();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ public void watchesCreateDirectoryStructure() throws Exception {
assertEquals(newHashSet(created), newHashSet(createdEvents.getAllValues()));
}

@Test
public void watchesCreatedSubDirectoriesRecursively() throws Exception {
FileWatcherNotificationHandler notificationHandler = aNotificationHandler();
fileWatcher = new FileTreeWatcher(testDirectory, newHashSet(), notificationHandler);
fileWatcher.startup();

Thread.sleep(500);

final String first = fileWatcherTestTree.createDirectory("", "first");
final String second = fileWatcherTestTree.createDirectory(first, "second");
final String file = fileWatcherTestTree.createFile(second);

Thread.sleep(5000);

fileWatcherTestTree.updateFile(file);

Thread.sleep(5000);

verify(notificationHandler, never()).errorOccurred(eq(testDirectory), any(Throwable.class));
verify(notificationHandler, never()).handleFileWatcherEvent(eq(DELETED), eq(testDirectory), anyString(), anyBoolean());

verify(notificationHandler, times(3)).handleFileWatcherEvent(eq(CREATED), eq(testDirectory), anyString(), anyBoolean());

ArgumentCaptor<String> modifiedEvents = ArgumentCaptor.forClass(String.class);
verify(notificationHandler).handleFileWatcherEvent(eq(MODIFIED), eq(testDirectory), modifiedEvents.capture(), anyBoolean());
assertEquals(newHashSet(file), newHashSet(modifiedEvents.getAllValues()));
}

@Test
public void watchesCreateDirectoryAndStartsWatchingNewlyCreatedDirectory() throws Exception {
FileWatcherNotificationHandler notificationHandler = aNotificationHandler();
Expand Down

0 comments on commit 839f2f1

Please sign in to comment.