Search in sources :

Example 26 with JobEvent

use of org.eclipse.scout.rt.platform.job.listener.JobEvent in project scout.rt by eclipse.

the class ModelJobEventFilterTest method test.

@Test
public void test() {
    IClientSession session1 = mock(IClientSession.class);
    when(session1.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
    IClientSession session2 = mock(IClientSession.class);
    when(session2.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
    IFilter<JobEvent> filter = ModelJobEventFilter.INSTANCE;
    // not a model job (no future)
    JobEvent event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(null));
    assertFalse(filter.accept(event));
    // not a model job (no ClientRunContext)
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
    assertFalse(filter.accept(event));
    // not a model job (no ClientRunContext)
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
    assertFalse(filter.accept(event));
    // not a model job (no mutex and not session on ClientRunContext)
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty()))));
    assertFalse(filter.accept(event));
    // not a model job (no mutex)
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)))));
    assertFalse(filter.accept(event));
    // not a model job (wrong mutex type)
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(Jobs.newExecutionSemaphore(1)))));
    assertFalse(filter.accept(event));
    // not a model job (different session on ClientRunContext and mutex)
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(session2.getModelJobSemaphore()))));
    assertFalse(filter.accept(event));
    // not a model job (no session on ClientRunContext)
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(null, false)).withExecutionSemaphore(session1.getModelJobSemaphore()))));
    assertFalse(filter.accept(event));
    // this is a model job (same session on ClientRunContext and mutex)
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(session1.getModelJobSemaphore()))));
    assertTrue(filter.accept(event));
}
Also used : JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) IClientSession(org.eclipse.scout.rt.client.IClientSession) IJobManager(org.eclipse.scout.rt.platform.job.IJobManager) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData) Test(org.junit.Test)

Example 27 with JobEvent

use of org.eclipse.scout.rt.platform.job.listener.JobEvent in project scout.rt by eclipse.

the class SessionJobEventFilterTest method test.

@Test
public void test() {
    IClientSession session1 = mock(IClientSession.class);
    IClientSession session2 = mock(IClientSession.class);
    SessionJobEventFilter filter = new SessionJobEventFilter(session1);
    // Tests JobEvent of an event without a job associated
    JobEvent event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(null));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job without RunContext
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with RunContext
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext without session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty()))));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext with correct session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)))));
    assertTrue(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext with wrong session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session2, false)))));
    assertFalse(filter.accept(event));
    // Tests adaptable to the session
    assertSame(session1, filter.getAdapter(ISession.class));
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) SessionJobEventFilter(org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter) IClientSession(org.eclipse.scout.rt.client.IClientSession) IJobManager(org.eclipse.scout.rt.platform.job.IJobManager) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData) Test(org.junit.Test)

Aggregations

JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)27 Test (org.junit.Test)23 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)19 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)7 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)6 JobEventData (org.eclipse.scout.rt.platform.job.listener.JobEventData)6 IClientSession (org.eclipse.scout.rt.client.IClientSession)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Times (org.eclipse.scout.rt.testing.platform.runner.Times)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IBlockingCondition (org.eclipse.scout.rt.platform.job.IBlockingCondition)2 IExecutionSemaphore (org.eclipse.scout.rt.platform.job.IExecutionSemaphore)2 IFuture (org.eclipse.scout.rt.platform.job.IFuture)2 JobInput (org.eclipse.scout.rt.platform.job.JobInput)2 JobState (org.eclipse.scout.rt.platform.job.JobState)2 IJobListener (org.eclipse.scout.rt.platform.job.listener.IJobListener)2 IRegistrationHandle (org.eclipse.scout.rt.platform.util.IRegistrationHandle)2 ISession (org.eclipse.scout.rt.shared.ISession)2 SessionJobEventFilter (org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter)2 HashSet (java.util.HashSet)1