use of org.jboss.cdi.tck.util.Timer.StopCondition in project cdi-tck by eclipse-ee4j.
the class ApplicationContextSharedTest method testApplicationScopeActiveDuringCallToEjbTimeoutMethod.
@OperateOnDeployment("TEST")
@Test
@SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "dc")
public void testApplicationScopeActiveDuringCallToEjbTimeoutMethod() throws Exception {
FMS flightManagementSystem = getContextualReference(FMS.class);
flightManagementSystem.climb();
new Timer().setDelay(20, TimeUnit.SECONDS).addStopCondition(new StopCondition() {
public boolean isSatisfied() {
return FMSModelIII.isClimbed();
}
}).start();
assertTrue(flightManagementSystem.isApplicationScopeActive());
}
use of org.jboss.cdi.tck.util.Timer.StopCondition in project cdi-tck by eclipse-ee4j.
the class ApplicationContextSharedTest method testApplicationContextShared.
@OperateOnDeployment("TEST")
@Test
@SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "e")
public void testApplicationContextShared() throws Exception {
FMSModelIII.reset();
FMS flightManagementSystem = getContextualReference(FMS.class);
flightManagementSystem.climb();
Timer timer = new Timer().setDelay(20, TimeUnit.SECONDS).addStopCondition(new StopCondition() {
public boolean isSatisfied() {
return FMSModelIII.isClimbed();
}
}).start();
flightManagementSystem.descend();
timer.addStopCondition(new StopCondition() {
public boolean isSatisfied() {
return FMSModelIII.isDescended();
}
}, true).start();
assertTrue(flightManagementSystem.isSameBean());
}
use of org.jboss.cdi.tck.util.Timer.StopCondition in project cdi-tck by eclipse-ee4j.
the class RequestScopeEventMessageDeliveryTest method testEventsFired.
@Test(groups = { JAVAEE_FULL, JMS })
@SpecAssertion(section = REQUEST_CONTEXT_EE, id = "jf")
@SpecAssertion(section = REQUEST_CONTEXT, id = "a")
@SpecAssertion(section = REQUEST_CONTEXT, id = "c")
public void testEventsFired() throws Exception {
new Timer().setDelay(5, TimeUnit.SECONDS).addStopCondition(new StopCondition() {
public boolean isSatisfied() {
return AbstractMessageListener.isInitialized();
}
}).start();
AbstractMessageListener.reset();
observer.reset();
producer.sendTopicMessage();
new Timer().setDelay(5, TimeUnit.SECONDS).addStopCondition(new StopCondition() {
public boolean isSatisfied() {
return AbstractMessageListener.isInitializedEventObserver() && AbstractMessageListener.getProcessedMessages() >= 1;
}
}).start();
assertEquals(1, AbstractMessageListener.getProcessedMessages());
assertTrue(AbstractMessageListener.isInitializedEventObserver());
// wait for the request scope for the message delivery to be destroyed and verify that the event was delivered
new Timer().setDelay(5, TimeUnit.SECONDS).addStopCondition(new StopCondition() {
public boolean isSatisfied() {
return observer.isDestroyedCalled();
}
}).start();
assertTrue(observer.isDestroyedCalled());
}
use of org.jboss.cdi.tck.util.Timer.StopCondition in project cdi-tck by eclipse-ee4j.
the class InactiveConversationTest method testContextNotActiveExceptionThrown.
@Test(groups = JAVAEE_FULL)
@SpecAssertion(section = CONVERSATION, id = "p")
public void testContextNotActiveExceptionThrown() throws Exception {
assertNotNull(foo);
// Conversation scope is not active during EJB timeout method
foo.createTimer();
StopCondition condition = new StopCondition() {
@Override
public boolean isSatisfied() {
return bar.isContextNotActiveExceptionThrown();
}
};
Timer timer = new Timer().setDelay(1000).addStopCondition(condition).start();
assertTrue(timer.isStopConditionsSatisfiedBeforeTimeout() || condition.isSatisfied());
}
use of org.jboss.cdi.tck.util.Timer.StopCondition in project cdi-tck by eclipse-ee4j.
the class ConversationFilterTest method testConversationBusy.
/**
* "The container ensures that a long-running conversation may be associated with at most one request at a time, by blocking or rejecting concurrent requests."
*
* In fact the spec doesn't require the container to reject the concurrent requests, but we don't expect it will block them
* forever.
*
* @throws Exception
*/
@Test(groups = INTEGRATION)
@SpecAssertion(section = CONVERSATION_CONTEXT_EE, id = "ua")
public void testConversationBusy() throws Exception {
// Init the long-running conversation
WebClient client = new WebClient();
TextPage initPage = client.getPage(contextPath + "introspect?mode=" + IntrospectServlet.MODE_INIT);
String cid = extractCid(initPage.getContent());
assertNotNull(cid);
assertFalse(cid.isEmpty());
String jsessionid = client.getCookieManager().getCookie(JSESSIONID).getValue();
assertNotNull(jsessionid);
assertFalse(jsessionid.isEmpty());
ExecutorService executorService = Executors.newFixedThreadPool(2);
WebRequest longTask = new WebRequest(IntrospectServlet.MODE_LONG_TASK, contextPath, cid, jsessionid);
WebRequest busyRequest = new WebRequest(IntrospectServlet.MODE_BUSY_REQUEST, contextPath, cid, jsessionid);
final Future<String> longTaskFuture = executorService.submit(longTask);
Timer timer = Timer.startNew(100l);
final Future<String> busyRequestFuture = executorService.submit(busyRequest);
timer.setSleepInterval(100l).setDelay(10, TimeUnit.SECONDS).addStopCondition(new StopCondition() {
@Override
public boolean isSatisfied() {
return longTaskFuture.isDone() || busyRequestFuture.isDone();
}
}).start();
assertEquals(longTaskFuture.get(), "OK");
assertEquals(busyRequestFuture.get(), "BusyConversationException");
executorService.shutdown();
}
Aggregations