Search in sources :

Example 36 with InSequence

use of org.jboss.arquillian.junit.InSequence in project wildfly by wildfly.

the class SessionPassivationTestCase method test.

@Test
@InSequence(1)
public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL) throws IOException, URISyntaxException {
    String session1 = null;
    String session2 = null;
    try (CloseableHttpClient client1 = TestHttpClientUtils.promiscuousCookieHttpClient();
        CloseableHttpClient client2 = TestHttpClientUtils.promiscuousCookieHttpClient()) {
        // This should not trigger any passivation/activation events
        HttpResponse response = client1.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL, "a", "1")));
        try {
            assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            session1 = getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID);
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
        long now = System.currentTimeMillis();
        long start = now;
        Map<String, Queue<SessionOperationServlet.EventType>> events = new HashMap<>();
        Map<String, SessionOperationServlet.EventType> expectedEvents = new HashMap<>();
        events.put(session1, new LinkedList<>());
        expectedEvents.put(session1, SessionOperationServlet.EventType.PASSIVATION);
        // This will trigger passivation of session1
        response = client2.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL, "a", "2")));
        try {
            assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            session2 = getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID);
            events.put(session2, new LinkedList<>());
            expectedEvents.put(session2, SessionOperationServlet.EventType.PASSIVATION);
            collectEvents(response, events);
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
        // Ensure session1 was passivated
        while (events.get(session1).isEmpty() && ((now - start) < MAX_PASSIVATION_WAIT)) {
            response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a")));
            try {
                assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
                assertEquals(session2, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID));
                assertEquals("2", getRequiredHeaderValue(response, SessionOperationServlet.RESULT));
                collectEvents(response, events);
            } finally {
                HttpClientUtils.closeQuietly(response);
            }
            Thread.yield();
            now = System.currentTimeMillis();
        }
        assertFalse(events.get(session1).isEmpty());
        validateEvents(session1, events, expectedEvents);
        now = System.currentTimeMillis();
        start = now;
        // This should trigger activation of session1 and passivation of session2
        response = client1.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a")));
        try {
            assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            assertEquals(session1, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID));
            assertEquals("1", getRequiredHeaderValue(response, SessionOperationServlet.RESULT));
            collectEvents(response, events);
            assertFalse(events.get(session1).isEmpty());
            assertTrue(events.get(session1).contains(SessionOperationServlet.EventType.ACTIVATION));
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
        // Verify session2 was passivated
        while (events.get(session2).isEmpty() && ((now - start) < MAX_PASSIVATION_WAIT)) {
            response = client1.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a")));
            try {
                assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
                assertEquals(session1, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID));
                assertEquals("1", getRequiredHeaderValue(response, SessionOperationServlet.RESULT));
                collectEvents(response, events);
            } finally {
                HttpClientUtils.closeQuietly(response);
            }
            Thread.yield();
            now = System.currentTimeMillis();
        }
        assertFalse(events.get(session2).isEmpty());
        validateEvents(session2, events, expectedEvents);
        now = System.currentTimeMillis();
        start = now;
        // This should trigger activation of session2 and passivation of session1
        response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a")));
        try {
            assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            assertEquals(session2, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID));
            assertEquals("2", getRequiredHeaderValue(response, SessionOperationServlet.RESULT));
            collectEvents(response, events);
            assertFalse(events.get(session2).isEmpty());
            assertTrue(events.get(session2).contains(SessionOperationServlet.EventType.ACTIVATION));
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
        // Verify session1 was passivated
        while (!events.get(session1).isEmpty() && ((now - start) < MAX_PASSIVATION_WAIT)) {
            response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a")));
            try {
                assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
                assertEquals(session2, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID));
                assertEquals("2", getRequiredHeaderValue(response, SessionOperationServlet.RESULT));
                collectEvents(response, events);
            } finally {
                HttpClientUtils.closeQuietly(response);
            }
            Thread.yield();
            now = System.currentTimeMillis();
        }
        assertFalse(events.get(session1).isEmpty());
        validateEvents(session1, events, expectedEvents);
        validateEvents(session2, events, expectedEvents);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Queue(java.util.Queue) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 37 with InSequence

use of org.jboss.arquillian.junit.InSequence in project wildfly by wildfly.

the class JPA2LCTestCase method testMultipleNonTXTransactionalEntityManagerInvocations.

