{
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins maxUnreplicated of 0
JBossCacheManager[] mgrs = getCacheManagers(warname, 1800, 1);
JBossCacheManager jbcm0 = mgrs[0];
JBossCacheManager jbcm1 = mgrs[1];
assertTrue(jbcm0.getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
MockClusteredSessionNotificationPolicy mcsnp0 = (MockClusteredSessionNotificationPolicy) jbcm0.getNotificationPolicy();
assertNotNull("capability set", mcsnp0.getClusteredSessionNotificationCapability());
mcsnp0.setResponse(notify);
assertTrue(jbcm1.getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
MockClusteredSessionNotificationPolicy mcsnp1 = (MockClusteredSessionNotificationPolicy) jbcm1.getNotificationPolicy();
assertNotNull("capability set", mcsnp1.getClusteredSessionNotificationCapability());
mcsnp1.setResponse(notify);
MockHttpSessionListener hsl0 = new MockHttpSessionListener();
MockHttpSessionAttributeListener hsal0 = new MockHttpSessionAttributeListener();
Context ctx = (Context) jbcm0.getContainer();
ctx.setApplicationLifecycleListeners(new Object[]{ hsl0 });
ctx.setApplicationEventListeners(new Object[]{ hsal0 });
MockHttpSessionListener hsl1 = new MockHttpSessionListener();
MockHttpSessionAttributeListener hsal1 = new MockHttpSessionAttributeListener();
ctx = (Context) jbcm1.getContainer();
ctx.setApplicationLifecycleListeners(new Object[]{ hsl1 });
ctx.setApplicationEventListeners(new Object[]{ hsal1 });
// Initial request
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attributes, false);
SessionTestUtil.invokeRequest(jbcm0, 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(jbcm0, 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);
jbcm0.backgroundProcess();
jbcm1.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(jbcm0, 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(jbcm1, setHandler, sessionId);
if (!notify)
{
validateNoNotifications(hsl0, hsal0, hsl1, hsal1);
}
else
{
assertEquals(1, hsl1.invocations.size());
assertEquals(MockHttpSessionListener.Type.CREATED, hsl1.invocations.get(0));
assertEquals(1, hsal1.invocations.size());
assertEquals(MockHttpSessionAttributeListener.Type.ADDED, hsal1.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(hsl0, hsal0, null, null, null);
clearNotifications(null, null, hsl1, hsal1, SessionSpecListenerAttribute.invocations);
}
// Passivate
Thread.sleep(1100);
jbcm0.backgroundProcess();
jbcm1.backgroundProcess();
if (!notify)
{
validateNoNotifications(hsl0, hsal0, hsl1, hsal1);
}