use of org.eclipse.che.api.core.notification.EventSubscriber in project che by eclipse.
the class WorkspaceServiceTermination method terminate.
@Override
public void terminate() throws InterruptedException {
EventSubscriber propagator = new WorkspaceStoppedEventsPropagator();
eventService.subscribe(propagator);
try {
workspaceManager.shutdown();
} finally {
eventService.unsubscribe(propagator);
}
}
use of org.eclipse.che.api.core.notification.EventSubscriber in project che by eclipse.
the class UserDaoTest method shouldFireBeforeUserRemovedEventOnRemoveExistedUser.
@Test
public void shouldFireBeforeUserRemovedEventOnRemoveExistedUser() throws Exception {
final UserImpl user = users[0];
final BeforeUserRemovedEvent[] firedEvent = { null };
EventSubscriber<BeforeUserRemovedEvent> beforeUserRemovedSubscriber = event -> firedEvent[0] = event;
eventService.subscribe(beforeUserRemovedSubscriber, BeforeUserRemovedEvent.class);
userDao.remove(user.getId());
assertNotNull(firedEvent[0]);
assertEquals(firedEvent[0].getUser().getId(), user.getId());
eventService.unsubscribe(beforeUserRemovedSubscriber, BeforeUserRemovedEvent.class);
}
use of org.eclipse.che.api.core.notification.EventSubscriber in project che by eclipse.
the class UserDaoTest method shouldFireUserRemovedEventOnRemoveExistedUser.
@Test
public void shouldFireUserRemovedEventOnRemoveExistedUser() throws Exception {
final UserImpl user = users[0];
final UserRemovedEvent[] firedEvent = { null };
EventSubscriber<UserRemovedEvent> userRemovedSubscriber = event -> firedEvent[0] = event;
eventService.subscribe(userRemovedSubscriber, UserRemovedEvent.class);
userDao.remove(user.getId());
assertNotNull(firedEvent[0]);
assertEquals(firedEvent[0].getUserId(), user.getId());
eventService.unsubscribe(userRemovedSubscriber, UserRemovedEvent.class);
}
use of org.eclipse.che.api.core.notification.EventSubscriber in project che by eclipse.
the class WorkspaceServiceTerminationTest method publishesStoppedWorkspaceStoppedEventsAsServiceItemStoppedEvents.
@Test
public void publishesStoppedWorkspaceStoppedEventsAsServiceItemStoppedEvents() throws Exception {
when(workspaceManager.getRunningWorkspacesIds()).thenReturn(ImmutableSet.of("id1", "id2", "id3"));
doAnswer(inv -> {
@SuppressWarnings("unchecked") EventSubscriber<WorkspaceStatusEvent> subscriber = (EventSubscriber<WorkspaceStatusEvent>) inv.getArguments()[0];
subscriber.onEvent(newWorkspaceStatusEvent(WorkspaceStatus.STARTING, "id1"));
subscriber.onEvent(newWorkspaceStatusEvent(WorkspaceStatus.RUNNING, "id1"));
subscriber.onEvent(newWorkspaceStatusEvent(WorkspaceStatus.STOPPING, "id1"));
subscriber.onEvent(newWorkspaceStatusEvent(WorkspaceStatus.STOPPED, "id1"));
subscriber.onEvent(newWorkspaceStatusEvent(WorkspaceStatus.RUNNING, "id2"));
subscriber.onEvent(newWorkspaceStatusEvent(WorkspaceStatus.STOPPING, "id2"));
subscriber.onEvent(newWorkspaceStatusEvent(WorkspaceStatus.STOPPED, "id2"));
subscriber.onEvent(newWorkspaceStatusEvent(WorkspaceStatus.STOPPED, "id3"));
return null;
}).when(eventService).subscribe(any());
termination.terminate();
verify(eventService).publish(new SystemServiceItemStoppedEvent("workspace", "id1", 1, 3));
verify(eventService).publish(new SystemServiceItemStoppedEvent("workspace", "id2", 2, 3));
verify(eventService).publish(new SystemServiceItemStoppedEvent("workspace", "id3", 3, 3));
}
Aggregations