Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x

Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
Jan Bartel 2019-08-27 10:56:15 +10:00
commit fabc50ecc5
1 changed files with 17 additions and 10 deletions

View File

@ -81,8 +81,14 @@ public class ClusteredSessionMigrationTest extends AbstractTestBase
server1.start();
int port1 = server1.getPort();
TestServer server2 = new TestServer(0, TestServer.DEFAULT_MAX_INACTIVE, TestServer.DEFAULT_SCAVENGE_SEC,
cacheFactory, storeFactory);
//Configure a cache and store same way for server2
DefaultSessionCacheFactory cacheFactory2 = new DefaultSessionCacheFactory();
cacheFactory2.setEvictionPolicy(SessionCache.NEVER_EVICT);
cacheFactory2.setSaveOnCreate(true);
SessionDataStoreFactory storeFactory2 = createSessionDataStoreFactory();
TestServer server2 = new TestServer(0,TestServer.DEFAULT_MAX_INACTIVE, TestServer.DEFAULT_SCAVENGE_SEC,
cacheFactory2, storeFactory2);
server2.addContext(contextPath).addServlet(TestServlet.class, servletMapping);
try
@ -110,8 +116,6 @@ public class ClusteredSessionMigrationTest extends AbstractTestBase
request2.header("Cookie", sessionCookie);
ContentResponse response2 = request2.send();
assertEquals(HttpServletResponse.SC_OK, response2.getStatus());
String response = response2.getContentAsString();
assertEquals(response.trim(), String.valueOf(value));
}
finally
{
@ -132,6 +136,8 @@ public class ClusteredSessionMigrationTest extends AbstractTestBase
public static class TestServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static long createTime = 0;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
@ -149,6 +155,7 @@ public class ClusteredSessionMigrationTest extends AbstractTestBase
{
if (session == null)
session = request.getSession(true);
createTime = session.getCreationTime();
int value = Integer.parseInt(request.getParameter("value"));
session.setAttribute("value", value);
PrintWriter writer = response.getWriter();
@ -157,12 +164,12 @@ public class ClusteredSessionMigrationTest extends AbstractTestBase
}
else if ("get".equals(action))
{
int value = (Integer)session.getAttribute("value");
int x = session.getMaxInactiveInterval();
assertTrue(x > 0);
PrintWriter writer = response.getWriter();
writer.println(value);
writer.flush();
//We cannot test if the session contains the attribute node1
//set, because it may not have finished writing the attribute
//by the time its response returned to the client and the request
//was sent to node2. Just test the create time, which should be
//saved.
assertEquals(createTime, session.getCreationTime());
}
}
}