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);
}
}
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);
}
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);
}
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());
}
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());
}
Aggregations