[jboss-cvs] JBossAS SVN: r73111 - in trunk/testsuite/src/main/org/jboss/test/cluster: testutil and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 7 11:45:36 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-05-07 11:45:36 -0400 (Wed, 07 May 2008)
New Revision: 73111

Added:
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/JGroupsConfigSupport.java
Modified:
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionCountUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java
Log:
Factor out some utility methods for reuse

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionCountUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionCountUnitTestCase.java	2008-05-07 15:30:31 UTC (rev 73110)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionCountUnitTestCase.java	2008-05-07 15:45:36 UTC (rev 73111)
@@ -34,12 +34,8 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.pojo.PojoCache;
 import org.jboss.logging.Logger;
-import org.jboss.metadata.javaee.spec.EmptyMetaData;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
-import org.jboss.metadata.web.jboss.PassivationConfig;
-import org.jboss.metadata.web.jboss.ReplicationConfig;
-import org.jboss.metadata.web.jboss.ReplicationGranularity;
-import org.jboss.metadata.web.jboss.ReplicationTrigger;
+import org.jboss.test.cluster.testutil.JGroupsConfigSupport;
 import org.jboss.test.cluster.testutil.SessionTestUtil;
 import org.jboss.web.tomcat.service.session.JBossCacheManager;
 
@@ -52,13 +48,10 @@
 public class SessionCountUnitTestCase extends TestCase
 {
    private static final Logger log = Logger.getLogger(SessionCountUnitTestCase.class);
-   private static final String UDP_PORT = "34567";
    
    private static long testCount = System.currentTimeMillis();
    
-   private String bind_address;
-   private String udp_group;
-   private String udp_port;
+   private JGroupsConfigSupport jgroupsSupport;
    private Set<PojoCache> caches = new HashSet<PojoCache>();
    private String tempDir;
    
@@ -79,20 +72,9 @@
       super.setUp();
       
       // Set system properties to properly bind JGroups channels
+      jgroupsSupport = new JGroupsConfigSupport();
+      jgroupsSupport.setUp();
       
-      // First, preserve any existing values
-      bind_address = System.getProperty("jgroups.bind_addr");
-      udp_group = System.getProperty("jboss.partition.udpGroup");
-      udp_port = System.getProperty("jboss.partition.udpPort");
-      
-      System.setProperty("jgroups.bind_addr", System.getProperty("jbosstest.cluster.node0", "127.0.0.1"));
-      String grp = System.getProperty("jbosstest.udpGroup");
-      if (grp != null && grp.length() > 0)
-      {
-         System.setProperty("jboss.partition.udpGroup", grp);
-      }
-      System.setProperty("jboss.partition.udpPort", UDP_PORT);
-      
       File tmpDir = new File(System.getProperty("java.io.tmpdir"));
       File root = new File(tmpDir, getClass().getSimpleName());
       tempDir = root.getAbsolutePath();
@@ -104,20 +86,8 @@
       super.tearDown();
       
       // Restore any system properties we set in setUp
-      if (bind_address == null)
-         System.clearProperty("jgroups.bind_addr");
-      else
-         System.setProperty("jgroups.bind_addr", bind_address);
-      if (udp_group == null)
-         System.clearProperty("jboss.partition.udpGroup");
-      else
-         System.setProperty("jboss.partition.udpGroup", udp_group);
+      jgroupsSupport.tearDown();
       
-      if (udp_port == null)
-         System.clearProperty("jboss.partition.udpPort");
-      else
-         System.setProperty("jboss.partition.udpPort", udp_port);
-      
       for (PojoCache cache : caches)
       { 
          // Try to clean up so we avoid loading sessions 
@@ -163,7 +133,7 @@
       
       JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, null, false, false, null, caches);
        
-      JBossWebMetaData webMetaData = createWebMetaData(2);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(2);
       jbcm.init("test.war", webMetaData);
       
       jbcm.start();
@@ -187,7 +157,7 @@
       
       // Confirm a session timeout clears space
       sess1.setMaxInactiveInterval(1);       
-      sleep(1100);      
+      SessionTestUtil.sleepThread(1100);      
       
       createAndUseSession(jbcm, "3", true, true);      
       
@@ -206,7 +176,7 @@
       String passDir = getPassivationDir(testCount, 1);
       JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, passDir, false, false, null, caches);
        
