[jboss-cvs] JBossAS SVN: r107862 - in projects/ejb3/branches/infinispan-int/core/src: test/java/org/jboss/ejb3 and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 27 13:55:51 EDT 2010


Author: pferraro
Date: 2010-08-27 13:55:50 -0400 (Fri, 27 Aug 2010)
New Revision: 107862

Added:
   projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/
   projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/
   projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/DefaultCacheSourceTest.java
   projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/InfinispanStatefulCacheTest.java
   projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/StatefulContainerFactory.java
Modified:
   projects/ejb3/branches/infinispan-int/core/src/main/java/org/jboss/ejb3/cache/infinispan/DefaultCacheSource.java
   projects/ejb3/branches/infinispan-int/core/src/main/java/org/jboss/ejb3/cache/infinispan/InfinispanStatefulCache.java
Log:
Update DefaultCacheSource logic use CacheConfig.name() as container name, not cache name.

Modified: projects/ejb3/branches/infinispan-int/core/src/main/java/org/jboss/ejb3/cache/infinispan/DefaultCacheSource.java
===================================================================
--- projects/ejb3/branches/infinispan-int/core/src/main/java/org/jboss/ejb3/cache/infinispan/DefaultCacheSource.java	2010-08-27 17:38:11 UTC (rev 107861)
+++ projects/ejb3/branches/infinispan-int/core/src/main/java/org/jboss/ejb3/cache/infinispan/DefaultCacheSource.java	2010-08-27 17:55:50 UTC (rev 107862)
@@ -39,8 +39,6 @@
    
    private final CacheContainerRegistry registry;
    
-   private String defaultContainerName = DEFAULT_CACHE_CONTAINER;
-   
    public DefaultCacheSource(CacheContainerRegistry registry)
    {
       this.registry = registry;
@@ -53,34 +51,39 @@
    @Override
    public <K, V> Cache<K, V> getCache(StatefulContainer ejbContainer)
    {
-      String containerName = this.defaultContainerName;
       CacheConfig cacheConfig = ejbContainer.getAnnotation(CacheConfig.class);
-      String templateCacheName = cacheConfig.name();
-      
-      if ((templateCacheName != null) && !templateCacheName.trim().isEmpty())
+      String containerName = cacheConfig.name();
+      String templateCacheName = null;
+
+      if ((containerName == null) || containerName.isEmpty())
       {
-         // Parse cache container name
-         String[] parts = templateCacheName.split(":");
+         containerName = CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME;
+      }
+      else
+      {
+         String[] parts = containerName.split("/");
+         
          if (parts.length == 2)
          {
             containerName = parts[0];
             templateCacheName = parts[1];
          }
       }
-      else
-      {
-         templateCacheName = CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME;
-      }
       
       String cacheName = ejbContainer.getDeploymentPropertyListString();
       
       EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
-      Cache<?, ?> templateCache = container.getCache(templateCacheName);
-      Configuration configuration = templateCache.getConfiguration().clone();
       
+      this.applyOverrides(container.defineConfiguration(cacheName, templateCacheName, new Configuration()), cacheConfig);
+      
+      return container.getCache(cacheName);
+   }
+
+   private void applyOverrides(Configuration configuration, CacheConfig cacheConfig)
+   {
       int backups = cacheConfig.backups();
       CacheConfig.Mode mode = cacheConfig.mode();
-
+      
       CacheMode cacheMode = configuration.getCacheMode();
       
       if (backups != CacheConfig.DEFAULT_BACKUPS)
@@ -105,33 +108,23 @@
          }
       }
       
-      switch (mode)
+      if (mode != CacheConfig.Mode.DEFAULT)
       {
-         case SYNCHRONOUS:
+         switch (mode)
          {
-            cacheMode = cacheMode.toSync();
-            break;
+            case SYNCHRONOUS:
+            {
+               cacheMode = cacheMode.toSync();
+               break;
+            }
+            case ASYNCHRONOUS:
+            {
+               cacheMode = cacheMode.toAsync();
+               break;
+            }
          }
-         case ASYNCHRONOUS:
-         {
-            cacheMode = cacheMode.toAsync();
-            break;
-         }
-         case DEFAULT:
-         {
-            // Do nothing
-         }
       }
       
       configuration.setCacheMode(cacheMode);
-      
-      container.defineConfiguration(cacheName, configuration);
-      
-      return container.getCache(cacheName);
    }
