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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 21 12:34:53 EDT 2010


Author: pferraro
Date: 2010-07-21 12:34:53 -0400 (Wed, 21 Jul 2010)
New Revision: 106989

Added:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/InfinispanHAPartitionCacheHandler.java
Modified:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImplTest.java
Log:
Add getCache() to sub-interface.  Validate value in unit tests.

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImpl.java	2010-07-21 16:24:37 UTC (rev 106988)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImpl.java	2010-07-21 16:34:53 UTC (rev 106989)
@@ -8,15 +8,14 @@
 import org.infinispan.lifecycle.ComponentStatus;
 import org.infinispan.manager.CacheContainer;
 import org.infinispan.manager.EmbeddedCacheManager;
-import org.jboss.ha.framework.server.spi.HAPartitionCacheHandler;
 import org.jboss.ha.ispn.CacheContainerRegistry;
 import org.jgroups.ChannelFactory;
 
 @SuppressWarnings("deprecation")
-public class HAPartitionCacheHandlerImpl implements HAPartitionCacheHandler
+public class HAPartitionCacheHandlerImpl<K, V> implements InfinispanHAPartitionCacheHandler<K, V>
 {
    private final CacheContainerRegistry registry;
-   private final AtomicReference<Cache<Object, Object>> cacheReference = new AtomicReference<Cache<Object, Object>>();
+   private final AtomicReference<Cache<K, V>> cacheReference = new AtomicReference<Cache<K, V>>();
    private final AtomicInteger acquireCount = new AtomicInteger();
    
    private volatile String cacheContainerName;
@@ -27,7 +26,21 @@
       this.registry = registry;
    }
    
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.framework.server.InfinispanHAPartitionCacheHandler#getCache()
+    */
    @Override