-      JBossWebMetaData webMetaData = createWebMetaData(1, true, 1, -1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 1, -1);
       jbcm.init("test.war", webMetaData);
       
       jbcm.start();
@@ -227,7 +197,7 @@
       
       // Confirm a session timeout clears space
       sess1.setMaxInactiveInterval(1);       
-      sleep(1100);      
+      SessionTestUtil.sleepThread(1100);      
       
       createAndUseSession(jbcm, "2", true, true);      
       
@@ -238,7 +208,7 @@
       assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
 
       //    Sleep past maxIdleTime
-      sleep(1100);        
+      SessionTestUtil.sleepThread(1100);        
       
       assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
       
@@ -260,7 +230,7 @@
       String passDir = getPassivationDir(testCount, 1);
       JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, passDir, false, false, null, caches);
       
-      JBossWebMetaData webMetaData = createWebMetaData(1, true, 3, 1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
       jbcm.init("test.war", webMetaData);
       
       jbcm.start();
@@ -281,7 +251,7 @@
       
       // Confirm a session timeout clears space
       sess1.setMaxInactiveInterval(1);       
-      sleep(1100);      
+      SessionTestUtil.sleepThread(1100);      
       
       createAndUseSession(jbcm, "2", true, false);      
       
@@ -291,7 +261,7 @@
       assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
 
       //    Sleep past minIdleTime
-      sleep(1100);        
+      SessionTestUtil.sleepThread(1100);        
       
 //      assertTrue("Session 2 still valid", sess2.isValid());
       assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
@@ -312,7 +282,7 @@
       ++testCount;
       JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, null, false, false, null, caches);
       
-      JBossWebMetaData webMetaData = createWebMetaData(1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1);
       jbcm0.init("test.war", webMetaData);
       
       jbcm0.start();
@@ -345,7 +315,7 @@
       // Confirm a session timeout clears space
       sess1.setMaxInactiveInterval(1);     
       useSession(jbcm0, "1");
-      sleep(jbcm0.getMaxInactiveInterval() * 1000 + 100);      
+      SessionTestUtil.sleepThread(jbcm0.getMaxInactiveInterval() * 1000 + 100);      
       
       createAndUseSession(jbcm1, "2", true, true);      
       
@@ -368,7 +338,7 @@
       String passDir = getPassivationDir(testCount, 1);
       JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, false, null, caches);
       
-      JBossWebMetaData webMetaData = createWebMetaData(1, true, 1, -1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 1, -1);
       jbcm0.init("test.war", webMetaData);
       
       jbcm0.start();
@@ -402,7 +372,7 @@
       createAndUseSession(jbcm1, "2", false, false);      
       
       //    Sleep past maxIdleTime      
-      sleep(1100);        
+      SessionTestUtil.sleepThread(1100);        
       
       assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
        
@@ -427,7 +397,7 @@
       String passDir = getPassivationDir(testCount, 1);
       JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, false, null, caches);
       
-      JBossWebMetaData webMetaData = createWebMetaData(1, true, 3, 1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
       jbcm0.init("test.war", webMetaData);
       
       jbcm0.start();
@@ -461,7 +431,7 @@
       createAndUseSession(jbcm1, "2", false, false);      
       
       // Sleep past maxIdleTime      
-      sleep(1100);        
+      SessionTestUtil.sleepThread(1100);        
       
       assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
        
@@ -487,7 +457,7 @@
       String passDir = getPassivationDir(testCount, 1);
       JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, true, false, null, caches);
       
-      JBossWebMetaData webMetaData = createWebMetaData(1, true, 3, 1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
       jbcm0.init("test.war", webMetaData);
       
       jbcm0.start();
@@ -521,7 +491,7 @@
       createAndUseSession(jbcm1, "2", false, false);      
       
       // Sleep past maxIdleTime      
-      sleep(1100);        
+      SessionTestUtil.sleepThread(1100);        
       
       assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
        
@@ -547,7 +517,7 @@
       String passDir = getPassivationDir(testCount, 1);
       JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, true, null, caches);
       
