ctx = (Context) managers[1].getContainer();
ctx.setApplicationSessionLifecycleListeners(new Object[]{ hsl1 });
ctx.setApplicationEventListeners(new Object[]{ hsal1 });
// Initial request
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attributes, false);
SessionTestUtil.invokeRequest(managers[0], setHandler, null);
validateNewSession(setHandler);
String sessionId = setHandler.getSessionId();
if (!notify)
{
validateNoNotifications(hsl0, hsal0, hsl1, hsal1);
}
else
{
assertEquals(1, hsl0.invocations.size());
assertEquals(MockHttpSessionListener.Type.CREATED, hsl0.invocations.get(0));
assertEquals(1, hsal0.invocations.size());
assertEquals(MockHttpSessionAttributeListener.Type.ADDED, hsal0.invocations.get(0));
assertEquals(2, SessionSpecListenerAttribute.invocations.size());
assertEquals(SessionSpecListenerAttribute.Type.BOUND, SessionSpecListenerAttribute.invocations.get(0));
assertEquals(SessionSpecListenerAttribute.Type.PASSIVATED, SessionSpecListenerAttribute.invocations.get(1));
validateNoNotifications(null, null, hsl1, hsal1, null);
clearNotifications(hsl0, hsal0, null, null, SessionSpecListenerAttribute.invocations);
}
// Modify attribute request
setHandler = new SetAttributesRequestHandler(newAttributes, false);
SessionTestUtil.invokeRequest(managers[0], setHandler, sessionId);
if (!notify)
{
validateNoNotifications(hsl0, hsal0, hsl1, hsal1);
}
else
{
assertEquals(1, hsal0.invocations.size());
assertEquals(MockHttpSessionAttributeListener.Type.REPLACED, hsal0.invocations.get(0));
assertEquals(4, SessionSpecListenerAttribute.invocations.size());
assertEquals(SessionSpecListenerAttribute.Type.ACTIVATING, SessionSpecListenerAttribute.invocations.get(0));
assertEquals(SessionSpecListenerAttribute.Type.BOUND, SessionSpecListenerAttribute.invocations.get(1));
assertEquals(SessionSpecListenerAttribute.Type.UNBOUND, SessionSpecListenerAttribute.invocations.get(2));
assertEquals(SessionSpecListenerAttribute.Type.PASSIVATED, SessionSpecListenerAttribute.invocations.get(3));
validateNoNotifications(hsl0, null, hsl1, hsal1, null);
clearNotifications(null, hsal0, null, null, SessionSpecListenerAttribute.invocations);
}
// Passivate
Thread.sleep(1100);
managers[0].backgroundProcess();
managers[1].backgroundProcess();
if (!notify)
{
validateNoNotifications(hsl0, hsal0, hsl1, hsal1);
}
else
{
assertEquals(1, SessionSpecListenerAttribute.invocations.size());
assertEquals(SessionSpecListenerAttribute.Type.PASSIVATED, SessionSpecListenerAttribute.invocations.get(0));
validateNoNotifications(hsl0, hsal0, hsl1, hsal1, null);
clearNotifications(null, null, null, null, SessionSpecListenerAttribute.invocations);
}
// Remove attribute request
RemoveAttributesRequestHandler removeHandler = new RemoveAttributesRequestHandler(newAttributes.keySet(), false);
SessionTestUtil.invokeRequest(managers[0], removeHandler, sessionId);
if (!notify)
{
validateNoNotifications(hsl0, hsal0, hsl1, hsal1);
}
else
{
assertEquals(1, hsal0.invocations.size());
assertEquals(MockHttpSessionAttributeListener.Type.REMOVED, hsal0.invocations.get(0));
assertEquals(3, SessionSpecListenerAttribute.invocations.size());
assertEquals(SessionSpecListenerAttribute.Type.ACTIVATING, SessionSpecListenerAttribute.invocations.get(0));
assertEquals(SessionSpecListenerAttribute.Type.ACTIVATING, SessionSpecListenerAttribute.invocations.get(1));
assertEquals(SessionSpecListenerAttribute.Type.UNBOUND, SessionSpecListenerAttribute.invocations.get(2));
validateNoNotifications(hsl0, null, hsl1, hsal1, null);
clearNotifications(null, hsal0, null, null, SessionSpecListenerAttribute.invocations);
}
// Failover request
setHandler = new SetAttributesRequestHandler(attributes, false);
SessionTestUtil.invokeRequest(managers[1], setHandler, sessionId);
if (!notify)
{
validateNoNotifications(hsl0, hsal0, hsl1, hsal1);