[jbosscache-commits] JBoss Cache SVN: r5123 - in core/trunk/src: test/java/org/jboss/cache/marshall and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Jan 14 10:34:07 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-01-14 10:34:07 -0500 (Mon, 14 Jan 2008)
New Revision: 5123

Modified:
   core/trunk/src/main/java/org/jboss/cache/RegionManager.java
   core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
   core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
Log:
Fixed default region activation issues

Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java	2008-01-14 14:53:44 UTC (rev 5122)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java	2008-01-14 15:34:07 UTC (rev 5123)
@@ -56,20 +56,8 @@
    protected final Set<Fqn> activationChangeNodes = Collections.synchronizedSet(new HashSet<Fqn>());
    protected Configuration configuration;
 
-   /**
-    * Constructs a new instance not attached to a cache.
-    */
-   public RegionManager()
-   {
-      // always create a default MARSHALLING region!
-      Region r = new RegionImpl(Fqn.ROOT, this);
-      r.registerContextClassLoader(Thread.currentThread().getContextClassLoader() == null ? this.getClass().getClassLoader() : Thread.currentThread().getContextClassLoader());
-      r.setActive(true);
-      regionsRegistry.put(Fqn.ROOT, r);
-   }
-
    @Inject
-   private void injectDependencies(CacheSPI cache, Configuration configuration)
+   void injectDependencies(CacheSPI cache, Configuration configuration)
    {
       this.cache = cache;
       this.configuration = configuration;
@@ -92,8 +80,6 @@
       }
 
       setDefaultInactive(configuration.isInactiveOnStartup());
-
-      if (defaultInactive) regionsRegistry.get(Fqn.ROOT).setActive(false);
    }
 
    @Stop
@@ -319,7 +305,6 @@
       {
          if (log.isTraceEnabled()) log.trace("Activating region " + fqn);
          Region r = getRegion(fqn, false);
-         if (r != null && r.getFqn() != null && r.getFqn().isRoot() && !fqn.isRoot() && defaultInactive) return;
          if (r != null)
          {
             if (!defaultInactive && r.getClassLoader() == null)
@@ -363,16 +348,6 @@
       {
          throw new RuntimeException(e);
       }
-
-//      if (!fqn.isRoot())
-//      {
-//         // activate parent regions
-//         Region parent = getRegion(fqn.getParent(), false);
-//         if (parent != null && !parent.isActive())
-//         {
-//            activate(parent.getFqn(), suppressRegionNotEmptyException);
-//         }
-//      }
    }
 
    /**
@@ -722,7 +697,6 @@
 
          if (region != null)
          {
-            if (region.getFqn().isRoot() && !fqn.isRoot() && !defaultInactive) return;
             if (defaultInactive && region.getClassLoader() == null)
             {
                // This region's state will no match that of a non-existent one

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java	2008-01-14 14:53:44 UTC (rev 5122)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java	2008-01-14 15:34:07 UTC (rev 5123)
@@ -9,6 +9,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
+import org.jboss.cache.factories.ComponentRegistry;
 import org.testng.annotations.Test;
 
 import java.io.ByteArrayInputStream;
@@ -82,11 +83,15 @@
       // 3.  marshall a (primitive response) - case such as a state transfer sending out boolean status
 
       // first create a stream to unmarshall.
-      RegionManager rm = new RegionManager();
+//      RegionManager rm = new RegionManager();
       final CacheMarshaller200 cm200 = new CacheMarshaller200();
+      c.setInactiveOnStartup(false);
       c.setUseRegionBasedMarshalling(true);
-      cm200.injectDependencies(new RegionManager(), c, getClass().getClassLoader());
-      cm200.init();
+      ComponentRegistry cr = new ComponentRegistry(c);
+      cr.registerComponent(cm200, CacheMarshaller200.class);
+      cr.start();
+
+      RegionManager rm = cr.getComponent(RegionManager.class);
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       ObjectOutputStream oos = new ObjectOutputStream(baos);
       final Fqn region = Fqn.fromString("/hello");

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java	2008-01-14 14:53:44 UTC (rev 5122)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java	2008-01-14 15:34:07 UTC (rev 5123)
@@ -82,7 +82,7 @@
       assertFalse("Should not be expecting any more regions", expectedRegions.hasNext());
    }
 
-   public void testDefaultRegion()
+   public void testNoDefaultRegion()
    {
       Fqn fqn1 = Fqn.fromString("/a/b/c");
       Fqn fqn2 = Fqn.fromString("/a/b/");
@@ -90,10 +90,17 @@
       r.getRegion(fqn1, true);
       r.getRegion(fqn2, true);
 
-      Region region = r.getRegion("/a", false);
+      Region region = null;
+      try
+      {
+         region = r.getRegion("/a", false);
+      }
+      catch (Exception e)
+      {
+         fail("If we don't set the default region, it still should be ok!");
+      }
 
-      assertNotNull("Default region is not null!", region);
-      assert region.getFqn().equals(Fqn.ROOT) : "Should be the default region";
+      assertNull("Default region is not null!", region);
    }
 
 
@@ -120,28 +127,28 @@
       Region r2 = r.getRegion(fqn2, true);
       Region r3 = r.getRegion(fqn3, true);
 
-      assertEquals("Expecting 4 regions", 4, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("Expecting 3 regions", 3, r.getAllRegions(Region.Type.ANY).size());
 
       // test that removal doesn't affect parent traversal.
       assertEquals(r3, r.getRegion(fqn3, false));
 
       r.removeRegion(Fqn.fromString(fqn3));
 
-      assertEquals("Expecting 3 regions", 3, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("Expecting 2 regions", 2, r.getAllRegions(Region.Type.ANY).size());
 
       // test that removal doesn't affect parent traversal.
       assertEquals("Should have retrieved parent region", r2, r.getRegion(fqn3, false));
 
       r.removeRegion(Fqn.fromString(fqn2));
 
-      assertEquals("Expecting 2 region", 2, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("Expecting 1 region", 1, r.getAllRegions(Region.Type.ANY).size());
 
       // test that removal doesn't affect parent traversal.
       assertEquals("Should have retrieved parent region", r1, r.getRegion(fqn3, false));
 
       r.removeRegion(Fqn.fromString(fqn1));
 
-      assertEquals("Expecting 1 regions (default region)", 1, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("Expecting 0 regions", 0, r.getAllRegions(Region.Type.ANY).size());
    }
 
    public void testGetRegionsMethods()
@@ -153,7 +160,7 @@
       @SuppressWarnings("unused")
       Region r1 = r.getRegion(f1, true), r2 = r.getRegion(f2, true), r3 = r.getRegion(f3, true), r4 = r.getRegion(f4, true);
 
-      assertEquals("5 regions should exist", 5, r.getAllRegions(Region.Type.ANY).size());
+      assertEquals("4 regions should exist", 4, r.getAllRegions(Region.Type.ANY).size());
 
       assertEquals("None of the regions should marshalling or active", 0, r.getAllRegions(Region.Type.MARSHALLING).size());
 




More information about the jbosscache-commits mailing list