-      JBossWebMetaData webMetaData = createWebMetaData(1, true, 3, 1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
       jbcm0.init("test.war", webMetaData);
       
       jbcm0.start();
@@ -581,7 +551,7 @@
       createAndUseSession(jbcm1, "2", false, false);      
       
       // Sleep past maxIdleTime      
-      sleep(1100);        
+      SessionTestUtil.sleepThread(1100);        
       
       assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
        
@@ -607,7 +577,7 @@
       String passDir = getPassivationDir(testCount, 1);
       JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, true, true, null, caches);
       
-      JBossWebMetaData webMetaData = createWebMetaData(1, true, 3, 1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
       jbcm0.init("test.war", webMetaData);
       
       jbcm0.start();
@@ -641,7 +611,7 @@
       createAndUseSession(jbcm1, "2", false, false);      
       
       // Sleep past maxIdleTime      
-      sleep(1100);        
+      SessionTestUtil.sleepThread(1100);        
       
       assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
        
@@ -681,7 +651,7 @@
       JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 300, true, passDir, false, false, null, caches);
       PojoCache cache = jbcm.getPojoCache();
       
-      JBossWebMetaData webMetaData = createWebMetaData(2, true, 3, 1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(2, true, 3, 1);
       jbcm.init("test.war", webMetaData);
       
       jbcm.start();
@@ -706,7 +676,7 @@
       assertEquals("Expired session count correct", 0, jbcm.getExpiredSessionCount());
 
       //    Sleep past minIdleTime
-      sleep(1100);
+      SessionTestUtil.sleepThread(1100);
       
       assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
       
@@ -749,7 +719,7 @@
       assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
       
       // Sleep past minIdleTime
-      sleep(1100);
+      SessionTestUtil.sleepThread(1100);
       
       createAndUseSession(jbcm, "4", true, true); 
    }
@@ -780,7 +750,7 @@
       JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 300, false, passDir, totalReplication, marshalling, null, caches);
       PojoCache cache = jbcm.getPojoCache();
       
-      JBossWebMetaData webMetaData = createWebMetaData(2, true, 3, 1);
+      JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(2, true, 3, 1);
       jbcm.init("test.war", webMetaData);
       
       jbcm.start();
@@ -826,7 +796,7 @@
       assertEquals("Expired session count correct", 0, jbcm1.getExpiredSessionCount());
 
       //    Sleep past minIdleTime
-      sleep(1100);
+      SessionTestUtil.sleepThread(1100);
       
       assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
       
@@ -882,7 +852,7 @@
       assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
       
       // Sleep past minIdleTime
-      sleep(1100);
+      SessionTestUtil.sleepThread(1100);
       
       createAndUseSession(jbcm, "4", true, true); 
    }
@@ -919,29 +889,6 @@
       
    }
    
-   private JBossWebMetaData createWebMetaData(int maxSessions)
-   {
-      return createWebMetaData(maxSessions, false, -1, -1);
-   }
-   
-   private JBossWebMetaData createWebMetaData(int maxSessions, boolean passivation,
-                                              int maxIdle, int minIdle)
-   {
-      JBossWebMetaData webMetaData = new JBossWebMetaData();
-      webMetaData.setDistributable(new EmptyMetaData());
-      webMetaData.setMaxActiveSessions(new Integer(maxSessions));
-      PassivationConfig pcfg = new PassivationConfig();
-      pcfg.setUseSessionPassivation(Boolean.valueOf(passivation));
-      pcfg.setPassivationMaxIdleTime(new Integer(maxIdle));
-      pcfg.setPassivationMinIdleTime(new Integer(minIdle));
-      webMetaData.setPassivationConfig(pcfg);
-      ReplicationConfig repCfg = new ReplicationConfig();
-      repCfg.setReplicationGranularity(ReplicationGranularity.SESSION);
-      repCfg.setReplicationTrigger(ReplicationTrigger.SET_AND_NON_PRIMITIVE_GET);
-      webMetaData.setReplicationConfig(repCfg);
-      return webMetaData;
-   }
-   
    private Session createAndUseSession(JBossCacheManager jbcm, String id, 
                            boolean canCreate, boolean access)
          throws Exception
@@ -993,15 +940,6 @@
       
       sess.endAccess();
    }
