[jboss-cvs] JBossAS SVN: r65955 - in projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test: integrated and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 8 23:49:41 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-10-08 23:49:41 -0400 (Mon, 08 Oct 2007)
New Revision: 65955

Added:
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/GroupedPassivatingUnitTestCase.java
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/MockBeanContainer.java
   projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/MockBeanContext.java
Log:
Add tests

Added: projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/GroupedPassivatingUnitTestCase.java
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/GroupedPassivatingUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/GroupedPassivatingUnitTestCase.java	2007-10-09 03:49:41 UTC (rev 65955)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.integrated;
+
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.cache.PassivationManager;
+import org.jboss.ejb3.cache.StatefulObjectFactory;
+import org.jboss.ejb3.cache.grouped.SerializationGroup;
+import org.jboss.ejb3.cache.impl.FileObjectStore;
+import org.jboss.ejb3.cache.impl.SerializationGroupContainer;
+import org.jboss.ejb3.cache.impl.SimpleIntegratedObjectStore;
+import org.jboss.ejb3.cache.impl.SimplePassivatingCache2;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 65920 $
+ */
+public class GroupedPassivatingUnitTestCase extends TestCase
+{
+   private static final Logger log = Logger.getLogger(GroupedPassivatingUnitTestCase.class);
+   
+   private static void sleep(long micros)
+   {
+      try
+      {
+         Thread.sleep(micros);
+      }
+      catch (InterruptedException e)
+      {
+         // ignore
+      }
+   }
+   
+   public void test1()
+   {      
+      SerializationGroupContainer container = new SerializationGroupContainer();
+      StatefulObjectFactory<SerializationGroup> factory = container;
+      PassivationManager<SerializationGroup> passivationManager = container;
+      FileObjectStore<SerializationGroup> filestore = new FileObjectStore<SerializationGroup>();
+      filestore.setStorageDirectory("./target/tmp/groups");
+      filestore.start();
+      SimpleIntegratedObjectStore<SerializationGroup> store = new SimpleIntegratedObjectStore<SerializationGroup>(filestore);
+      SimplePassivatingCache2<SerializationGroup> groupCache = new SimplePassivatingCache2<SerializationGroup>(factory, passivationManager, store);
+      store.setName("PassivationGroupContainer");
+      MockBeanContainer container1 = new MockBeanContainer("MockBeanContainer1", 1, groupCache);
+      MockBeanContainer container2 = new MockBeanContainer("MockBeanContainer2", 10, groupCache);
+      
+      try
+      {
+         groupCache.start();
+         container1.start();
+         container2.start();
+         
+         Object shared = new Serializable()
+         {
+            private static final long serialVersionUID = 1L;
+         };
+         MockBeanContext firstCtx1;
+         MockBeanContext ctx1 = firstCtx1 = container1.getCache().create(null, null);
+         Object key1 = ctx1.getId();
+         ctx1.shared = shared;
+         MockBeanContext ctx2 = container2.getCache().create(null, null);
+         Object key2 = ctx2.getId();
+         ctx2.shared = shared;
+         
+         // TODO: how will passivation groups be created?
+         SerializationGroup group = groupCache.create(null, null);
+         container1.getCache().setGroup(ctx1, group);
+         container2.getCache().setGroup(ctx2, group);
+         // TODO: currently we need to release the group
+         // BES -- not any more
+   //      groupCache.release(group);
+         
+         container1.getCache().release(ctx1);
+         container2.getCache().release(ctx2);
+         
+         sleep(4000);
+         
+         assertEquals("ctx1 should have been passivated", 1, container1.passivations);
+         assertEquals("ctx2 should have been passivated", 1, container2.passivations);
+         
+         ctx2 = container2.getCache().get(key2);
+         
+         log.info("ctx2 = " + ctx2);
+         assertNotNull(ctx2);
+         
+         ctx1 = container1.getCache().get(key1);
+         
+         log.info("ctx1 = " + ctx1);
+         
+         assertTrue("ctx1 must be different than firstCtx1 (else no passivation has taken place)", ctx1 != firstCtx1);
+         
+         assertEquals(ctx1.shared, ctx2.shared);
+      }
+      finally
+      {
+         container1.stop();
+         container2.stop();
+         groupCache.stop();
+      }
+   }
+}

