Merge pull request #1886 from upthewaterspout/issue/1885

Issue #1885 Fixed rounding error of negative maxInactiveInterval
This commit is contained in:
Jan Bartel 2017-10-11 09:41:10 +11:00 committed by GitHub
commit a4618a7ca6
2 changed files with 49 additions and 1 deletions

View File

@ -575,7 +575,8 @@ public class Session implements SessionHandler.SessionIf
{
try (Lock lock = _lock.lock())
{
return (int)(_sessionData.getMaxInactiveMs()/1000);
long maxInactiveMs = _sessionData.getMaxInactiveMs();
return (int)(maxInactiveMs < 0 ? -1 : maxInactiveMs/1000);
}
}

View File

@ -430,6 +430,53 @@ public abstract class AbstractModifyMaxInactiveIntervalTest extends AbstractTest
server.stop();
}
}
@Test
public void testGetMaxInactiveIntervalWithNegativeMaxInactiveInterval() throws Exception
{
int maxInactive = -1;
DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory();
cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT);
SessionDataStoreFactory storeFactory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)storeFactory).setGracePeriodSec(TestServer.DEFAULT_SCAVENGE_SEC);
TestServer server = new TestServer(0, maxInactive, __scavenge, cacheFactory, storeFactory);
ServletContextHandler ctxA = server.addContext("/mod");
ctxA.addServlet(TestModServlet.class, "/test");
server.start();
int port=server.getPort();
try
{
HttpClient client = new HttpClient();
client.start();
try
{
// Perform a request to create a session
ContentResponse response = client.GET("http://localhost:" + port + "/mod/test?action=create");
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.getHeaders().get("Set-Cookie");
assertTrue(sessionCookie != null);
//Test that the maxInactiveInterval matches the expected value
Request request= client.newRequest("http://localhost:" + port + "/mod/test?action=test&val="+maxInactive);
response = request.send();
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
finally
{
client.stop();
}
}
finally
{
server.stop();
}
}
public static class TestModServlet extends HttpServlet