Search in sources :

Example 26 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.

the class JobListenerBlockedFutureTest method testEvents.

@Test
public void testEvents() throws Exception {
    JobEventCaptureListener captureListener = new JobEventCaptureListener();
    Jobs.getJobManager().addListener(captureListener);
    IClientSession clientSession = mock(IClientSession.class);
    IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
        // NOOP
        }
    }, Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(clientSession, true)));
    Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(future).toFilter(), 1, TimeUnit.MINUTES);
    Jobs.getJobManager().shutdown();
    // verify events
    int i = -1;
    List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
    List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
    i++;
    assertStateChangedEvent(future, JobState.SCHEDULED, capturedEvents.get(i));
    assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
    i++;
    assertStateChangedEvent(future, JobState.RUNNING, capturedEvents.get(i));
    assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
    i++;
    assertStateChangedEvent(future, JobState.DONE, capturedEvents.get(i));
    assertEquals(JobState.DONE, capturedFutureStates.get(i));
    i++;
    assertJobManagerShutdownEvent(capturedEvents.get(i));
    assertNull(capturedFutureStates.get(i));
    assertEquals(i + 1, capturedEvents.size());
}
Also used : JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) IClientSession(org.eclipse.scout.rt.client.IClientSession) JobState(org.eclipse.scout.rt.platform.job.JobState) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Example 27 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.

the class ModelJobsTest method testIsModelThread.

@Test
public void testIsModelThread() {
    final IClientSession clientSession1 = mock(IClientSession.class);
    when(clientSession1.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
    final IClientSession clientSession2 = mock(IClientSession.class);
    when(clientSession2.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
    ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            // Test model thread for same session (1)
            assertTrue(ModelJobs.isModelThread());
            // Test model thread for same session (2)
            ClientRunContexts.copyCurrent().run(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertTrue(ModelJobs.isModelThread());
                }
            });
            // Test model thread for other session
            ClientRunContexts.copyCurrent().withSession(clientSession2, true).run(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertTrue(ModelJobs.isModelThread());
                }
            });
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession1, true))).awaitDoneAndGet();
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 28 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.

the class ModelJobsTest method testIsModelJob.

@Test
public void testIsModelJob() {
    IClientSession session1 = mock(IClientSession.class);
    when(session1.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
    IClientSession session2 = mock(IClientSession.class);
    when(session2.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
    // not a model job (no Future)
    assertFalse(ModelJobs.isModelJob(null));
    // not a model job (no ClientRunContext)
    assertFalse(ModelJobs.isModelJob(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
    // not a model job (no ClientRunContext)
    assertFalse(ModelJobs.isModelJob(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
    // not a model job (no mutex and not session on ClientRunContext)
    assertFalse(ModelJobs.isModelJob(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty()))));
    // not a model job (no mutex)
    assertFalse(ModelJobs.isModelJob(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)))));
    // not a model job (wrong mutex type)
    assertFalse(ModelJobs.isModelJob(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(Jobs.newExecutionSemaphore(1)))));
    // not a model job (different session on ClientRunContext and mutex)
    assertFalse(ModelJobs.isModelJob(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(session2.getModelJobSemaphore()))));
    // not a model job (no session on ClientRunContext)
    assertFalse(ModelJobs.isModelJob(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(null, false)).withExecutionSemaphore(session1.getModelJobSemaphore()))));
    // this is a model job (same session on ClientRunContext and mutex)
    assertTrue(ModelJobs.isModelJob(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)).withExecutionSemaphore(session1.getModelJobSemaphore()))));
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Example 29 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession 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 30 with IClientSession

use of org.eclipse.scout.rt.client.IClientSession 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

IClientSession (org.eclipse.scout.rt.client.IClientSession)30 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)11 Test (org.junit.Test)11 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)4 Subject (javax.security.auth.Subject)3 HttpSession (javax.servlet.http.HttpSession)3 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)3 IFuture (org.eclipse.scout.rt.platform.job.IFuture)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 ISession (org.eclipse.scout.rt.shared.ISession)3 UserAgent (org.eclipse.scout.rt.shared.ui.UserAgent)3 WeakReference (java.lang.ref.WeakReference)2 Locale (java.util.Locale)2 Callable (java.util.concurrent.Callable)2 IMessageBox (org.eclipse.scout.rt.client.ui.messagebox.IMessageBox)2 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)2 JobEventData (org.eclipse.scout.rt.platform.job.listener.JobEventData)2 NlsLocale (org.eclipse.scout.rt.platform.nls.NlsLocale)2 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)2 SessionStoreTestForm (org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm)2