Search in sources :

Example 1 with EventSubscriber

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);
    }
}
Also used : EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber)

Example 2 with EventSubscriber

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);
}
Also used : Mockito.doCallRealMethod(org.mockito.Mockito.doCallRealMethod) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) TckRepository(org.eclipse.che.commons.test.tck.repository.TckRepository) Page(org.eclipse.che.api.core.Page) Constants(org.eclipse.che.api.user.server.Constants) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TckRepositoryException(org.eclipse.che.commons.test.tck.repository.TckRepositoryException) AfterMethod(org.testng.annotations.AfterMethod) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) CascadeEvent(org.eclipse.che.core.db.cascade.event.CascadeEvent) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) CascadeEventSubscriber(org.eclipse.che.core.db.cascade.CascadeEventSubscriber) Arrays.asList(java.util.Arrays.asList) User(org.eclipse.che.api.core.model.user.User) ConflictException(org.eclipse.che.api.core.ConflictException) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) EventService(org.eclipse.che.api.core.notification.EventService) EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) Assert.fail(org.testng.Assert.fail) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) NotFoundException(org.eclipse.che.api.core.NotFoundException) Matchers.any(org.mockito.Matchers.any) PostUserPersistedEvent(org.eclipse.che.api.user.server.event.PostUserPersistedEvent) TckListener(org.eclipse.che.commons.test.tck.TckListener) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) UserRemovedEvent(org.eclipse.che.api.user.server.event.UserRemovedEvent) UserDao(org.eclipse.che.api.user.server.spi.UserDao) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Mockito.mock(org.mockito.Mockito.mock) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) Test(org.testng.annotations.Test)

Example 3 with EventSubscriber

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);
}
Also used : Mockito.doCallRealMethod(org.mockito.Mockito.doCallRealMethod) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) TckRepository(org.eclipse.che.commons.test.tck.repository.TckRepository) Page(org.eclipse.che.api.core.Page) Constants(org.eclipse.che.api.user.server.Constants) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TckRepositoryException(org.eclipse.che.commons.test.tck.repository.TckRepositoryException) AfterMethod(org.testng.annotations.AfterMethod) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) CascadeEvent(org.eclipse.che.core.db.cascade.event.CascadeEvent) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) CascadeEventSubscriber(org.eclipse.che.core.db.cascade.CascadeEventSubscriber) Arrays.asList(java.util.Arrays.asList) User(org.eclipse.che.api.core.model.user.User) ConflictException(org.eclipse.che.api.core.ConflictException) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) EventService(org.eclipse.che.api.core.notification.EventService) EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) Assert.fail(org.testng.Assert.fail) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) NotFoundException(org.eclipse.che.api.core.NotFoundException) Matchers.any(org.mockito.Matchers.any) PostUserPersistedEvent(org.eclipse.che.api.user.server.event.PostUserPersistedEvent) TckListener(org.eclipse.che.commons.test.tck.TckListener) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) UserRemovedEvent(org.eclipse.che.api.user.server.event.UserRemovedEvent) UserDao(org.eclipse.che.api.user.server.spi.UserDao) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Mockito.mock(org.mockito.Mockito.mock) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) UserRemovedEvent(org.eclipse.che.api.user.server.event.UserRemovedEvent) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 4 with EventSubscriber

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));
}
Also used : EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) SystemServiceItemStoppedEvent(org.eclipse.che.api.system.shared.event.service.SystemServiceItemStoppedEvent) WorkspaceStatusEvent(org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent) Test(org.testng.annotations.Test)

Aggregations

EventSubscriber (org.eclipse.che.api.core.notification.EventSubscriber)4 Test (org.testng.annotations.Test)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Arrays.asList (java.util.Arrays.asList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Inject (javax.inject.Inject)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 Page (org.eclipse.che.api.core.Page)2 ServerException (org.eclipse.che.api.core.ServerException)2 User (org.eclipse.che.api.core.model.user.User)2 EventService (org.eclipse.che.api.core.notification.EventService)2 Constants (org.eclipse.che.api.user.server.Constants)2 BeforeUserRemovedEvent (org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent)2 PostUserPersistedEvent (org.eclipse.che.api.user.server.event.PostUserPersistedEvent)2 UserRemovedEvent (org.eclipse.che.api.user.server.event.UserRemovedEvent)2 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)2 UserDao (org.eclipse.che.api.user.server.spi.UserDao)2