Package org.jboss.web.tomcat.service.session

Examples of org.jboss.web.tomcat.service.session.JBossCacheManager


   {
      if (distributedManagerFactory == null)
         throw new IllegalStateException("Failed to initialize distributedManagerFactory");
     
      distributedManagerFactory.setPojoCache(cache);
      JBossCacheManager jbcm = new JBossCacheManager(distributedManagerFactory);
      jbcm.setSnapshotMode(SnapshotMode.INSTANT);
     
      MockEngine engine = new MockEngine();
      engine.setJvmRoute(jvmRoute);
      MockHost host = new MockHost();
      engine.addChild(host);
      host.setName("localhost");
      StandardContext container = new StandardContext();
      container.setName(warName);
      host.addChild(container);
      container.setManager(jbcm);
     
      // Do this after assigning the manager to the container, or else
      // the container's setting will override ours
      // Can't just set the container as their config is per minute not per second
      jbcm.setMaxInactiveInterval(maxInactiveInterval);
  
      return jbcm;     
   }
View Full Code Here


   {
      log.info("Enter testStandaloneMaxSessions");
     
      ++testCount;
     
      JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, null, false, false, null, caches);
      
      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(2);
      jbcm.init("test.war", webMetaData);
     
      jbcm.start();
     
      assertFalse("Passivation is disabled", jbcm.isPassivationEnabled());
      assertEquals("Correct max active count", 2, jbcm.getMaxActiveAllowed());
     
      // Set up a session
      Session sess1 = createAndUseSession(jbcm, "1", true, true);
     
      assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
     
      createAndUseSession(jbcm, "2", true, true);
     
      assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 2, jbcm.getLocalActiveSessionCount());
     
      // Should fail to create a 3rd
      createAndUseSession(jbcm, "3", false, false);
     
      // Confirm a session timeout clears space
      sess1.setMaxInactiveInterval(1);      
      SessionTestUtil.sleepThread(1100);     
     
      createAndUseSession(jbcm, "3", true, true);     
     
      assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 2, jbcm.getLocalActiveSessionCount());
      assertEquals("Created session count correct", 3, jbcm.getCreatedSessionCount());
      assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
   }
View Full Code Here

   {
      log.info("Enter testStandaloneMaxSessionsWithMaxIdle");
     
      ++testCount;
      String passDir = getPassivationDir(testCount, 1);
      JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, passDir, false, false, null, caches);
      
      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 1, -1);
      jbcm.init("test.war", webMetaData);
     
      jbcm.start();
     
      assertTrue("Passivation is enabled", jbcm.isPassivationEnabled());
      assertEquals("Correct max active count", 1, jbcm.getMaxActiveAllowed());
      assertEquals("Correct max idle time", 1, jbcm.getPassivationMaxIdleTime());
      assertEquals("Correct min idle time", -1, jbcm.getPassivationMinIdleTime());

      // Set up a session
      Session sess1 = createAndUseSession(jbcm, "1", true, true);
     
      assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
     
      // Should fail to create a 2nd
      createAndUseSession(jbcm, "2", false, false);
     
      // Confirm a session timeout clears space
      sess1.setMaxInactiveInterval(1);      
      SessionTestUtil.sleepThread(1100);     
     
      createAndUseSession(jbcm, "2", true, true);     
     
      assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
      assertEquals("Created session count correct", 2, jbcm.getCreatedSessionCount());
      assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
      assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());

      //    Sleep past maxIdleTime
      SessionTestUtil.sleepThread(1100);       
     
      assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
     
      createAndUseSession(jbcm, "3", true, true);     
     
      assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
      assertEquals("Created session count correct", 3, jbcm.getCreatedSessionCount());
      assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
      assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
     
   }
View Full Code Here

   {
      log.info("Enter testStandaloneMaxSessionsWithMinIdle");
     
      ++testCount;
      String passDir = getPassivationDir(testCount, 1);
      JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, passDir, false, false, null, caches);
     
      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
      jbcm.init("test.war", webMetaData);
     
      jbcm.start();
     
      assertTrue("Passivation is enabled", jbcm.isPassivationEnabled());
      assertEquals("Correct max active count", 1, jbcm.getMaxActiveAllowed());
      assertEquals("Correct max idle time", 3, jbcm.getPassivationMaxIdleTime());
      assertEquals("Correct min idle time", 1, jbcm.getPassivationMinIdleTime());
     
      // Set up a session
      Session sess1 = createAndUseSession(jbcm, "1", true, true);
     
      assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
     
      // Should fail to create a 2nd
      createAndUseSession(jbcm, "2", false, false);
     
      // Confirm a session timeout clears space
      sess1.setMaxInactiveInterval(1);      
      SessionTestUtil.sleepThread(1100);     
     
      createAndUseSession(jbcm, "2", true, false);     
     
      assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());    
      assertEquals("Created session count correct", 2, jbcm.getCreatedSessionCount());
      assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());

      //    Sleep past minIdleTime
      SessionTestUtil.sleepThread(1100);       
     
