Search in sources :

Example 1 with StopCondition

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());
}
Also used : Timer(org.jboss.cdi.tck.util.Timer) StopCondition(org.jboss.cdi.tck.util.Timer.StopCondition) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) AbstractTest(org.jboss.cdi.tck.AbstractTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 2 with StopCondition

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());
}
Also used : Timer(org.jboss.cdi.tck.util.Timer) StopCondition(org.jboss.cdi.tck.util.Timer.StopCondition) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) AbstractTest(org.jboss.cdi.tck.AbstractTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 3 with StopCondition

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());
}
Also used : Timer(org.jboss.cdi.tck.util.Timer) StopCondition(org.jboss.cdi.tck.util.Timer.StopCondition) AbstractTest(org.jboss.cdi.tck.AbstractTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 4 with StopCondition

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());
}
Also used : Timer(org.jboss.cdi.tck.util.Timer) StopCondition(org.jboss.cdi.tck.util.Timer.StopCondition) AbstractTest(org.jboss.cdi.tck.AbstractTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 5 with StopCondition

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();
}
Also used : Timer(org.jboss.cdi.tck.util.Timer) ExecutorService(java.util.concurrent.ExecutorService) StopCondition(org.jboss.cdi.tck.util.Timer.StopCondition) TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.testng.annotations.Test) AbstractTest(org.jboss.cdi.tck.AbstractTest) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Aggregations

Timer (org.jboss.cdi.tck.util.Timer)38 StopCondition (org.jboss.cdi.tck.util.Timer.StopCondition)38 Test (org.testng.annotations.Test)34 AbstractTest (org.jboss.cdi.tck.AbstractTest)28 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)28 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)8 ServletException (jakarta.servlet.ServletException)4 TextPage (com.gargoylesoftware.htmlunit.TextPage)2 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 ExecutorService (java.util.concurrent.ExecutorService)2 LogMessage (org.jboss.cdi.tck.tests.context.jms.LogStore.LogMessage)2