[jboss-cvs] JBossAS SVN: r107033 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 22 12:48:03 EDT 2010


Author: pferraro
Date: 2010-07-22 12:48:01 -0400 (Thu, 22 Jul 2010)
New Revision: 107033

Added:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactory.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactory.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactoryImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactoryTest.java
Modified:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java
Log:
Extract factories for creating SessionAttributeStorage and SessionAttributeMarshaller from DistributedCacheManagerFactoryImpl.
Add unit tests for each.

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java	2010-07-22 16:37:32 UTC (rev 107032)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -22,64 +22,48 @@
 package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
 
 import org.infinispan.manager.CacheContainer;
-import org.jboss.ha.framework.server.MarshalledValueObjectStreamSource;
 import org.jboss.ha.ispn.CacheContainerRegistry;
-import org.jboss.metadata.web.jboss.ReplicationGranularity;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
 
 /**
+ * Factory for creating an Infinispan-backed distributed cache manager.
  * @author Paul Ferraro
- *
  */
 public class DistributedCacheManagerFactoryImpl implements DistributedCacheManagerFactory
 {
    private final CacheContainerRegistry registry;
+   private final SessionAttributeStorageFactory storageFactory;
+   private final SessionAttributeMarshallerFactory marshallerFactory;
+   private final CacheInvoker invoker;
+   
    private volatile String cacheContainerName;
    
    public DistributedCacheManagerFactoryImpl(CacheContainerRegistry registry)
    {
+      this(registry, new SessionAttributeStorageFactoryImpl(), new SessionAttributeMarshallerFactoryImpl(), new RetryingCacheInvoker(10, 100));
+   }
+   
+   public DistributedCacheManagerFactoryImpl(CacheContainerRegistry registry, SessionAttributeStorageFactory storageFactory, SessionAttributeMarshallerFactory marshallerFactory, CacheInvoker invoker)
+   {
       this.registry = registry;
+      this.storageFactory = storageFactory;
+      this.marshallerFactory = marshallerFactory;
+      this.invoker = invoker;
    }
    
    @Override
    public <T extends OutgoingDistributableSessionData> DistributedCacheManager<T> getDistributedCacheManager(LocalDistributableSessionManager manager)
    {
       CacheContainer container = this.registry.getCacheContainer(this.cacheContainerName);
-      SessionAttributeStorage<T> storage = this.getSessionAttributeStorage(manager);
+      SessionAttributeMarshaller marshaller = this.marshallerFactory.createMarshaller(manager);
+      SessionAttributeStorage<T> storage = this.storageFactory.createStorage(manager.getReplicationConfig().getReplicationGranularity(), marshaller);
       
-      return new DistributedCacheManagerImpl<T>(manager, container, storage, new RetryingCacheInvoker(10, 100));
+      return new DistributedCacheManagerImpl<T>(manager, container, storage, this.invoker);
    }
-
-   @SuppressWarnings("unchecked")
-   private <T extends OutgoingDistributableSessionData> SessionAttributeStorage<T> getSessionAttributeStorage(LocalDistributableSessionManager manager)
-   {
-      SessionAttributeMarshaller marshaller = new SessionAttributeMarshallerImpl(manager, new MarshalledValueObjectStreamSource());
-      ReplicationGranularity granularity = manager.getReplicationConfig().getReplicationGranularity();
-      
-      switch (granularity)
-      {
-         case SESSION:
-         {
-            return (SessionAttributeStorage<T>) new FineSessionAttributeStorage(marshaller);
-         }
-         case ATTRIBUTE:
-         {
-            return (SessionAttributeStorage<T>) new CoarseSessionAttributeStorage(marshaller);
-         }
-         case FIELD:
-         {
-            throw new IllegalArgumentException("FIELD replication granularity is no longer supported, use SESSION or ATTRIBUTE instead.");
-         }
-         default:
-         {
-            throw new IllegalArgumentException("Unknown replication granularity: " + granularity);
-         }
-      }
-   }
-
+   
    public String getCacheContainerName()
    {
       return this.cacheContainerName;

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactory.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactory.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactory.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -0,0 +1,38 @@
+/*
+ * 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+
+/**
+ * Factory for creating session attribute marshallers.
+ * @author Paul Ferraro
+ */
+public interface SessionAttributeMarshallerFactory
+{
+   /**
+    * Create a session attribute marshaller using the specified distributable session manager.
+    * @param manager a distributable session manager
+    * @return a session attribute marshaller
+    */
+   SessionAttributeMarshaller createMarshaller(LocalDistributableSessionManager manager);
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -0,0 +1,55 @@
+/*
+ * 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.jboss.ha.framework.interfaces.ObjectStreamSource;
+import org.jboss.ha.framework.server.MarshalledValueObjectStreamSource;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+
+/**
+ * Default factory for creating session attribute marshallers.
+ * @author Paul Ferraro
+ */
+public class SessionAttributeMarshallerFactoryImpl implements SessionAttributeMarshallerFactory
+{
+   private final ObjectStreamSource source;
+   
+   public SessionAttributeMarshallerFactoryImpl()
+   {
+      this(new MarshalledValueObjectStreamSource());
+   }
+   
+   public SessionAttributeMarshallerFactoryImpl(ObjectStreamSource source)
+   {
+      this.source = source;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeMarshallerFactory#createMarshaller(org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager)
+    */
+   @Override
+   public SessionAttributeMarshaller createMarshaller(LocalDistributableSessionManager manager)
+   {
+      return new SessionAttributeMarshallerImpl(manager, this.source);
+   }
+}

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java	2010-07-22 16:37:32 UTC (rev 107032)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -32,8 +32,8 @@
 import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
 
 /**
+ * Session attribute marshaller that marshals attribute values using a {@link SimpleCachableMarshalledValue}.
  * @author Paul Ferraro
- *
  */
 public class SessionAttributeMarshallerImpl implements SessionAttributeMarshaller
 {
@@ -53,10 +53,6 @@
    @Override
    public Object marshal(Object value)
    {
-      // JBAS-2921 - replaced MarshalledValue calls with SessionSerializationFactory calls
-      // to allow for switching between JBossSerialization and JavaSerialization using
-      // system property -D=session.serialization.jboss=true / false
-      // MarshalledValue mv = new MarshalledValue(value);
       if ((value == null) || MarshalledValueHelper.isTypeExcluded(value.getClass())) return value;
 
       if (!(value instanceof Serializable))

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactory.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactory.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactory.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -0,0 +1,41 @@
+/*
+ * 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+
+/**
+ * Factory for creating strategies for storing session attributes.
+ * @author Paul Ferraro
+ */
+public interface SessionAttributeStorageFactory
+{
+   /**
+    * Creates a session attribute storage strategy.
+    * @param <T> the type of session data appropriate for the specified granularity
+    * @param granularity the replication granularity
+    * @param marshaller a session attribute marshaller
+    * @return a strategy for storing session attributes.
+    */
+   <T extends OutgoingDistributableSessionData> SessionAttributeStorage<T> createStorage(ReplicationGranularity granularity, SessionAttributeMarshaller marshaller);
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactoryImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactoryImpl.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -0,0 +1,61 @@
+/*
+ * 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+
+/**
+ * Default factory for creating strategies for storing session attributes.
+ * @author Paul Ferraro
+ */
+public class SessionAttributeStorageFactoryImpl implements SessionAttributeStorageFactory
+{
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeStorageFactory#createStorage(org.jboss.metadata.web.jboss.ReplicationGranularity, org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeMarshaller)
+    */
+   @SuppressWarnings("unchecked")
+   @Override
+   public <T extends OutgoingDistributableSessionData> SessionAttributeStorage<T> createStorage(ReplicationGranularity granularity, SessionAttributeMarshaller marshaller)
+   {
+      switch (granularity)
+      {
+         case SESSION:
+         {
+            return (SessionAttributeStorage<T>) new CoarseSessionAttributeStorage(marshaller);
+         }
+         case ATTRIBUTE:
+         {
+            return (SessionAttributeStorage<T>) new FineSessionAttributeStorage(marshaller);
+         }
+         case FIELD:
+         {
+            throw new IllegalArgumentException("FIELD replication granularity is no longer supported, use SESSION or ATTRIBUTE instead.");
+         }
+         default:
+         {
+            throw new IllegalArgumentException("Unknown replication granularity: " + granularity);
+         }
+      }
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryTest.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -0,0 +1,106 @@
+/*
+ * 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.infinispan.manager.CacheContainer;
+import org.junit.Assert;
+
+import org.easymock.EasyMock;
+import org.jboss.ha.ispn.CacheContainerRegistry;
+import org.jboss.metadata.web.jboss.ReplicationConfig;
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.ClusteringNotSupportedException;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class DistributedCacheManagerFactoryTest
+{
+   private CacheContainerRegistry registry = EasyMock.createStrictMock(CacheContainerRegistry.class);
+   private SessionAttributeStorageFactory storageFactory = EasyMock.createStrictMock(SessionAttributeStorageFactory.class);
+   private SessionAttributeMarshallerFactory marshallerFactory = EasyMock.createStrictMock(SessionAttributeMarshallerFactory.class);
+   private CacheInvoker invoker = EasyMock.createStrictMock(CacheInvoker.class);
+   private LocalDistributableSessionManager manager = EasyMock.createStrictMock(LocalDistributableSessionManager.class);
+   private CacheContainer container = EasyMock.createStrictMock(CacheContainer.class);
+   @SuppressWarnings("unchecked")
+   private SessionAttributeStorage<OutgoingDistributableSessionData> storage = EasyMock.createStrictMock(SessionAttributeStorage.class);
+   private SessionAttributeMarshaller marshaller = EasyMock.createStrictMock(SessionAttributeMarshaller.class);
+   
+   @Test
+   public void testDefaultCacheContainer() throws ClusteringNotSupportedException
+   {
+      DistributedCacheManagerFactory factory = new DistributedCacheManagerFactoryImpl(this.registry, this.storageFactory, this.marshallerFactory, this.invoker);
+      
+      ReplicationConfig config = new ReplicationConfig();
+      ReplicationGranularity granularity = ReplicationGranularity.SESSION;
+      config.setReplicationGranularity(granularity);
+      
+      EasyMock.expect(this.registry.getCacheContainer(null)).andReturn(this.container);
+      EasyMock.expect(this.marshallerFactory.createMarshaller(this.manager)).andReturn(this.marshaller);
+      EasyMock.expect(this.manager.getReplicationConfig()).andReturn(config);
+      EasyMock.expect(this.storageFactory.createStorage(granularity, this.marshaller)).andReturn(this.storage);
+      
+      EasyMock.replay(this.registry, this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.container, this.storage, this.marshaller);
+      
+      DistributedCacheManager<?> result = factory.getDistributedCacheManager(this.manager);
+      
+      EasyMock.verify(this.registry, this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.container, this.storage, this.marshaller);
+      
+      Assert.assertNotNull(result);
+      Assert.assertTrue(result instanceof DistributedCacheManagerImpl);
+      
+      EasyMock.reset(this.registry, this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.container, this.storage, this.marshaller);
+   }
+   
+   @Test
+   public void testSpecificCacheContainer() throws ClusteringNotSupportedException
+   {
+      DistributedCacheManagerFactoryImpl factory = new DistributedCacheManagerFactoryImpl(this.registry, this.storageFactory, this.marshallerFactory, this.invoker);
+      factory.setCacheContainerName("mycontainer");
+      
+      ReplicationConfig config = new ReplicationConfig();
+      ReplicationGranularity granularity = ReplicationGranularity.SESSION;
+      config.setReplicationGranularity(granularity);
+      
+      EasyMock.expect(this.registry.getCacheContainer("mycontainer")).andReturn(this.container);
+      EasyMock.expect(this.marshallerFactory.createMarshaller(this.manager)).andReturn(this.marshaller);
+      EasyMock.expect(this.manager.getReplicationConfig()).andReturn(config);
+      EasyMock.expect(this.storageFactory.createStorage(granularity, this.marshaller)).andReturn(this.storage);
+      
+      EasyMock.replay(this.registry, this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.container, this.storage, this.marshaller);
+      
+      DistributedCacheManager<?> result = factory.getDistributedCacheManager(this.manager);
+      
+      EasyMock.verify(this.registry, this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.container, this.storage, this.marshaller);
+      
+      Assert.assertNotNull(result);
+      Assert.assertTrue(result instanceof DistributedCacheManagerImpl);
+      
+      EasyMock.reset(this.registry, this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.container, this.storage, this.marshaller);
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -0,0 +1,53 @@
+/*
+ * 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.junit.Assert;
+
+import org.easymock.EasyMock;
+import org.jboss.ha.framework.interfaces.ObjectStreamSource;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionAttributeMarshallerFactoryTest
+{
+   @Test
+   public void test()
+   {
+      ObjectStreamSource source = EasyMock.createStrictMock(ObjectStreamSource.class);
+      LocalDistributableSessionManager manager = EasyMock.createStrictMock(LocalDistributableSessionManager.class);
+      SessionAttributeMarshallerFactory factory = new SessionAttributeMarshallerFactoryImpl(source);
+      
+      EasyMock.replay(source, manager);
+      
+      SessionAttributeMarshaller marshaller = factory.createMarshaller(manager);
+      
+      EasyMock.verify(source, manager);
+      
+      Assert.assertNotNull(marshaller);
+      Assert.assertTrue(marshaller instanceof SessionAttributeMarshallerImpl);
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactoryTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactoryTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorageFactoryTest.java	2010-07-22 16:48:01 UTC (rev 107033)
@@ -0,0 +1,75 @@
+/*
+ * 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.easymock.EasyMock;
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionAttributeStorageFactoryTest
+{
+   @Test
+   public void testSession()
+   {
+      this.test(ReplicationGranularity.SESSION, CoarseSessionAttributeStorage.class);
+   }
+   
+   @Test
+   public void testAttribute()
+   {
+      this.test(ReplicationGranularity.ATTRIBUTE, FineSessionAttributeStorage.class);
+   }
+   
+   @Test
+   public void testField()
+   {
+      this.test(ReplicationGranularity.FIELD, null);
+   }
+   
+   private void test(ReplicationGranularity granularity, Class<? extends SessionAttributeStorage<?>> expectedClass)
+   {
+      SessionAttributeMarshaller marshaller = EasyMock.createStrictMock(SessionAttributeMarshaller.class);
+      
+      SessionAttributeStorageFactory factory = new SessionAttributeStorageFactoryImpl();
+      
+      EasyMock.replay(marshaller);
+      
+      try
+      {
+         SessionAttributeStorage<?> storage = factory.createStorage(granularity, marshaller);
+         
+         Assert.assertNotNull(expectedClass);
+         Assert.assertTrue(storage.getClass().getName(), expectedClass.isInstance(storage));
+      }
+      catch (IllegalArgumentException e)
+      {
+         Assert.assertNull(expectedClass);
+      }
+      
+      EasyMock.verify(marshaller);
+   }
+}



More information about the jboss-cvs-commits mailing list