//      assertTrue("Session 2 still valid", sess2.isValid());
      assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
     
      createAndUseSession(jbcm, "3", true, true);     
     
      assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
      assertEquals("Created session count correct", 3, jbcm.getCreatedSessionCount());
      assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
      assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
   }
View Full Code Here

   public void testReplicatedMaxSessions() throws Exception
   {
      log.info("Enter testReplicatedMaxSessions");
     
      ++testCount;
      JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, null, false, false, null, caches);
     
      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1);
      jbcm0.init("test.war", webMetaData);
     
      jbcm0.start();
     
      assertFalse("Passivation is disabled", jbcm0.isPassivationEnabled());
      assertEquals("Correct max active count", 1, jbcm0.getMaxActiveAllowed());
      assertEquals("Correct max inactive interval", 1, jbcm0.getMaxInactiveInterval());
     
      JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 1, false, null, false, false, null, caches);
     
      jbcm1.init("test.war", webMetaData);
     
      jbcm1.start();
     
      assertFalse("Passivation is disabled", jbcm1.isPassivationEnabled());
      assertEquals("Correct max active count", 1, jbcm1.getMaxActiveAllowed());
      assertEquals("Correct max inactive interval", 1, jbcm1.getMaxInactiveInterval());
     
      // Set up a session
      Session sess1 = createAndUseSession(jbcm0, "1", true, true);
     
      assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());     
      assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
      assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
     
      // Should fail to create a 2nd
      createAndUseSession(jbcm1, "2", false, false);
     
      // Confirm a session timeout clears space
      sess1.setMaxInactiveInterval(1);    
      useSession(jbcm0, "1");
      SessionTestUtil.sleepThread(jbcm0.getMaxInactiveInterval() * 1000 + 100);     
     
      createAndUseSession(jbcm1, "2", true, true);     
     
      assertEquals("Session count correct", 2, jbcm0.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
      assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
      assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());     
     
      assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
      assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
      assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
   }
View Full Code Here

   {
      log.info("Enter testReplicatedMaxSessionsWithMaxIdle");
     
      ++testCount;
      String passDir = getPassivationDir(testCount, 1);
      JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, false, null, caches);
     
      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 1, -1);
      jbcm0.init("test.war", webMetaData);
     
      jbcm0.start();
     
      assertTrue("Passivation is enabled", jbcm0.isPassivationEnabled());
      assertEquals("Correct max active count", 1, jbcm0.getMaxActiveAllowed());
      assertEquals("Correct max idle time", 1, jbcm0.getPassivationMaxIdleTime());
      assertEquals("Correct min idle time", -1, jbcm0.getPassivationMinIdleTime());
     
      passDir = getPassivationDir(testCount, 2);
      JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, false, null, caches);
     
      jbcm1.init("test.war", webMetaData);
     
      jbcm1.start();
     
      assertTrue("Passivation is enabled", jbcm1.isPassivationEnabled());
      assertEquals("Correct max active count", 1, jbcm1.getMaxActiveAllowed());
      assertEquals("Correct max idle time", 1, jbcm1.getPassivationMaxIdleTime());
      assertEquals("Correct min idle time", -1, jbcm1.getPassivationMinIdleTime());
     
      // Set up a session
      createAndUseSession(jbcm0, "1", true, true);
     
      assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
      assertEquals("Passivated session count correct", 0, jbcm0.getPassivatedSessionCount());     
      assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
      assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
      assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
     
      // Should fail to create a 2nd
      createAndUseSession(jbcm1, "2", false, false);     
     
      //    Sleep past maxIdleTime     
      SessionTestUtil.sleepThread(1100);       
     
      assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
      
      createAndUseSession(jbcm1, "2", true, true);     
      
      assertEquals("Session count correct", 2, jbcm0.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
      assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
      assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount())
      assertEquals("Passivated session count correct", 0, jbcm0.getPassivatedSessionCount());   
      
      assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
      assertEquals("Local session count correct", 1, jbcm1.getLocalActiveSessionCount());
      assertEquals("Created session count correct", 1, jbcm1.getCreatedSessionCount());
      assertEquals("Expired session count correct", 0, jbcm1.getExpiredSessionCount());
      assertEquals("Passivated session count correct", 1, jbcm1.getPassivatedSessionCount());    
   }
