[jboss-cvs] JBossAS SVN: r63778 - in trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 2 12:35:31 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-07-02 12:35:30 -0400 (Mon, 02 Jul 2007)
New Revision: 63778

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/ProvidedPrefixEntityQueryUnitTestCase.java
Modified:
   trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/classloader/EntityQueryTestBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityClassloaderTestBase.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityQueryRedeployUnitTestCase.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityQueryUnitTestCase.java
Log:
[EJBTHREE-955] Port EJBTHREE-954 to trunk

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/classloader/EntityQueryTestBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/classloader/EntityQueryTestBean.java	2007-07-02 16:32:33 UTC (rev 63777)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/classloader/EntityQueryTestBean.java	2007-07-02 16:35:30 UTC (rev 63778)
@@ -227,7 +227,7 @@
    private boolean getSawRegion(String regionName, Set sawEvent)
    {
       boolean saw = false;
-      Fqn fqn = Fqn.fromString("/" + regionName.replace(".", "/"));
+      Fqn fqn = Fqn.fromString(regionName);
       for (Iterator it = sawEvent.iterator(); it.hasNext();)
       {
          Fqn modified = (Fqn) it.next();

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityClassloaderTestBase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityClassloaderTestBase.java	2007-07-02 16:32:33 UTC (rev 63777)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityClassloaderTestBase.java	2007-07-02 16:35:30 UTC (rev 63778)
@@ -25,6 +25,7 @@
 import javax.naming.InitialContext;
 
 import org.hibernate.cache.StandardQueryCache;
+import org.jboss.ejb3.entity.SecondLevelCacheUtil;
 import org.jboss.ejb3.test.clusteredentity.classloader.AccountHolderPK;
 import org.jboss.ejb3.test.clusteredentity.classloader.EntityQueryTest;
 import org.jboss.test.JBossClusteredTestCase;
@@ -40,6 +41,8 @@
 extends JBossClusteredTestCase
 {
    public static final String EAR_NAME = "clusteredentity-classloader-test";
+   public static final String JAR_NAME = "clusteredentity-classloader-test";
+   public static final String PERSISTENCE_UNIT_NAME = "tempdb";
    
    protected org.jboss.logging.Logger log = getLog();
 
@@ -135,21 +138,22 @@
    
    protected void resetRegionUsageState()
    {  
-      sfsb0.getSawRegionModification(StandardQueryCache.class.getName());
-      sfsb0.getSawRegionModification("AccountRegion");
+      String stdName = createRegionName(StandardQueryCache.class.getName());
+      String acctName = createRegionName("AccountRegion");
       
-      sfsb0.getSawRegionAccess(StandardQueryCache.class.getName());
-      sfsb0.getSawRegionAccess("AccountRegion");
-
+      sfsb0.getSawRegionModification(stdName);
+      sfsb0.getSawRegionModification(acctName);
       
-      sfsb1.getSawRegionModification(StandardQueryCache.class.getName());
-      sfsb1.getSawRegionModification("AccountRegion");
+      sfsb0.getSawRegionAccess(stdName);
+      sfsb0.getSawRegionAccess(acctName);
       
-      sfsb1.getSawRegionAccess(StandardQueryCache.class.getName());
-      sfsb1.getSawRegionAccess("AccountRegion");
+      sfsb1.getSawRegionModification(stdName);
+      sfsb1.getSawRegionModification(acctName);
       
-      log.info("Region usage state cleared");
+      sfsb1.getSawRegionAccess(stdName);
+      sfsb1.getSawRegionAccess(acctName);
       
+      log.info("Region usage state cleared");      
    }
    
    protected void modifyEntities(EntityQueryTest bean)
@@ -169,7 +173,27 @@
       log.info("Standard entities restored to initial state");
    }
 
-   protected void queryTest(boolean setupEntities, boolean useNamedQuery, boolean useNamedRegion, boolean checkEmptyRegion)
+   /**
+    * Executes a series of entity operations and queries, checking that
+    * expected modifications and reads of the query cache occur.
+    * 
+    * @param setupEntities  <code>true</code> if entities don't exist and need
+    *                       to be created; <code>false</code> if they should
+    *                       exist and need to be returned to their initial state
+    * @param useNamedQuery  <code>true</code> if named queries are to be used;
+    *                       <code>false</code> if the EJBQL should be passed
+    *                       to the Query
+    * @param useNamedRegion <code>true</code> if the query should be cached in
+    *                       "AccountRegion"; <code>false</code> if it should be
+    *                       cached in the default region
+    * @param expectInactivatedRegion <code>true</code> if the test should assume
+    *                                the query cache region is inactive on each
+    *                                server until accessed on that server;
+    *                                <code>false</code> if it should be assumed
+    *                                the region is activated and able to 
+    *                                receive replication events.
+    */
+   protected void queryTest(boolean setupEntities, boolean useNamedQuery, boolean useNamedRegion, boolean expectInactivatedRegion)
    {
       if (setupEntities)
          standardEntitySetup();
@@ -180,12 +204,13 @@
       
       // Initial ops on node 0
       
-      String regionName = useNamedRegion ? "AccountRegion" : StandardQueryCache.class.getName();
+      String regionName = createRegionName(useNamedRegion ? "AccountRegion" : StandardQueryCache.class.getName());
       
       // Query on post code count
       assertEquals("63088 has correct # of accounts", 6, sfsb0.getCountForBranch("63088", useNamedQuery, useNamedRegion));
       
-      assertTrue("Query cache used", sfsb0.getSawRegionModification(regionName));
+      assertTrue("Query cache used " + regionName, 
+                 sfsb0.getSawRegionModification(regionName));
       // Clear the access state
       sfsb0.getSawRegionAccess(regionName);
       
@@ -196,25 +221,28 @@
       sleep(SLEEP_TIME);
       
       // If region isn't activated yet, should not have been modified      
-      if (checkEmptyRegion)
+      if (expectInactivatedRegion)
       {
-         assertFalse("Query cache remotely modified", sfsb1.getSawRegionModification(regionName));
+         assertFalse("Query cache remotely modified " + regionName, 
+                      sfsb1.getSawRegionModification(regionName));
          // Clear the access state
          sfsb1.getSawRegionAccess(regionName);
       }
-      else if (useNamedRegion)
+      else //if (useNamedRegion)
       {
-         assertTrue("Query cache remotely modified", sfsb1.getSawRegionModification(regionName));
+         assertTrue("Query cache remotely modified " + regionName, 
+                    sfsb1.getSawRegionModification(regionName));
          // Clear the access state
          sfsb1.getSawRegionAccess(regionName);         
       }
       
       assertEquals("63088 has correct # of accounts", 6, sfsb1.getCountForBranch("63088", useNamedQuery, useNamedRegion));
       
-      if (checkEmptyRegion)
+      if (expectInactivatedRegion)
       {
-         // Query should have been inserted
-         assertTrue("Query cache modified", sfsb1.getSawRegionModification(regionName));
+         // Query should have activated the region and then been inserted
+         assertTrue("Query cache modified " + regionName, 
+                    sfsb1.getSawRegionModification(regionName));
          // Clear the access state
          sfsb1.getSawRegionAccess(regionName);
       }
@@ -232,7 +260,8 @@
       
       assertEquals("Correct high balances for Jones", 40, sfsb0.getTotalBalance(JONES, useNamedQuery, useNamedRegion));
       
-      assertTrue("Query cache used", sfsb0.getSawRegionModification(regionName));
+      assertTrue("Query cache used " + regionName, 
+                 sfsb0.getSawRegionModification(regionName));
       // Clear the access state
       sfsb0.getSawRegionAccess(regionName);
       
@@ -245,30 +274,20 @@
       
       // First check if the previous queries replicated (if the region is replicable)
       
-      if (useNamedRegion)
-      {
-         assertTrue("Query cache remotely modified", sfsb1.getSawRegionModification(regionName));
-         // Clear the access state
-         sfsb1.getSawRegionAccess(regionName);
-      }
+      assertTrue("Query cache remotely modified " + regionName, 
+                 sfsb1.getSawRegionModification(regionName));
+      // Clear the access state
+      sfsb1.getSawRegionAccess(regionName);
       
       assertEquals("Correct branch for Smith", "94536", sfsb1.getBranch(SMITH, useNamedQuery, useNamedRegion));
       
       assertEquals("Correct high balances for Jones", 40, sfsb1.getTotalBalance(JONES, useNamedQuery, useNamedRegion));
       
-      if (useNamedRegion)
-      {
-         // Should be no change; query was already there
-         assertFalse("Query cache modified", sfsb1.getSawRegionModification(regionName));
-         assertTrue("Query cache accessed", sfsb1.getSawRegionAccess(regionName));
-      }
-      else
-      {
-         // Query should have been inserted
-         assertTrue("Query cache modified", sfsb1.getSawRegionModification(regionName));
-         // Clear the access state
-         sfsb1.getSawRegionAccess(regionName);
-      }      
+      // Should be no change; query was already there
+      assertFalse("Query cache modified " + regionName, 
+                  sfsb1.getSawRegionModification(regionName));
+      assertTrue("Query cache accessed " + regionName, 
+                 sfsb1.getSawRegionAccess(regionName));
       
       log.info("Second set of queries on node1 done");
       
@@ -298,10 +317,51 @@
       }
    }
    
+   protected String createRegionName(String noPrefix)
+   {
+      String prefix = createCacheRegionPrefix(getEarName(), getJarName(), getPersistenceUnitName());
+      return "/" + prefix + "/" + noPrefix.replace('.', '/');
+   }
+            
    protected String getEarName()
    {
       return EAR_NAME;
    }
+            
+   protected String getJarName()
+   {
+      return JAR_NAME;
+   }
+            
+   protected String getPersistenceUnitName()
+   {
+      return PERSISTENCE_UNIT_NAME;
+   }
+   
+   public static String createCacheRegionPrefix(String earName, String jarName, String unitName)
+   {
+      StringBuilder sb = new StringBuilder();
+      if (earName != null)
+      {
+         sb.append(earName);
+         if (!earName.endsWith(".ear")) 
+            sb.append("_ear");
+         sb.append(",");
+      }
+      if (jarName != null)
+      {
+         sb.append(jarName);
+         if (!jarName.endsWith(".jar"))
+            sb.append("_jar");
+         sb.append(",");
+      }
+      sb.append(unitName);
+      String raw = sb.toString();
+      // Replace any '.' otherwise the JBoss Cache integration may replace
+      // it with a '/' and it will become a level in the FQN
+      String escaped = raw.replace('.', '_');
+      return escaped;
+   }
 
    protected boolean isOptimistic()
    {

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityQueryRedeployUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityQueryRedeployUnitTestCase.java	2007-07-02 16:32:33 UTC (rev 63777)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityQueryRedeployUnitTestCase.java	2007-07-02 16:35:30 UTC (rev 63778)
@@ -45,14 +45,14 @@
    public void testRedeploy() throws Exception
    {
       // Set things up with the default region
-      queryTest(true, true, false, true);
+      queryTest(true, true, false, false);
       // Now get the named query regions active
       queryTest(false, true, true, true);
       
       redeploy();
       
       // Redo the test, but no entity creation
-      queryTest(false, true, false, true);
+      queryTest(false, true, false, false);
       queryTest(false, true, true, true);
    }
    

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityQueryUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityQueryUnitTestCase.java	2007-07-02 16:32:33 UTC (rev 63777)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EntityQueryUnitTestCase.java	2007-07-02 16:35:30 UTC (rev 63778)
@@ -45,7 +45,7 @@
    public void testManualQueryDefaultRegion() throws Exception
    {
       log.info("+++ start testManualQueryDefaultRegion");
-      queryTest(false, false);
+      queryTest(true, false, false, false);
       log.info("+++ end testManualQueryDefaultRegion");
    }
    
@@ -54,7 +54,7 @@
       log.info("+++ start testManualQueryNamedRegion");
       try
       {
-         queryTest(false, true);
+         queryTest(true, false, true, firstNamedRegionTest);
       }
       finally
       {
@@ -66,7 +66,7 @@
    public void testNamedQueryDefaultRegion() throws Exception
    {    
       log.info("+++ start testNamedQueryDefaultRegion");
-      queryTest(true, false);
+      queryTest(true, true, false, false);
       log.info("+++ end testNamedQueryDefaultRegion");
    }
    
@@ -75,7 +75,7 @@
       log.info("+++ start testNamedQueryNamedRegion");
       try
       {
-         queryTest(true, true);
+         queryTest(true, true, true, firstNamedRegionTest);
       }
       finally
       {
@@ -83,11 +83,6 @@
       }
       log.info("+++ start testNamedQueryNamedRegion");
    }
-
-   private void queryTest(boolean useNamedQuery, boolean useNamedRegion)
-   {
-      queryTest(true, useNamedQuery, useNamedRegion, firstNamedRegionTest);
-   }
    
    public static Test suite() throws Exception
    {

Copied: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/ProvidedPrefixEntityQueryUnitTestCase.java (from rev 62816, branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/ProvidedPrefixEntityQueryUnitTestCase.java)
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/ProvidedPrefixEntityQueryUnitTestCase.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/ProvidedPrefixEntityQueryUnitTestCase.java	2007-07-02 16:35:30 UTC (rev 63778)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ejb3.test.clusteredentity.unit;
+
+import org.jboss.ejb3.test.common.unit.DBSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Duplicates teh EntityQueryUnitTestCase, but with a
+ * hibernate.cache.region_prefix specified in persistence.xml.
+ * 
+ * @author Brian Stansberry
+ */
+public class ProvidedPrefixEntityQueryUnitTestCase extends EntityQueryUnitTestCase
+{
+   public static final String EAR_NAME = "clusteredentity-providedprefix-test";
+   public static final String PROVIDED_PREFIX = "myprefix";
+   
+   public ProvidedPrefixEntityQueryUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      Test t1 = getDeploySetup(ProvidedPrefixEntityQueryUnitTestCase.class, 
+                               EAR_NAME + ".ear");
+
+      suite.addTest(t1);
+
+      // Create an initializer for the test suite
+      DBSetup wrapper = new DBSetup(suite);
+      return wrapper;
+   }
+
+   @Override
+   protected String createRegionName(String noPrefix)
+   {
+      return "/" + PROVIDED_PREFIX + "/" + noPrefix.replace('.', '/');
+   }
+
+   @Override
+   protected String getEarName()
+   {
+      return EAR_NAME;
+   }
+
+   @Override
+   protected String getJarName()
+   {
+      return EAR_NAME;
+   }
+
+   
+   
+
+}




More information about the jboss-cvs-commits mailing list