Added: projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/MockBeanContainer.java
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/MockBeanContainer.java	                        (rev 0)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/MockBeanContainer.java	2007-10-09 03:49:41 UTC (rev 65955)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.integrated;
+
+import org.jboss.ejb3.cache.PassivatingCache;
+import org.jboss.ejb3.cache.PassivationManager;
+import org.jboss.ejb3.cache.StatefulObjectFactory;
+import org.jboss.ejb3.cache.grouped.GroupedPassivatingCache;
+import org.jboss.ejb3.cache.grouped.SerializationGroup;
+import org.jboss.ejb3.cache.impl.FileObjectStore;
+import org.jboss.ejb3.cache.impl.GroupedPassivatingCacheImpl2;
+import org.jboss.ejb3.cache.impl.SerializationGroupMemberImpl;
+import org.jboss.ejb3.cache.impl.SimpleIntegratedObjectStore;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 65920 $
+ */
+public class MockBeanContainer implements StatefulObjectFactory<MockBeanContext>, PassivationManager<MockBeanContext>
+{
+   private static final Logger log = Logger.getLogger(MockBeanContainer.class);
+   
+   protected int activations = 0;
+   protected int passivations = 0;
+   
+   private GroupedPassivatingCache<MockBeanContext> cache;
+   
+   public MockBeanContainer(String name, int sessionTimeout, PassivatingCache<SerializationGroup> groupCache)
+   {
+      FileObjectStore<SerializationGroupMemberImpl<MockBeanContext>> filestore = new FileObjectStore<SerializationGroupMemberImpl<MockBeanContext>>();
+      filestore.setStorageDirectory("./target/tmp/" + name);
+      filestore.start();
+      SimpleIntegratedObjectStore<SerializationGroupMemberImpl<MockBeanContext>> store = 
+         new SimpleIntegratedObjectStore<SerializationGroupMemberImpl<MockBeanContext>>(filestore);
+      store.setName(name);
+      store.setIdleTimeSeconds(sessionTimeout);
+      store.setInterval(1);
+      this.cache = new GroupedPassivatingCacheImpl2<MockBeanContext>(this, this, store, groupCache);
+   }
+   
+   public MockBeanContext create(Class<?>[] initTypes, Object[] initValues)
+   {
+      return new MockBeanContext();
+   }
+   
+   public GroupedPassivatingCache<MockBeanContext> getCache()
+   {
+      return cache;
+   }
+   
+   public void destroy(MockBeanContext obj)
+   {
+   }
+
+   public void postActivate(MockBeanContext obj)
+   {
+      if(obj == null) throw new IllegalArgumentException("obj is null");
+      
+      log.info("postActivate " + obj);
+      activations++;
+      synchronized(this)
+      {
+         notifyAll();
+      }
+   }
+
+   public void prePassivate(MockBeanContext obj)
+   {
+      if(obj == null) throw new IllegalArgumentException("obj is null");
+      
+      log.info("prePassivate " + obj);
+      passivations++;
+      synchronized(this)
+      {
+         notifyAll();
+      }
+   }
+   public boolean isClustered()
+   {
+      // TODO Auto-generated method stub
+      return false;
+}
+   public void postReplicate(MockBeanContext obj)
+   {
+      throw new UnsupportedOperationException("Clustering not supported");      
+   }
+
+   public void preReplicate(MockBeanContext obj)
+   {
+      throw new UnsupportedOperationException("Clustering not supported"); 
+   }
+   
+   public void start()
+   {
+      cache.start();
+   }
+   
+   public void stop()
+   {
+      cache.stop();
+   }
+   
+}

Added: projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/MockBeanContext.java
===================================================================
--- projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/MockBeanContext.java	                        (rev 0)
+++ projects/ejb3/branches/cluster-dev/ejb3-cache/src/test/java/org/jboss/ejb3/test/integrated/MockBeanContext.java	2007-10-09 03:49:41 UTC (rev 65955)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.integrated;
+
+import java.io.Serializable;
+
+import org.jboss.ejb3.cache.Cacheable;
+
+/**
+ * Comment
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 65339 $
+ */
+public class MockBeanContext implements Cacheable, Serializable
+{
+   private static final long serialVersionUID = 1L;
+
+   private static volatile long currentId = 100000;
+   
+   private long id;
+   
+   private boolean inUse;
+   private long lastUsed;
+   
+   public Object shared;
+   
+   public MockBeanContext()
+   {
+      this.id = ++currentId;
+   }
+   
+   public Object getId()
+   {
+      return id;
+   }
+
+   public boolean isInUse()
+   {
+      return inUse;
+   }
+
+   public void setInUse(boolean inUse)
+   {
+      this.inUse = inUse;
+      lastUsed = System.currentTimeMillis();
+   }
+
+   public long getLastUsed()
+   {
+      return lastUsed;
+   }
+
+   @Override
+   public String toString()
+   {
+      return super.toString() + "{id=" + id + "}";
+   }
+
+}




More information about the jboss-cvs-commits mailing list