Search in sources :

Example 1 with DELETED

use of org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.DELETED 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)

Example 2 with DELETED

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

the class ProjectTreeTracker method getDeleteOperation.

private Consumer<String> getDeleteOperation(String endpointId) {
    return it -> {
        timers.add(it);
        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                if (timers.contains(it)) {
                    timers.remove(it);
                    ProjectTreeStateUpdateDto params = newDto(ProjectTreeStateUpdateDto.class).withPath(it).withType(DELETED);
                    transmitter.transmitOneToNone(endpointId, OUTGOING_METHOD, params);
                }
            }
        }, 1_000L);
    };
}
Also used : ProjectTreeTrackingOperationDto(org.eclipse.che.api.project.shared.dto.event.ProjectTreeTrackingOperationDto) RequestTransmitter(org.eclipse.che.api.core.jsonrpc.RequestTransmitter) ProjectTreeStateUpdateDto(org.eclipse.che.api.project.shared.dto.event.ProjectTreeStateUpdateDto) HashMap(java.util.HashMap) Timer(java.util.Timer) Singleton(javax.inject.Singleton) CREATED(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.CREATED) Inject(javax.inject.Inject) FileWatcherManager(org.eclipse.che.api.vfs.watcher.FileWatcherManager) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) TimerTask(java.util.TimerTask) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Type(org.eclipse.che.api.project.shared.dto.event.ProjectTreeTrackingOperationDto.Type) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) Set(java.util.Set) Consumer(java.util.function.Consumer) RequestHandlerConfigurator(org.eclipse.che.api.core.jsonrpc.RequestHandlerConfigurator) Entry(java.util.Map.Entry) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DELETED(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.DELETED) EMPTY_CONSUMER(org.eclipse.che.api.vfs.watcher.FileWatcherManager.EMPTY_CONSUMER) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ProjectTreeStateUpdateDto(org.eclipse.che.api.project.shared.dto.event.ProjectTreeStateUpdateDto)

Aggregations

CREATED (org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.CREATED)2 DELETED (org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType.DELETED)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Sets.newConcurrentHashSet (com.google.common.collect.Sets.newConcurrentHashSet)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 File (java.io.File)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Inject (javax.inject.Inject)1