use of com.linkedin.kafka.cruisecontrol.servlet.handler.async.runnable.OperationFuture in project cruise-control by linkedin.
the class UserTaskManagerTest method testExpireSession.
@Test
public void testExpireSession() throws Exception {
UUID testUserTaskId = UUID.randomUUID();
UserTaskManager.UuidGenerator mockUuidGenerator = EasyMock.mock(UserTaskManager.UuidGenerator.class);
EasyMock.expect(mockUuidGenerator.randomUUID()).andReturn(testUserTaskId).anyTimes();
Time mockTime = new MockTime();
HttpSession mockHttpSession = EasyMock.mock(HttpSession.class);
EasyMock.expect(mockHttpSession.getLastAccessedTime()).andReturn(mockTime.milliseconds()).anyTimes();
mockHttpSession.invalidate();
HttpServletRequest mockHttpServletRequest = prepareRequest(mockHttpSession, null);
OperationFuture future = new OperationFuture("future");
UserTaskManager userTaskManager = new UserTaskManager(1000, 1, TimeUnit.HOURS.toMillis(6), 100, mockTime, mockUuidGenerator);
HttpServletResponse mockHttpServletResponse = EasyMock.mock(HttpServletResponse.class);
mockHttpServletResponse.setHeader(EasyMock.anyString(), EasyMock.anyString());
EasyMock.replay(mockUuidGenerator, mockHttpSession, mockHttpServletResponse);
// test-case: test if the sessions are removed on expiration
OperationFuture future1 = userTaskManager.getOrCreateUserTask(mockHttpServletRequest, mockHttpServletResponse, uuid -> future, 0, true, null).get(0);
Assert.assertEquals(future, future1);
mockTime.sleep(1001);
Thread.sleep(TimeUnit.SECONDS.toMillis(UserTaskManager.USER_TASK_SCANNER_PERIOD_SECONDS + 1));
OperationFuture future2 = userTaskManager.getFuture(mockHttpServletRequest);
Assert.assertNull(future2);
EasyMock.verify(mockUuidGenerator, mockHttpSession, mockHttpServletResponse);
userTaskManager.close();
}
Aggregations