use of org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent 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));
}
use of org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent in project che by eclipse.
the class WorkspaceRuntimesTest method verifyEventsSequence.
private void verifyEventsSequence(WorkspaceStatusEvent... expected) {
Iterator<WorkspaceStatusEvent> it = captureEvents().iterator();
for (WorkspaceStatusEvent expEvent : expected) {
if (!it.hasNext()) {
fail(format("It is expected to receive the status changed event '%s' -> '%s' " + "but there are no more events published", expEvent.getPrevStatus(), expEvent.getStatus()));
}
WorkspaceStatusEvent cur = it.next();
if (cur.getPrevStatus() != expEvent.getPrevStatus() || cur.getStatus() != expEvent.getStatus()) {
fail(format("Expected to receive status change '%s' -> '%s', while received '%s' -> '%s'", expEvent.getPrevStatus(), expEvent.getStatus(), cur.getPrevStatus(), cur.getStatus()));
}
assertEquals(cur, expEvent);
}
if (it.hasNext()) {
WorkspaceStatusEvent next = it.next();
fail(format("No more events expected, but received '%s' -> '%s'", next.getPrevStatus(), next.getStatus()));
}
}
Aggregations