+   public Cache<K, V> getCache()
+   {
+      return this.cacheReference.get();
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.framework.server.spi.HAPartitionCacheHandler#acquireCache()
+    */
+   @Override
    public void acquireCache()
    {
       if (this.cacheReference.get() == null)
@@ -36,16 +49,20 @@
          
          String name = this.cacheName;
          
-         this.cacheReference.compareAndSet(null, (name != null) ? container.getCache(name) : container.getCache());
+         this.cacheReference.compareAndSet(null, (name != null) ? container.<K, V>getCache(name) : container.<K, V>getCache());
       }
       
       this.acquireCount.incrementAndGet();
    }
 
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.framework.server.spi.HAPartitionCacheHandler#startCache()
+    */
    @Override
    public void startCache()
    {
-      Cache<Object, Object> cache = this.cacheReference.get();
+      Cache<K, V> cache = this.cacheReference.get();
       
       if (cache == null)
       {
@@ -58,6 +75,10 @@
       }
    }
 
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.framework.server.spi.HAPartitionCacheHandler#releaseCache()
+    */
    @Override
    public void releaseCache()
    {
@@ -65,7 +86,7 @@
       
       if (count == 0)
       {
-         Cache<Object, Object> cache = this.cacheReference.getAndSet(null);
+         Cache<K, V> cache = this.cacheReference.getAndSet(null);
          
          if ((cache != null) && (cache.getStatus() == ComponentStatus.RUNNING))
          {
@@ -81,12 +102,20 @@
       }
    }
 
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.framework.server.spi.HAPartitionCacheHandler#getChannelStackName()
+    */
    @Override
    public String getChannelStackName()
    {
       return this.getTransportProperties().getProperty("stack");
    }
 
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.framework.server.spi.HAPartitionCacheHandler#getCacheChannelFactory()
+    */
    @Override
    public ChannelFactory getCacheChannelFactory()
    {
@@ -95,7 +124,7 @@
    
    private Properties getTransportProperties()
    {
-      Cache<Object, Object> cache = this.cacheReference.get();
+      Cache<K, V> cache = this.cacheReference.get();
       
       if (cache == null)
       {
@@ -114,6 +143,10 @@
       return manager.getGlobalConfiguration().getTransportProperties();
    }
    
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.framework.server.spi.HAPartitionCacheHandler#getCacheConfigName()
+    */
    @Override
    public String getCacheConfigName()
    {
@@ -134,9 +167,4 @@
    {
       this.cacheContainerName = cacheContainerName;
    }
-   
-   public Cache<Object, Object> getCache()
-   {
-      return this.cacheReference.get();
-   }
 }

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/InfinispanHAPartitionCacheHandler.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/InfinispanHAPartitionCacheHandler.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/InfinispanHAPartitionCacheHandler.java	2010-07-21 16:34:53 UTC (rev 106989)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.ha.framework.server;
+
+import org.infinispan.Cache;
+import org.jboss.ha.framework.server.spi.HAPartitionCacheHandler;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface InfinispanHAPartitionCacheHandler<K, V> extends HAPartitionCacheHandler
+{
+   Cache<K, V> getCache();
+}

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImplTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImplTest.java	2010-07-21 16:24:37 UTC (rev 106988)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImplTest.java	2010-07-21 16:34:53 UTC (rev 106989)
@@ -32,8 +32,10 @@
       @SuppressWarnings("unchecked")
       Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
       
-      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl(registry);
+      InfinispanHAPartitionCacheHandler<Object, Object> handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       
+      Assert.assertNull(handler.getCache());
+      
       EasyMock.expect(registry.getCacheContainer(null)).andReturn(container);
       EasyMock.expect(container.getCache()).andReturn(cache);
       
@@ -42,6 +44,9 @@
       handler.acquireCache();
 
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
 
       // Release w/out start
@@ -52,6 +57,9 @@
       handler.releaseCache();
 
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertNull(handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
       
       // Re-acquire
@@ -63,6 +71,9 @@
       handler.acquireCache();
 
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
       
       // start cache
@@ -74,6 +85,9 @@
       handler.startCache();
       
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
 
       // Already started
@@ -84,6 +98,9 @@
       handler.startCache();
       
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
 
       // Release
@@ -95,6 +112,9 @@
       handler.releaseCache();
       
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertNull(handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
    }
 
@@ -106,10 +126,12 @@
       @SuppressWarnings("unchecked")
       Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
       
-      HAPartitionCacheHandlerImpl handler = new HAPartitionCacheHandlerImpl(registry);
+      HAPartitionCacheHandlerImpl<Object, Object> handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       handler.setCacheContainerName("container");
       handler.setCacheConfigName("cache");
       
+      Assert.assertNull(handler.getCache());
+      
       EasyMock.expect(registry.getCacheContainer("container")).andReturn(container);
       EasyMock.expect(container.getCache("cache")).andReturn(cache);
       
@@ -118,6 +140,9 @@
       handler.acquireCache();
 
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
 
       // Release w/out start
@@ -126,8 +151,11 @@
       EasyMock.replay(registry, container, cache);
       
       handler.releaseCache();
-
+      
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertNull(handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
       
       // Re-acquire
@@ -137,8 +165,11 @@
       EasyMock.replay(registry, container, cache);
       
       handler.acquireCache();
-
+      
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
       
       // start cache
@@ -150,8 +181,11 @@
       handler.startCache();
       
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
-
+      
       // Already started
       EasyMock.expect(cache.getStatus()).andReturn(ComponentStatus.RUNNING);
       
@@ -160,6 +194,9 @@
       handler.startCache();
       
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
 
       // Release
@@ -171,6 +208,9 @@
       handler.releaseCache();
       
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertNull(handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
    }
    
@@ -182,7 +222,7 @@
       @SuppressWarnings("unchecked")
       final Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
       
-      final HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl(registry);
+      final InfinispanHAPartitionCacheHandler<Object, Object> handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       
       // Acquire and start cache
       EasyMock.expect(registry.getCacheContainer(null)).andReturn(container);
@@ -196,6 +236,9 @@
       handler.startCache();
 
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
 
       EasyMock.makeThreadSafe(cache, true);
@@ -262,6 +305,7 @@
       EasyMock.verify(registry, container, cache);
       
       Assert.assertTrue(exceptions.toString(), exceptions.isEmpty());
+      Assert.assertSame(cache, handler.getCache());
 
       EasyMock.reset(registry, container, cache);
       
@@ -274,6 +318,9 @@
       handler.releaseCache();
       
       EasyMock.verify(registry, container, cache);
+      
+      Assert.assertNull(handler.getCache());
+      
       EasyMock.reset(registry, container, cache);
    }
    
@@ -282,7 +329,7 @@
    {
       CacheContainerRegistry registry = EasyMock.createStrictMock(CacheContainerRegistry.class);
       
-      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl(registry);
+      InfinispanHAPartitionCacheHandler<Object, Object> handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       
       EasyMock.replay(registry);
       
@@ -301,6 +348,7 @@
       
       Assert.assertNotNull(exception);
       Assert.assertTrue(exception.toString(), exception instanceof IllegalStateException);
+      Assert.assertNull(handler.getCache());
    }
 
    @Test
@@ -308,7 +356,7 @@
    {
       CacheContainerRegistry registry = EasyMock.createStrictMock(CacheContainerRegistry.class);
       
-      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl(registry);
+      InfinispanHAPartitionCacheHandler<Object, Object> handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       
       EasyMock.replay(registry);
       
@@ -327,6 +375,7 @@
       
       Assert.assertNotNull(exception);
       Assert.assertTrue(exception.toString(), exception instanceof IllegalStateException);
+      Assert.assertNull(handler.getCache());
    }
    
    @Test
@@ -334,7 +383,7 @@
    {
       CacheContainerRegistry registry = EasyMock.createStrictMock(CacheContainerRegistry.class);
       
-      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl(registry);
+      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       
       try
       {
@@ -353,7 +402,7 @@
    {
       CacheContainerRegistry registry = EasyMock.createStrictMock(CacheContainerRegistry.class);
       
-      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl(registry);
+      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       
       try
       {
@@ -375,7 +424,7 @@
       @SuppressWarnings("unchecked")
       Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
       
-      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl(registry);
+      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       
       EasyMock.expect(registry.getCacheContainer(null)).andReturn(container);
       EasyMock.expect(container.getCache()).andReturn(cache);
@@ -414,7 +463,7 @@
       @SuppressWarnings("unchecked")
       Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
       
-      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl(registry);
+      HAPartitionCacheHandler handler = new HAPartitionCacheHandlerImpl<Object, Object>(registry);
       
       EasyMock.expect(registry.getCacheContainer(null)).andReturn(container);
       EasyMock.expect(container.getCache()).andReturn(cache);



More information about the jboss-cvs-commits mailing list