Skip to content

Commit

Permalink
WFLY-6624 Re-enable web passivation tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Oct 22, 2016
1 parent 6a24c0b commit 039cb2d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
Expand Up @@ -77,7 +77,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
resp.setHeader("node", env.getNodeName());
}
} catch (IllegalStateException e) {
// Service was not started
this.log(e.getLocalizedMessage(), e);
}
resp.getWriter().write("Success");
}
Expand Down
Expand Up @@ -27,12 +27,10 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Ignore;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
@RunAsClient
@Ignore("WFLY-6624")
public class CoarseSessionPassivationTestCase extends SessionPassivationTestCase {

@Deployment(name = DEPLOYMENT_1, managed = false, testable = false)
Expand Down
Expand Up @@ -27,12 +27,10 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Ignore;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
@RunAsClient
@Ignore("WFLY-6624")
public class FineSessionPassivationTestCase extends SessionPassivationTestCase {

@Deployment(name = DEPLOYMENT_1, managed = false, testable = false)
Expand Down
Expand Up @@ -103,26 +103,38 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
HttpSession session = req.getSession(true);
resp.addHeader(SESSION_ID, session.getId());
System.out.println(String.format("%s?%s;jsessionid=%s", req.getRequestURL(), req.getQueryString(), session.getId()));
if (operation.equals(SET)) {
String name = getRequiredParameter(req, NAME);
String value = req.getParameter(VALUE);
session.setAttribute(name, (value != null) ? new SessionAttributeValue(value) : null);
} else if (operation.equals(REMOVE)) {
String name = getRequiredParameter(req, NAME);
session.removeAttribute(name);
} else if (operation.equals(INVALIDATE)) {
session.invalidate();
} else if (operation.equals(GET)) {
String name = getRequiredParameter(req, NAME);
SessionAttributeValue value = (SessionAttributeValue) session.getAttribute(name);
if (value != null) {
resp.setHeader(RESULT, value.getValue());
switch (operation) {
case SET: {
String name = getRequiredParameter(req, NAME);
String value = req.getParameter(VALUE);
session.setAttribute(name, (value != null) ? new SessionAttributeValue(value) : null);
break;
}
case REMOVE: {
String name = getRequiredParameter(req, NAME);
session.removeAttribute(name);
break;
}
case INVALIDATE: {
session.invalidate();
break;
}
case GET: {
String name = getRequiredParameter(req, NAME);
SessionAttributeValue value = (SessionAttributeValue) session.getAttribute(name);
if (value != null) {
resp.setHeader(RESULT, value.getValue());
}
break;
}
case TIMEOUT: {
String timeout = getRequiredParameter(req, TIMEOUT);
session.setMaxInactiveInterval(Integer.parseInt(timeout));
break;
}
default: {
throw new ServletException("Unrecognized operation: " + operation);
}
} else if (operation.equals(TIMEOUT)) {
String timeout = getRequiredParameter(req, TIMEOUT);
session.setMaxInactiveInterval(Integer.parseInt(timeout));
} else {
throw new ServletException("Unrecognized operation: " + operation);
}

List<Map.Entry<String, EventType>> events = new LinkedList<>();
Expand Down
Expand Up @@ -68,7 +68,7 @@ static WebArchive getBaseDeployment() {

@Test
@InSequence(1)
public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1)
public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL)
throws IOException, URISyntaxException {

String session1 = null;
Expand All @@ -77,7 +77,7 @@ public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDe
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(baseURL1, "a", "1")));
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);
Expand All @@ -92,16 +92,25 @@ public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDe
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)) {
// This will trigger passivation of session1
response = client2.execute(new HttpGet(SessionOperationServlet.createSetURI(baseURL1, "a", "2")));
response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL, "a")));
try {
assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
session2 = getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID);
if (!events.containsKey(session2)) {
events.put(session2, new LinkedList<>());
expectedEvents.put(session2, SessionOperationServlet.EventType.PASSIVATION);
}
assertEquals(session2, getRequiredHeaderValue(response, SessionOperationServlet.SESSION_ID));
assertEquals("2", getRequiredHeaderValue(response, SessionOperationServlet.RESULT));
collectEvents(response, events);
} finally {
HttpClientUtils.closeQuietly(response);
Expand All @@ -117,9 +126,10 @@ public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDe
start = now;

// This should trigger activation of session1 and passivation of session2
response = client1.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL1, "a")));
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());
Expand All @@ -130,9 +140,10 @@ public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDe

// Verify session2 was passivated
while (events.get(session2).isEmpty() && ((now - start) < MAX_PASSIVATION_WAIT)) {
response = client1.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL1, "a")));
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 {
Expand All @@ -149,9 +160,10 @@ public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDe
start = now;

// This should trigger activation of session2 and passivation of session1
response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL1, "a")));
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());
Expand All @@ -162,9 +174,10 @@ public void test(@ArquillianResource(SessionOperationServlet.class) @OperateOnDe

// Verify session1 was passivated
while (!events.get(session1).isEmpty() && ((now - start) < MAX_PASSIVATION_WAIT)) {
response = client2.execute(new HttpGet(SessionOperationServlet.createGetURI(baseURL1, "a")));
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 {
Expand Down

0 comments on commit 039cb2d

Please sign in to comment.