-
-   private void sleep(long time)
-   {
-      try
-      {
-         Thread.sleep(time);
-      }
-      catch (InterruptedException e) {}
-   }
    
    private String getPassivationDir(long testCount, int cacheCount)
    {

Added: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/JGroupsConfigSupport.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/JGroupsConfigSupport.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/JGroupsConfigSupport.java	2008-05-07 15:45:36 UTC (rev 73111)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.cluster.testutil;
+
+/**
+ * @author Brian Stansberry
+ *
+ */
+public class JGroupsConfigSupport
+{
+   private static final String UDP_PORT = "34567";
+   
+   private String bind_address;
+   private String udp_group;
+   private String udp_port;
+   
+   public void setUp()
+   {
+      // Set system properties to properly bind JGroups channels
+      
+      // First, preserve any existing values
+      bind_address = System.getProperty("jgroups.bind_addr");
+      udp_group = System.getProperty("jboss.partition.udpGroup");
+      udp_port = System.getProperty("jboss.partition.udpPort");
+      
+      System.setProperty("jgroups.bind_addr", System.getProperty("jbosstest.cluster.node0", "127.0.0.1"));
+      String grp = System.getProperty("jbosstest.udpGroup");
+      if (grp != null && grp.length() > 0)
+      {
+         System.setProperty("jboss.partition.udpGroup", grp);
+      }
+      System.setProperty("jboss.partition.udpPort", UDP_PORT);
+   }
+   
+   public void tearDown()
+   {      
+      // Restore any system properties we set in setUp
+      if (bind_address == null)
+         System.clearProperty("jgroups.bind_addr");
+      else
+         System.setProperty("jgroups.bind_addr", bind_address);
+      if (udp_group == null)
+         System.clearProperty("jboss.partition.udpGroup");
+      else
+         System.setProperty("jboss.partition.udpGroup", udp_group);
+      
+      if (udp_port == null)
+         System.clearProperty("jboss.partition.udpPort");
+      else
+         System.setProperty("jboss.partition.udpPort", udp_port);
+   }
+}

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java	2008-05-07 15:30:31 UTC (rev 73110)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java	2008-05-07 15:45:36 UTC (rev 73111)
@@ -43,6 +43,12 @@
 import org.jboss.cache.loader.FileCacheLoaderConfig;
 import org.jboss.cache.pojo.PojoCache;
 import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.metadata.javaee.spec.EmptyMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.metadata.web.jboss.PassivationConfig;
+import org.jboss.metadata.web.jboss.ReplicationConfig;
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.metadata.web.jboss.ReplicationTrigger;
 import org.jboss.metadata.web.jboss.SnapshotMode;
 import org.jboss.test.cluster.web.CacheHelper;
 import org.jboss.test.cluster.web.MockEngine;
@@ -132,6 +138,29 @@
       return config;
    } 
    
+   public static JBossWebMetaData createWebMetaData(int maxSessions)
+   {
+      return createWebMetaData(maxSessions, false, -1, -1);
+   }
+   
+   public static JBossWebMetaData createWebMetaData(int maxSessions, boolean passivation,
+                                              int maxIdle, int minIdle)
+   {
+      JBossWebMetaData webMetaData = new JBossWebMetaData();
+      webMetaData.setDistributable(new EmptyMetaData());
+      webMetaData.setMaxActiveSessions(new Integer(maxSessions));
+      PassivationConfig pcfg = new PassivationConfig();
+      pcfg.setUseSessionPassivation(Boolean.valueOf(passivation));
+      pcfg.setPassivationMaxIdleTime(new Integer(maxIdle));
+      pcfg.setPassivationMinIdleTime(new Integer(minIdle));
+      webMetaData.setPassivationConfig(pcfg);
+      ReplicationConfig repCfg = new ReplicationConfig();
+      repCfg.setReplicationGranularity(ReplicationGranularity.SESSION);
+      repCfg.setReplicationTrigger(ReplicationTrigger.SET_AND_NON_PRIMITIVE_GET);
+      webMetaData.setReplicationConfig(repCfg);
+      return webMetaData;
+   }
+   
    public static Object getSessionVersion(MBeanServerConnection adaptor, String sessionFqn) throws Exception
    {
       return adaptor.invoke(CacheHelper.OBJECT_NAME, 




More information about the jboss-cvs-commits mailing list