-   
-   public void setDefaultContainerName(String defaultContainerName)
-   {
-      this.defaultContainerName = defaultContainerName;
-   }
 }

Modified: projects/ejb3/branches/infinispan-int/core/src/main/java/org/jboss/ejb3/cache/infinispan/InfinispanStatefulCache.java
===================================================================
--- projects/ejb3/branches/infinispan-int/core/src/main/java/org/jboss/ejb3/cache/infinispan/InfinispanStatefulCache.java	2010-08-27 17:38:11 UTC (rev 107861)
+++ projects/ejb3/branches/infinispan-int/core/src/main/java/org/jboss/ejb3/cache/infinispan/InfinispanStatefulCache.java	2010-08-27 17:55:50 UTC (rev 107862)
@@ -84,9 +84,9 @@
    private StatefulContainer ejbContainer;
    private CacheConfig cacheConfig;
    private ScheduledExecutorService executor;
+   private Cache<Object, StatefulBeanContext> cache;
 
    // Defined in start()
-   private Cache<Object, StatefulBeanContext> cache;
    private WeakReference<ClassLoader> classLoaderRef;
    
    public InfinispanStatefulCache(CacheSource source, CacheInvoker invoker, ThreadFactory threadFactory)

Added: projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/DefaultCacheSourceTest.java
===================================================================
--- projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/DefaultCacheSourceTest.java	                        (rev 0)
+++ projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/DefaultCacheSourceTest.java	2010-08-27 17:55:50 UTC (rev 107862)
@@ -0,0 +1,181 @@
+package org.jboss.ejb3.cache.infinispan;
+
+import java.util.List;
+
+import javax.ejb.Stateful;
+
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+import org.easymock.EasyMock;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.jboss.ejb3.annotation.CacheConfig;
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.ha.ispn.CacheContainerRegistry;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DefaultCacheSourceTest extends StatefulContainerFactory
+{
+   @Test
+   public void getCache() throws Exception
+   {
+      Configuration configuration = new Configuration();
+      configuration.setCacheMode(CacheMode.REPL_SYNC);
+      
+      this.getCache(this.createContainer(TestBeanWithDefaults.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.REPL_SYNC, 2);
+      this.getCache(this.createContainer(TestBeanWithCustomContainer.class), "container", null, configuration, CacheMode.REPL_SYNC, 2);
+      this.getCache(this.createContainer(TestBeanWithCustomContainerAndCache.class), "container", "cache", configuration, CacheMode.REPL_SYNC, 2);
+      this.getCache(this.createContainer(TestBeanWithAsyncDefaultBackups.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.REPL_ASYNC, 2);
+      this.getCache(this.createContainer(TestBeanWithSyncDefaultBackups.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.REPL_SYNC, 2);
+      this.getCache(this.createContainer(TestBeanWithDefaultModeNoBackups.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.LOCAL, 0);
+      this.getCache(this.createContainer(TestBeanWithDefaultModeSomeBackups.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.DIST_SYNC, 3);
+      this.getCache(this.createContainer(TestBeanWithDefaultModeTotalRepl.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.REPL_SYNC, -1);
+      this.getCache(this.createContainer(TestBeanWithExplicitDefaults.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.REPL_SYNC, 2);
+      this.getCache(this.createContainer(TestBeanWithReplAsync.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.REPL_ASYNC, -1);
+      this.getCache(this.createContainer(TestBeanWithReplSync.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.REPL_SYNC, -1);
+      this.getCache(this.createContainer(TestBeanWithLocalAsync.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.LOCAL, 0);
+      this.getCache(this.createContainer(TestBeanWithLocalSync.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.LOCAL, 0);
+      this.getCache(this.createContainer(TestBeanWithDistAsync.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.DIST_ASYNC, 3);
+      this.getCache(this.createContainer(TestBeanWithDistSync.class), CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME, null, configuration, CacheMode.DIST_SYNC, 4);
+   }
+   
+   private void getCache(StatefulContainer ejbContainer, String containerName, String templateCacheName, Configuration configuration, CacheMode mode, int backups) throws Exception
+   {
+      CacheContainerRegistry registry = EasyMock.createStrictMock(CacheContainerRegistry.class);
+      EmbeddedCacheManager container = EasyMock.createStrictMock(EmbeddedCacheManager.class);
+      @SuppressWarnings("unchecked")
+      Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
+      Configuration cacheConfiguration = configuration.clone();
+      Capture<String> capturedCacheNames = new Capture<String>(CaptureType.ALL);
+      
+      DefaultCacheSource source = new DefaultCacheSource(registry);
+      
+      EasyMock.expect(registry.getCacheContainer(containerName)).andReturn(container);
+      EasyMock.expect(container.defineConfiguration(EasyMock.capture(capturedCacheNames), EasyMock.eq(templateCacheName), EasyMock.eq(new Configuration()))).andReturn(cacheConfiguration);
+      EasyMock.expect(container.getCache(EasyMock.capture(capturedCacheNames))).andReturn(cache);
+      
+      EasyMock.replay(registry, container, cache);
+      
+      Cache<Object, Object> result = source.getCache(ejbContainer);
+      
+      EasyMock.verify(registry, container, cache);
+      
+      Assert.assertSame(cache, result);
+      
+      Assert.assertSame(mode, cacheConfiguration.getCacheMode());
+      Assert.assertEquals(backups, cacheConfiguration.getNumOwners());
+      
+      List<String> cacheNames = capturedCacheNames.getValues();
+      
+      Assert.assertEquals(ejbContainer.getDeploymentPropertyListString(), cacheNames.get(0));
+      Assert.assertSame(cacheNames.get(0), cacheNames.get(1));
+   }
+   
+   @Stateful
+   @CacheConfig
+   public static class TestBeanWithDefaults
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(name = "container")
+   public static class TestBeanWithCustomContainer
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(name = "container/cache")
+   public static class TestBeanWithCustomContainerAndCache
+   {
+      
+   }
+   
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.ASYNCHRONOUS)
+   public static class TestBeanWithAsyncDefaultBackups
+   {
+      
+   }
+   
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.SYNCHRONOUS)
+   public static class TestBeanWithSyncDefaultBackups
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(backups = CacheConfig.NO_BACKUPS)
+   public static class TestBeanWithDefaultModeNoBackups
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(backups = 3)
+   public static class TestBeanWithDefaultModeSomeBackups
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(backups = CacheConfig.TOTAL_REPLICATION)
+   public static class TestBeanWithDefaultModeTotalRepl
+   {
+      
+   }
+   
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.DEFAULT, backups = CacheConfig.DEFAULT_BACKUPS)
+   public static class TestBeanWithExplicitDefaults
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.ASYNCHRONOUS, backups = CacheConfig.TOTAL_REPLICATION)
+   public static class TestBeanWithReplAsync
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.SYNCHRONOUS, backups = CacheConfig.TOTAL_REPLICATION)
+   public static class TestBeanWithReplSync
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.ASYNCHRONOUS, backups = CacheConfig.NO_BACKUPS)
+   public static class TestBeanWithLocalAsync
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.SYNCHRONOUS, backups = CacheConfig.NO_BACKUPS)
+   public static class TestBeanWithLocalSync
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.ASYNCHRONOUS, backups = 3)
+   public static class TestBeanWithDistAsync
+   {
+      
+   }
+
+   @Stateful
+   @CacheConfig(mode = CacheConfig.Mode.SYNCHRONOUS, backups = 4)
+   public static class TestBeanWithDistSync
+   {
+      
+   }
+}

Added: projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/InfinispanStatefulCacheTest.java
===================================================================
--- projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/InfinispanStatefulCacheTest.java	                        (rev 0)
+++ projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/InfinispanStatefulCacheTest.java	2010-08-27 17:55:50 UTC (rev 107862)
@@ -0,0 +1,228 @@
+/*
+ * 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.ejb3.cache.infinispan;
+
+import java.util.List;
+import java.util.concurrent.Executors;
+
+import javax.ejb.Stateful;
+
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+import org.easymock.EasyMock;
+import org.infinispan.Cache;
+import org.jboss.ejb3.annotation.CacheConfig;
+import org.jboss.ejb3.cache.ClusteredStatefulCache;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.ha.ispn.invoker.CacheInvoker;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class InfinispanStatefulCacheTest extends StatefulContainerFactory
+{
+   private CacheSource source = EasyMock.createStrictMock(CacheSource.class);
+   private CacheInvoker invoker = EasyMock.createStrictMock(CacheInvoker.class);
+   @SuppressWarnings("unchecked")
+   private Cache<Object, StatefulBeanContext> cache = EasyMock.createStrictMock(Cache.class);
+   
+   private StatefulContainer container;
+   private StatefulBeanContext context;  
+   
+   private ClusteredStatefulCache statefulCache = new InfinispanStatefulCache(this.source, this.invoker, Executors.defaultThreadFactory());
+   
+   @SuppressWarnings("deprecation")
+   @Before
+   public void before() throws Exception
+   {
+      this.container = this.createContainer(TestBean.class);
+      this.context = new InfinispanStatefulCache.MyStatefulBeanContext(this.container, new TestBean());
+      
+      EasyMock.expect(this.source.<Object, StatefulBeanContext>getCache(EasyMock.same(this.container))).andReturn(this.cache);
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      this.statefulCache.initialize(this.container);
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      EasyMock.reset(this.source, this.invoker, this.cache);
+
+      
+      this.cache.start();
+      this.cache.addListener(EasyMock.same(this.statefulCache));
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      this.statefulCache.start();
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      EasyMock.reset(this.source, this.invoker, this.cache);
+   }
+
+   @After
+   public void after()
+   {
+      EasyMock.reset(this.source, this.invoker, this.cache);
+      
+      this.cache.removeListener(EasyMock.same(this.statefulCache));
+      this.cache.stop();
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      this.statefulCache.stop();
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      EasyMock.reset(this.source, this.invoker, this.cache);
+   }
+
+   @Test
+   public void peek() throws Exception
+   {
+      Capture<InfinispanStatefulCache.Operation<StatefulBeanContext>> capturedOperation = new Capture<InfinispanStatefulCache.Operation<StatefulBeanContext>>();
+      
+      EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(this.context);
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      StatefulBeanContext result = this.statefulCache.peek(this.context.getId());
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      
+      Assert.assertSame(result, this.context);
+      
+      EasyMock.reset(this.source, this.invoker, this.cache);
+      
+      
+      InfinispanStatefulCache.Operation<StatefulBeanContext> operation = capturedOperation.getValue();
+
+      EasyMock.expect(this.cache.get(this.context.getId())).andReturn(this.context);
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      result = operation.invoke(this.cache);
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      
+      Assert.assertSame(result, this.context);
+      
+      EasyMock.reset(this.source, this.invoker, this.cache);
+   }
+
+   @Test
+   public void release() throws Exception
+   {
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      this.statefulCache.release(this.context);
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      EasyMock.reset(this.source, this.invoker, this.cache);
+   }
+
+   @Test
+   public void replicate() throws Exception
+   {
+      Capture<InfinispanStatefulCache.Operation<StatefulBeanContext>> capturedOperation = new Capture<InfinispanStatefulCache.Operation<StatefulBeanContext>>();
+      
+      EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(this.context);
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      this.statefulCache.replicate(this.context);
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      EasyMock.reset(this.source, this.invoker, this.cache);
+      
+      
+      InfinispanStatefulCache.Operation<StatefulBeanContext> operation = capturedOperation.getValue();
+
+      EasyMock.expect(this.cache.put(context.getId(), context)).andReturn(null);
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      StatefulBeanContext result = operation.invoke(this.cache);
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      
+      Assert.assertNull(result);
+      
+      EasyMock.reset(this.source, this.invoker, this.cache);
+   }
+
+   @Test
+   public void remove() throws Exception
+   {
+      Capture<InfinispanStatefulCache.Operation<StatefulBeanContext>> capturedOperation = new Capture<InfinispanStatefulCache.Operation<StatefulBeanContext>>(CaptureType.ALL);
+      
+      EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(this.context);
+      EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(this.context);
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      this.statefulCache.remove(context.getId());
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+
+      List<InfinispanStatefulCache.Operation<StatefulBeanContext>> operations = capturedOperation.getValues();
+      Assert.assertEquals(2, operations.size());
+      
+      EasyMock.reset(this.source, this.invoker, this.cache);
+      
+      
+      EasyMock.expect(this.cache.get(this.context.getId())).andReturn(this.context);
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      StatefulBeanContext result = operations.get(0).invoke(this.cache);
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      
+      Assert.assertSame(result, this.context);
+      
+      EasyMock.reset(this.source, this.invoker, this.cache);
+
+      
+      EasyMock.expect(this.cache.remove(this.context.getId())).andReturn(null);
+      
+      EasyMock.replay(this.source, this.invoker, this.cache);
+      
+      result = operations.get(1).invoke(this.cache);
+      
+      EasyMock.verify(this.source, this.invoker, this.cache);
+      
+      Assert.assertNull(result);
+      
+      EasyMock.reset(this.source, this.invoker, this.cache);
+   }
+   
+   @Stateful
+   @CacheConfig
+   public static class TestBean
+   {
+   }
+}

Added: projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/StatefulContainerFactory.java
===================================================================
--- projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/StatefulContainerFactory.java	                        (rev 0)
+++ projects/ejb3/branches/infinispan-int/core/src/test/java/org/jboss/ejb3/cache/infinispan/StatefulContainerFactory.java	2010-08-27 17:55:50 UTC (rev 107862)
@@ -0,0 +1,105 @@
+package org.jboss.ejb3.cache.infinispan;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.concurrent.Executors;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import javax.transaction.TransactionManager;
+
+import org.easymock.EasyMock;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+import org.jboss.aop.advice.AdviceFactory;
+import org.jboss.aop.advice.AdviceStack;
+import org.jboss.aop.advice.AspectDefinition;
+import org.jboss.aop.advice.GenericAspectFactory;
+import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.advice.Scope;
+import org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor;
+import org.jboss.ejb3.core.test.common.MockEjb3Deployment;
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.ejb3.test.cachepassivation.MockDeploymentUnit;
+import org.jboss.ejb3.test.common.MetaDataHelper;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.tm.TransactionManagerLocator;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class StatefulContainerFactory
+{
+   static Context context = EasyMock.createStrictMock(Context.class);
+   private static String initialContextFactory;
+   
+   private static TransactionManager txManager = EasyMock.createStrictMock(TransactionManager.class);
+   
+   @BeforeClass
+   public static void beforeClass() throws NamingException
+   {
+      initialContextFactory = System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MockInitialContextFactory.class.getName());
+      
+      EasyMock.expect(context.lookup("java:/TransactionManager")).andReturn(txManager);
+      
+      EasyMock.replay(context);
+      
+      TransactionManagerLocator.locateTransactionManager();
+      
+      EasyMock.verify(context);
+      EasyMock.reset(context);
+   }
+   
+   @AfterClass
+   public static void afterClass() throws NamingException
+   {
+      if (initialContextFactory != null)
+      {
+         System.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
+      }
+      else
+      {
+         System.clearProperty(Context.INITIAL_CONTEXT_FACTORY);
+      }
+   }
+   
+   protected StatefulContainer createContainer(Class<?> bean) throws Exception
+   {
+      EasyMock.expect(context.getEnvironment()).andReturn(null);
+
+      EasyMock.replay(context);
+      
+      @SuppressWarnings("deprecation")
+      Ejb3Deployment deployment = MockEjb3Deployment.create(MockDeploymentUnit.create());
+      
+      EasyMock.verify(context);
+      EasyMock.reset(context);
+      
+      Domain domain = new Domain(new AspectManager(), "Test", false);
+      GenericAspectFactory aspectFactory = new GenericAspectFactory(CurrentInvocationInterceptor.class.getName(), null);
+      AspectDefinition def = new AspectDefinition("CurrentInvocationInterceptor", Scope.PER_VM, aspectFactory);
+      domain.addAspectDefinition(def);
+      AdviceFactory factory = new AdviceFactory(def, "invoke");
+      GenericAspectFactory aspectFactory2 = new GenericAspectFactory(CurrentInvocationContextInterceptor.class.getName(), null);
+      AspectDefinition def2 = new AspectDefinition("CurrentInvocationContextInterceptor", Scope.PER_VM, aspectFactory2);
+      domain.addAspectDefinition(def2);
+      AdviceFactory factory2 = new AdviceFactory(def2, "invoke");
+      AdviceStack stack = new AdviceStack("InjectionCallbackStack", new ArrayList<InterceptorFactory>(Arrays.asList(factory, factory2)));
+      domain.addAdviceStack(stack);
+      
+      JBossSessionBeanMetaData metaData = MetaDataHelper.getMetadataFromBeanImplClass(bean);
+      return new StatefulContainer(Thread.currentThread().getContextClassLoader(), bean.getName(), "TestBean", domain, new Hashtable<Object, Object>(), deployment, metaData, Executors.newCachedThreadPool());
+   }
+   
+   public static class MockInitialContextFactory implements InitialContextFactory
+   {
+      @Override
+      public Context getInitialContext(Hashtable<?, ?> env) throws NamingException
+      {
+         return context;
+      }
+   }
+}



More information about the jboss-cvs-commits mailing list