mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-04 04:49:12 +00:00
Merge pull request #1886 from upthewaterspout/issue/1885
Issue #1885 Fixed rounding error of negative maxInactiveInterval
This commit is contained in:
commit
a4618a7ca6
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user