View Full Code Here

   public void testUseJK() throws Exception
   {
      log.info("Enter testUseJK");
     
      ++testCount;
      JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, null, false, false, null, caches);
      PojoCache cache = SessionTestUtil.getDistributedCacheManagerFactoryPojoCache();
      JBossWebMetaData webMetaData = createWebMetaData(null, null, null, null, null);
      jbcm.init("test.war", webMetaData);     
      jbcm.start();

      assertFalse("With no config, not using JK", jbcm.getUseJK());
     
      cleanupManager(jbcm, cache);
     
      jbcm = SessionTestUtil.createManager("test" + ++testCount, 5, true, null, false, false, null, caches);
      cache = SessionTestUtil.getDistributedCacheManagerFactoryPojoCache();
     
      webMetaData = createWebMetaData(null, null, null, null, Boolean.TRUE);
      jbcm.init("test.war", webMetaData);     
      jbcm.start();

      assertTrue("With no jvmRoute but a config, using JK", jbcm.getUseJK());
     
      cleanupManager(jbcm, cache);
     
      jbcm = SessionTestUtil.createManager("test" + ++testCount, 5, true, null, false, false, "test", caches);
      cache = SessionTestUtil.getDistributedCacheManagerFactoryPojoCache();
     
      webMetaData = createWebMetaData(null, null, null, null, null);
      jbcm.init("test.war", webMetaData);     
      jbcm.start();

      assertTrue("With jvmRoute set, using JK", jbcm.getUseJK());
     
      cleanupManager(jbcm, cache);
     
      jbcm = SessionTestUtil.createManager("test" + ++testCount, 5, true, null, false, false, "test", caches);
      cache = SessionTestUtil.getDistributedCacheManagerFactoryPojoCache();
     
      webMetaData = createWebMetaData(null, null, null, null, Boolean.FALSE);
      jbcm.init("test.war", webMetaData);     
      jbcm.start();

      assertFalse("With a jvmRoute but config=false, not using JK", jbcm.getUseJK());
     
      cleanupManager(jbcm, cache);     
   }
View Full Code Here

   public void testSnapshot() throws Exception
   {
      log.info("Enter testSnapshot");
     
      ++testCount;
      JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, null, false, false, null, caches);
      PojoCache cache = SessionTestUtil.getDistributedCacheManagerFactoryPojoCache();
     
      JBossWebMetaData webMetaData = createWebMetaData(null, null, null, null, null);
      jbcm.init("test.war", webMetaData);     
      jbcm.start();

      assertEquals("With no config, using instant", SnapshotMode.INSTANT, jbcm.getSnapshotMode());
     
      cleanupManager(jbcm, cache);
     
      jbcm = SessionTestUtil.createManager("test" + ++testCount, 5, true, null, false, false, null, caches);
      cache = SessionTestUtil.getDistributedCacheManagerFactoryPojoCache();
     
      webMetaData = createWebMetaData(null, null, null, null, Boolean.TRUE);
      webMetaData.getReplicationConfig().setSnapshotMode(SnapshotMode.INTERVAL);
      webMetaData.getReplicationConfig().setSnapshotInterval(new Integer(2));
      jbcm.init("test.war", webMetaData);     
      jbcm.start();

      assertEquals("With config, using interval", SnapshotMode.INTERVAL, jbcm.getSnapshotMode());
      assertEquals("With config, using 2 second interval", 2, jbcm.getSnapshotInterval());
     
      cleanupManager(jbcm, cache);
     
   }
View Full Code Here

   {
      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);
      }
View Full Code Here

   {
      String warname = String.valueOf(++testId);
     
      // A war with a maxInactive of 2 secs and a maxIdle of 1
      JBossCacheManager[] mgrs = getCacheManagers(warname, 2, 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);        
      }
     
      // Failover request
      setHandler = new SetAttributesRequestHandler(newAttributes, 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.REPLACED, hsal1.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, 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);
      }
      else
      {
         assertEquals(2, SessionSpecListenerAttribute.invocations.size());
         assertEquals(SessionSpecListenerAttribute.Type.PASSIVATED, SessionSpecListenerAttribute.invocations.get(0));
         assertEquals(SessionSpecListenerAttribute.Type.PASSIVATED, SessionSpecListenerAttribute.invocations.get(1));
        
         validateNoNotifications(hsl0, hsal0, hsl1, hsal1, null);
         clearNotifications(null, null, null, null, SessionSpecListenerAttribute.invocations);
      }
     
      // Expire
      Thread.sleep(1000);
     
      jbcm0.backgroundProcess();
      jbcm1.backgroundProcess();
     
      if (!notify)
      {
         validateNoNotifications(hsl0, hsal0, hsl1, hsal1);
      }
View Full Code Here

TOP

Related Classes of org.jboss.web.tomcat.service.session.JBossCacheManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.