@Test
@InSequence(1)
public void testMultipleNonTXTransactionalEntityManagerInvocations() throws Exception {
    SFSB1 sfsb1 = lookup("SFSB1", SFSB1.class);
    sfsb1.createEmployee("Kelly Smith", "Watford, England", 1000);
    sfsb1.createEmployee("Alex Scott", "London, England", 2000);
    sfsb1.getEmployeeNoTX(1000);
    sfsb1.getEmployeeNoTX(2000);
    DataSource ds = rawLookup("java:jboss/datasources/ExampleDS", DataSource.class);
    Connection conn = ds.getConnection();
    try {
        int deleted = conn.prepareStatement("delete from Employee").executeUpdate();
        // verify that delete worked (or test is invalid)
        assertTrue("was able to delete added rows.  delete count=" + deleted, deleted > 1);
    } finally {
        conn.close();
    }
    // read deleted data from second level cache
    Employee emp = sfsb1.getEmployeeNoTX(1000);
    assertTrue("was able to read deleted database row from second level cache", emp != null);
}
Also used : Connection(java.sql.Connection) DataSource(javax.sql.DataSource) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 38 with InSequence

use of org.jboss.arquillian.junit.InSequence in project wildfly by wildfly.

the class EntityTestCase method testNamedQueries.

@Test
@InSequence(4)
public void testNamedQueries() throws Exception {
    EntityTest test = lookup("EntityTest", EntityTest.class);
    int count = test.testAllCustomersQuery();
    assertEquals("Number returned for allCustomers query", 4, count);
    Customer c = test.testCustomerByIdQuery();
    assertNotNull("One object should be returned by customerById query", c);
}
Also used : Customer(org.jboss.as.test.integration.jpa.hibernate.entity.Customer) EntityTest(org.jboss.as.test.integration.jpa.hibernate.EntityTest) EntityTest(org.jboss.as.test.integration.jpa.hibernate.EntityTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 39 with InSequence

use of org.jboss.arquillian.junit.InSequence in project wildfly by wildfly.

the class EntityTestCase method testManyToOne.

@Test
@InSequence(2)
public void testManyToOne() throws Exception {
    EntityTest test = lookup("EntityTest", EntityTest.class);
    Flight f = test.manyToOneCreate();
    Flight f2 = test.findFlightById(f.getId());
    assertEquals(f.getId(), new Long(1));
    assertEquals(f.getName(), f2.getName());
    assertEquals(f.getCompany().getName(), f2.getCompany().getName());
    Company c = test.findCompanyById(f.getCompany().getId());
    assertNotNull("Company has one flight.", c.getFlights());
    assertEquals(f.getCompany().getFlights().size(), c.getFlights().size());
}
Also used : Company(org.jboss.as.test.integration.jpa.hibernate.entity.Company) Flight(org.jboss.as.test.integration.jpa.hibernate.entity.Flight) EntityTest(org.jboss.as.test.integration.jpa.hibernate.EntityTest) EntityTest(org.jboss.as.test.integration.jpa.hibernate.EntityTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 40 with InSequence

use of org.jboss.arquillian.junit.InSequence in project wildfly by wildfly.

the class EntityTestCase method testFlush.

@Test
@InSequence(5)
public void testFlush() throws Exception {
    EntityTest test = lookup("EntityTest", EntityTest.class);
    Customer c = test.createCustomer("Thomas");
    test.changeCustomer(c.getId(), "George");
    Customer c2 = test.findCustomerById(c.getId());
    assertEquals("George", c2.getName());
}
Also used : Customer(org.jboss.as.test.integration.jpa.hibernate.entity.Customer) EntityTest(org.jboss.as.test.integration.jpa.hibernate.EntityTest) EntityTest(org.jboss.as.test.integration.jpa.hibernate.EntityTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Aggregations

InSequence (org.jboss.arquillian.junit.InSequence)157 Test (org.junit.Test)157 Faker (com.github.javafaker.Faker)21 Simple (org.apache.deltaspike.data.test.ee7.domain.Simple)18 ModelNode (org.jboss.dmr.ModelNode)14 URL (java.net.URL)13 HttpResponse (org.apache.http.HttpResponse)10 TakeOffer (io.bisq.api.model.TakeOffer)9 HttpGet (org.apache.http.client.methods.HttpGet)8 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)8 OfferToCreate (io.bisq.api.model.OfferToCreate)7 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)7 PartitionManager (org.picketlink.idm.PartitionManager)7 Response (javax.ws.rs.core.Response)6 IdentityManager (org.picketlink.idm.IdentityManager)6 StringTokenizer (java.util.StringTokenizer)5 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 House (org.apache.deltaspike.data.test.ee7.domain.House)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)5 ManagementClient (org.jboss.as.arquillian.container.ManagementClient)5