Search in sources :

Example 1 with MODIFIED

use of org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.MODIFIED in project che by eclipse.

the class FileTreeWatcherMassiveIoOperationTest method watchesUpdatesFilesInTree.

@Test
public void watchesUpdatesFilesInTree() throws Exception {
    fileWatcherTestTree.createTree("", 7, 5);
    Thread.sleep(100);
    FileWatcherNotificationHandler notificationListener = aNotificationListener();
    fileTreeWatcher = new FileTreeWatcher(testDirectory, newHashSet(), notificationListener);
    fileTreeWatcher.startup();
    Thread.sleep(5000);
    List<String> updated = fileWatcherTestTree.findAllFilesInTree("").stream().filter(path -> path.hashCode() % 2 == 0).collect(Collectors.toList());
    for (String file : updated) {
        fileWatcherTestTree.updateFile(file);
    }
    Thread.sleep(5000);
    verify(notificationListener, never()).errorOccurred(eq(testDirectory), any(Throwable.class));
    verify(notificationListener, never()).handleFileWatcherEvent(eq(CREATED), eq(testDirectory), anyString(), anyBoolean());
    verify(notificationListener, never()).handleFileWatcherEvent(eq(DELETED), eq(testDirectory), anyString(), anyBoolean());
    ArgumentCaptor<String> updatedEvents = ArgumentCaptor.forClass(String.class);
    verify(notificationListener, times(updated.size())).handleFileWatcherEvent(eq(MODIFIED), eq(testDirectory), updatedEvents.capture(), anyBoolean());
    assertThatCollectionsContainsSameItemsOrFailWithDiff(updatedEvents.getAllValues(), updated);
}
Also used : CREATED(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.CREATED) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Assert.fail(org.junit.Assert.fail) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) Before(org.junit.Before) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Collectors(java.util.stream.Collectors) File(java.io.File) MODIFIED(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.MODIFIED) Mockito.verify(org.mockito.Mockito.verify) IoUtil(org.eclipse.che.commons.lang.IoUtil) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DELETED(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.DELETED) Mockito.mock(org.mockito.Mockito.mock) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 File (java.io.File)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 CREATED (org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.CREATED)1 DELETED (org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.DELETED)1 MODIFIED (org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.MODIFIED)1 IoUtil (org.eclipse.che.commons.lang.IoUtil)1 NameGenerator (org.eclipse.che.commons.lang.NameGenerator)1 After (org.junit.After)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Matchers.any (org.mockito.Matchers.any)1 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)1 Matchers.anyString (org.mockito.Matchers.anyString)1