[jboss-cvs] JBossAS SVN: r107504 - in projects/cluster/ha-server-ispn/trunk/src: test/java/org/jboss/ha/ispn and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 9 12:39:15 EDT 2010


Author: pferraro
Date: 2010-08-09 12:39:15 -0400 (Mon, 09 Aug 2010)
New Revision: 107504

Modified:
   projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerRegistry.java
   projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java
Log:
Handle non-serializable jndi binding

Modified: projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerRegistry.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerRegistry.java	2010-08-09 15:45:28 UTC (rev 107503)
+++ projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerRegistry.java	2010-08-09 16:39:15 UTC (rev 107504)
@@ -40,6 +40,7 @@
 import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationEntry;
 import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationSource;
 import org.jboss.logging.Logger;
+import org.jboss.util.naming.NonSerializableFactory;
 
 /**
  * Cache container registry that populates itself using a specified factory from configuration from a specified source.
@@ -120,9 +121,12 @@
       
       for (Map.Entry<String, CacheContainer> entry: this.containers.values())
       {
+         String jndiName = entry.getKey();
+         
          try
          {
-            this.context.unbind(entry.getKey());
+            this.context.unbind(jndiName);
+            NonSerializableFactory.unbind(jndiName);
          }
          catch (NamingException e)
          {
@@ -180,7 +184,7 @@
       this.containers.put(entry.getId(), new AbstractMap.SimpleImmutableEntry<String, CacheContainer>(jndiName, container));
       
       // Bind cache container to jndi
-      this.context.bind(jndiName, container);
+      this.bind(jndiName, container);
    }
    
    private Map<String, String> mapAliases(CacheContainerRegistryConfigurationEntry entry)
@@ -213,7 +217,18 @@
       {
          entry.getValue().stop();
          
-         this.context.unbind(entry.getKey());
+         this.unbind(entry.getKey());
       }
    }
+   
+   private void bind(String name, Object value) throws NamingException
+   {
+      NonSerializableFactory.rebind(this.context, name, value);
+   }
+   
+   private void unbind(String name) throws NamingException
+   {
+      this.context.unbind(name);
+      NonSerializableFactory.unbind(name);
+   }
 }

Modified: projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java	2010-08-09 15:45:28 UTC (rev 107503)
+++ projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java	2010-08-09 16:39:15 UTC (rev 107504)
@@ -8,6 +8,8 @@
 import java.util.Set;
 
 import javax.naming.Context;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
 
 import junit.framework.Assert;
 
@@ -21,6 +23,7 @@
 import org.jboss.ha.ispn.config.CacheContainerRegistryConfiguration;
 import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationEntry;
 import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationSource;
+import org.jboss.util.naming.NonSerializableFactory;
 import org.junit.Test;
 
 public class DefaultCacheContainerRegistryTest
@@ -38,6 +41,7 @@
       CacheContainer otherCacheManager = EasyMock.createStrictMock(CacheContainer.class);
       Context context = EasyMock.createNiceMock(Context.class);
       Capture<CacheContainerConfiguration> capturedConfiguration = new Capture<CacheContainerConfiguration>(CaptureType.ALL);
+      Capture<Reference> capturedReferences = new Capture<Reference>(CaptureType.ALL);
       
       InfinispanConfiguration config = InfinispanConfiguration.newInfinispanConfiguration("config-samples/minimal.xml");
 
@@ -63,12 +67,12 @@
       EasyMock.expect(factory.createCacheContainer(EasyMock.capture(capturedConfiguration), EasyMock.eq(Collections.<String, String>emptyMap()))).andReturn(defaultCacheManager);
       EasyMock.expect(context.composeName("default", "java:CacheManager")).andReturn("java:CacheManager/default");
       
-      context.bind("java:CacheManager/default", defaultCacheManager);
+      context.rebind(EasyMock.eq("java:CacheManager/default"), EasyMock.capture(capturedReferences));
 
       EasyMock.expect(factory.createCacheContainer(EasyMock.capture(capturedConfiguration), EasyMock.eq(Collections.<String, String>emptyMap()))).andReturn(otherCacheManager);
       EasyMock.expect(context.composeName("other", "java:CacheManager")).andReturn("java:CacheManager/other");
       
-      context.bind("java:CacheManager/other", otherCacheManager);
+      context.rebind(EasyMock.eq("java:CacheManager/other"), EasyMock.capture(capturedReferences));
 
       EasyMock.replay(factory, source, context, defaultCacheManager, otherCacheManager);
       
@@ -105,6 +109,19 @@
       
       Assert.assertSame(registry, DefaultCacheContainerRegistry.getInstance());
       
+      List<Reference> references = capturedReferences.getValues();
+      Assert.assertEquals(2, references.size());
+      Reference reference = references.get(0);
+      RefAddr addr = reference.get("nns");
+      Assert.assertNotNull(addr);
+      Assert.assertEquals("java:CacheManager/default", addr.getContent());
+      Assert.assertSame(defaultCacheManager, NonSerializableFactory.lookup("java:CacheManager/default"));
+      reference = references.get(1);
+      addr = reference.get("nns");
+      Assert.assertNotNull(addr);
+      Assert.assertEquals("java:CacheManager/other", addr.getContent());
+      Assert.assertSame(otherCacheManager, NonSerializableFactory.lookup("java:CacheManager/other"));
+      
       EasyMock.reset(factory, source, context, defaultCacheManager, otherCacheManager);
       
       
@@ -120,6 +137,8 @@
       EasyMock.verify(factory, source, context, defaultCacheManager, otherCacheManager);
 
       Assert.assertNull(DefaultCacheContainerRegistry.getInstance());
+      Assert.assertNull(NonSerializableFactory.lookup("java:CacheManager/default"));
+      Assert.assertNull(NonSerializableFactory.lookup("java:CacheManager/other"));
       
       EasyMock.reset(factory, source, context, defaultCacheManager, otherCacheManager);
    }
@@ -137,6 +156,7 @@
       CacheContainer otherCacheManager = EasyMock.createStrictMock(CacheContainer.class);
       Context context = EasyMock.createStrictMock(Context.class);
       Capture<CacheContainerConfiguration> capturedConfiguration = new Capture<CacheContainerConfiguration>(CaptureType.ALL);
+      Capture<Reference> capturedReferences = new Capture<Reference>(CaptureType.ALL);
       
       InfinispanConfiguration config = InfinispanConfiguration.newInfinispanConfiguration("config-samples/minimal.xml");
 
@@ -174,12 +194,12 @@
       
       EasyMock.expect(factory.createCacheContainer(EasyMock.capture(capturedConfiguration), EasyMock.eq(Collections.singletonMap("legacy-other-cache", "other-cache")))).andReturn(otherCacheManager);
       
-      context.bind("java:other", otherCacheManager);
+      context.rebind(EasyMock.eq("java:other"), EasyMock.capture(capturedReferences));
 
       EasyMock.expect(factory.createCacheContainer(EasyMock.capture(capturedConfiguration), EasyMock.eq(Collections.singletonMap("legacy-default-cache", "default-cache")))).andReturn(defaultCacheManager);
       EasyMock.expect(context.composeName("default", "java:Infinispan")).andReturn("java:Infinispan/default");
       
-      context.bind("java:Infinispan/default", defaultCacheManager);
+      context.rebind(EasyMock.eq("java:Infinispan/default"), EasyMock.capture(capturedReferences));
 
       EasyMock.replay(factory, provider, context, defaultCacheManager, otherCacheManager);
       
@@ -216,6 +236,19 @@
       
       Assert.assertSame(registry, DefaultCacheContainerRegistry.getInstance());
       
+      List<Reference> references = capturedReferences.getValues();
+      Assert.assertEquals(2, references.size());
+      Reference reference = references.get(0);
+      RefAddr addr = reference.get("nns");
+      Assert.assertNotNull(addr);
+      Assert.assertEquals("java:other", addr.getContent());
+      Assert.assertSame(otherCacheManager, NonSerializableFactory.lookup("java:other"));
+      reference = references.get(1);
+      addr = reference.get("nns");
+      Assert.assertNotNull(addr);
+      Assert.assertEquals("java:Infinispan/default", addr.getContent());
+      Assert.assertSame(defaultCacheManager, NonSerializableFactory.lookup("java:Infinispan/default"));
+      
       EasyMock.reset(factory, provider, context, defaultCacheManager, otherCacheManager);
 
       
@@ -231,6 +264,8 @@
       EasyMock.verify(factory, context, defaultCacheManager, otherCacheManager);
       
       Assert.assertNull(DefaultCacheContainerRegistry.getInstance());
+      Assert.assertNull(NonSerializableFactory.lookup("java:other"));
+      Assert.assertNull(NonSerializableFactory.lookup("java:Infinispan/default"));
       
       EasyMock.reset(factory, context, defaultCacheManager, otherCacheManager);
    }



More information about the jboss-cvs-commits mailing list