use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class AbstractJaxWsClientTest method testAcquirePortConcurrentlyInDifferentTransactions.
@Test
public void testAcquirePortConcurrentlyInDifferentTransactions() throws InterruptedException {
final CountDownLatch txn1InitLatch = new CountDownLatch(1);
final CountDownLatch txn2InitLatch = new CountDownLatch(1);
final Holder<JaxWsConsumerTestServicePortType> txn1PortHolder = new Holder<>(JaxWsConsumerTestServicePortType.class);
final Holder<JaxWsConsumerTestServicePortType> txn2PortHolder = new Holder<>(JaxWsConsumerTestServicePortType.class);
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
JaxWsConsumerTestServicePortType port0 = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
assertSendEcho(port0, 0);
txn1PortHolder.setValue(port0);
txn1InitLatch.countDown();
txn2InitLatch.await();
JaxWsConsumerTestServicePortType port1 = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
assertSamePort(port0, port1);
assertSendEcho(port1, 1);
}
}, Jobs.newInput().withRunContext(ServerRunContexts.empty()));
txn1InitLatch.await();
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
JaxWsConsumerTestServicePortType port0 = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
assertSendEcho(port0, 0);
txn2PortHolder.setValue(port0);
txn2InitLatch.countDown();
JaxWsConsumerTestServicePortType port1 = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
assertSamePort(port0, port1);
assertSendEcho(port1, 1);
}
}, Jobs.newInput().withRunContext(ServerRunContexts.empty()));
txn2InitLatch.await();
assertDifferentPort(txn1PortHolder.getValue(), txn2PortHolder.getValue());
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class AbstractJaxWsClientTest method testAcquirePortInDifferentTransactions.
/*
* ************************************************************
* Test acquire port in different transactions
* ************************************************************/
@Test
public void testAcquirePortInDifferentTransactions() throws InterruptedException {
final Holder<JaxWsConsumerTestServicePortType> txn1PortHolder = new Holder<>(JaxWsConsumerTestServicePortType.class);
final Holder<JaxWsConsumerTestServicePortType> txn2PortHolder = new Holder<>(JaxWsConsumerTestServicePortType.class);
// This test case expects at most one port in the pool. It is guaranteed by discarding all pooled entries.
BEANS.get(JaxWsConsumerTestClient.class).discardAllPoolEntries();
ServerRunContexts.copyCurrent().run(new IRunnable() {
@Override
public void run() throws Exception {
JaxWsConsumerTestServicePortType port = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
assertSendEcho(port, 0);
txn1PortHolder.setValue(port);
}
});
ServerRunContexts.copyCurrent().run(new IRunnable() {
@Override
public void run() throws Exception {
JaxWsConsumerTestServicePortType port = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
assertSendEcho(port, 0);
txn2PortHolder.setValue(port);
}
});
if (BEANS.get(JaxWsImplementorSpecifics.class).isPoolingSupported()) {
assertSamePort(txn1PortHolder.getValue(), txn2PortHolder.getValue());
} else {
assertDifferentPort(txn1PortHolder.getValue(), txn2PortHolder.getValue());
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class UiSessionTest method doTestLogoutWithBlockingModelDisposal.
/**
* Tests that session invalidation still works even if the model is blocking during its disposal. Especially the
* {@link HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)} method is expected not
* to be blocked by the {@link SessionStore} (the method is invoked by the servlet container and blocking its thread
* could interfere with the application server itself, for example when a background thread is cleaning up timed out
* sessions).
*/
protected void doTestLogoutWithBlockingModelDisposal(final CloseAction openFormCloseAction, boolean expectFormFinallyCompleted, boolean expectSessionActiveAfterwards) throws InterruptedException {
// create new UI session along with client client and HTTP sessions
UiSession uiSession = (UiSession) JsonTestUtility.createAndInitializeUiSession();
final HttpSession httpSession = UiSessionTestUtility.getHttpSession(uiSession);
IClientSession clientSession = uiSession.getClientSession();
assertFalse(uiSession.isDisposed());
// register ui session in session store
final ISessionStore sessionStore = BEANS.get(HttpSessionHelper.class).getSessionStore(httpSession);
sessionStore.registerUiSession(uiSession);
assertThat(sessionStore, is(instanceOf(HttpSessionBindingListener.class)));
// create and start test form in a model job
SessionStoreTestForm form = ModelJobs.schedule(new Callable<SessionStoreTestForm>() {
@Override
public SessionStoreTestForm call() throws Exception {
SessionStoreTestForm f = new SessionStoreTestForm(openFormCloseAction);
f.start();
return f;
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true))).awaitDoneAndGet(1, TimeUnit.SECONDS);
// schedule a job that emulates servlet container that performs session invalidation on session timeout
IFuture<Void> appServerSessionTimeoutFuture = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
httpSession.invalidate();
}
}, Jobs.newInput().withName("simulate session timeout").withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(200, TimeUnit.MILLISECONDS)));
// perform logout on UI session that stops the client session and disposes all model objects.
uiSession.logout();
assertTrue(uiSession.isDisposed());
if (expectFormFinallyCompleted) {
form.awaitDoFinallyCompleted(1, TimeUnit.SECONDS);
} else {
BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
}
appServerSessionTimeoutFuture.awaitDone(3, TimeUnit.SECONDS);
assertTrue(appServerSessionTimeoutFuture.isDone());
if (expectFormFinallyCompleted) {
assertTrue(form.isFinallyCompleted());
BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
} else {
assertFalse(form.isFinallyCompleted());
// The model job was canceled by the SessionStore. Hence we cannot use UiJobs.awaitModelJobs().
// We still sleep some time
SleepUtil.sleepSafe(200, TimeUnit.MILLISECONDS);
}
assertEquals(expectSessionActiveAfterwards, clientSession.isActive());
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobListenerBlockedFutureTest method testEventsForBlockingJob.
@Test(timeout = 10000)
public void testEventsForBlockingJob() {
final IBlockingCondition condition = Jobs.newBlockingCondition(true);
IClientSession clientSession = mock(IClientSession.class);
when(clientSession.getModelJobSemaphore()).thenReturn(Jobs.newExecutionSemaphore(1));
JobEventCaptureListener captureListener = new JobEventCaptureListener();
Jobs.getJobManager().addListener(ModelJobs.newEventFilterBuilder().toFilter(), captureListener);
IFuture<Void> outerFuture = null;
final AtomicReference<IFuture<?>> innerFuture = new AtomicReference<>();
final JobInput modelJobInput = ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true));
// start recording of events
outerFuture = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
innerFuture.set(Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
condition.setBlocking(false);
// Wait until the outer future is re-acquiring the mutex.
// 2=outer-job + inner-job
JobTestUtil.waitForPermitCompetitors(modelJobInput.getExecutionSemaphore(), 2);
}
}, modelJobInput.copy().withName("inner").withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(2, TimeUnit.SECONDS))));
condition.waitFor();
}
}, modelJobInput.copy().withName("outer"));
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(outerFuture).toFilter(), 1, TimeUnit.MINUTES);
Jobs.getJobManager().shutdown();
// verify events
int i = -1;
List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
// outer
i++;
assertStateChangedEvent(outerFuture, JobState.SCHEDULED, capturedEvents.get(i));
assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
// outer
i++;
assertStateChangedEvent(outerFuture, JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
// outer
i++;
assertStateChangedEvent(outerFuture, JobState.RUNNING, capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
// inner
i++;
assertStateChangedEvent(innerFuture.get(), JobState.SCHEDULED, capturedEvents.get(i));
assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
// inner
i++;
assertStateChangedEvent(innerFuture.get(), JobState.PENDING, capturedEvents.get(i));
assertEquals(JobState.PENDING, capturedFutureStates.get(i));
// outer
i++;
assertStateChangedEvent(outerFuture, JobState.WAITING_FOR_BLOCKING_CONDITION, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_BLOCKING_CONDITION, capturedFutureStates.get(i));
// inner
i++;
assertStateChangedEvent(innerFuture.get(), JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
// inner
i++;
assertStateChangedEvent(innerFuture.get(), JobState.RUNNING, capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
// outer
i++;
assertStateChangedEvent(outerFuture, JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
// inner
i++;
assertStateChangedEvent(innerFuture.get(), JobState.DONE, capturedEvents.get(i));
assertEquals(JobState.DONE, capturedFutureStates.get(i));
// outer
i++;
assertStateChangedEvent(outerFuture, JobState.RUNNING, capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
// outer
i++;
assertStateChangedEvent(outerFuture, JobState.DONE, capturedEvents.get(i));
assertEquals(JobState.DONE, capturedFutureStates.get(i));
assertEquals(i + 1, capturedEvents.size());
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class ModelJobTest method testModelThread.
@Test
public void testModelThread() {
final AtomicBoolean modelThread = new AtomicBoolean();
assertFalse(ModelJobs.isModelThread());
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
modelThread.set(ModelJobs.isModelThread());
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(m_clientSession1, true))).awaitDoneAndGet();
assertFalse(ModelJobs.isModelThread());
assertTrue(modelThread.get());
}
Aggregations