[jboss-cvs] JBossAS SVN: r87398 - in projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 15 23:47:55 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-04-15 23:47:55 -0400 (Wed, 15 Apr 2009)
New Revision: 87398

Added:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheRemovalStatefulBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBase.java
Modified:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java
Log:
[EJBTHREE-1692] Add testing of Cache.getTotalSize() metric

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheRemovalStatefulBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheRemovalStatefulBean.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheRemovalStatefulBean.java	2009-04-16 03:47:55 UTC (rev 87398)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.stateful;
+
+import javax.annotation.Resource;
+import javax.annotation.Resources;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.ejb3.annotation.Cache;
+import org.jboss.ejb3.annotation.CacheConfig;
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.ejb3.annotation.SecurityDomain;
+import org.jboss.ejb3.annotation.defaults.RemoteBindingDefaults;
+
+/**
+ * Same as TreeCacheStatefulBean, but configures a removalTimeoutSeconds to
+ * validate metrics when a removal thread is used.
+ * 
+ * @author Brian Stansberry
+ */
+ at Stateful(name = "TreeCacheRemovalStatefulBean")
+ at Remote(org.jboss.ejb3.test.stateful.Stateful.class)
+ at Local(org.jboss.ejb3.test.stateful.StatefulLocal.class)
+ at RemoteBinding(jndiBinding = "TreeCacheRemovalStateful", interceptorStack = "RemoteBindingStatefulSessionClientInterceptors", factory = RemoteBindingDefaults.PROXY_FACTORY_STATEFUL_REMOTE)
+ at CacheConfig(name = "jboss.cache:service=EJB3SFSBClusteredCache", maxSize = 1000, idleTimeoutSeconds = 1, removalTimeoutSeconds = 20)
+ at SecurityDomain("test")
+ at Resources(
+{@Resource(name = "jdbc/ds", mappedName = "java:/DefaultDS")})
+ at Cache("StatefulTreeCache")
+public class TreeCacheRemovalStatefulBean extends TreeCacheStatefulBase
+{
+   
+}


Property changes on: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheRemovalStatefulBean.java
___________________________________________________________________
Name: svn:keywords
   + 

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBase.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBase.java	2009-04-16 03:47:55 UTC (rev 87398)
@@ -0,0 +1,216 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.stateful;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import javax.annotation.Resource;
+import javax.ejb.Init;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.interceptor.Interceptors;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.Container;
+import org.jboss.logging.Logger;
+import org.jboss.serial.io.JBossObjectInputStream;
+import org.jboss.serial.io.JBossObjectOutputStream;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class TreeCacheStatefulBase implements org.jboss.ejb3.test.stateful.Stateful
+{
+   private static final Logger log = Logger.getLogger(TreeCacheStatefulBase.class);
+   
+   private static int beansRemoved = 0;
+
+   @Resource
+   private SessionContext sessionContext;
+
+   @Resource(mappedName = "java:/DefaultDS")
+   private transient javax.sql.DataSource datasource;
+
+   @Resource(mappedName = "java:/ConnectionFactory")
+   public transient javax.jms.QueueConnectionFactory connectionFactory;
+
+   private String state;
+
+   @Interceptors(MyInterceptor.class)
+   public String getInterceptorState()
+   {
+      throw new RuntimeException("NOT REACHABLE");
+   }
+
+   @Interceptors(MyInterceptor.class)
+   public void setInterceptorState(String param)
+   {
+      throw new RuntimeException("NOT REACHABLE");
+   }
+
+   public boolean testSessionContext()
+   {
+      return sessionContext.isCallerInRole("role");
+   }
+
+   public void testResources() throws Exception
+   {
+      datasource.toString();
+      connectionFactory.toString();
+
+      javax.sql.DataSource ds = (javax.sql.DataSource) new InitialContext().lookup(Container.ENC_CTX_NAME
+            + "/env/jdbc/ds");
+      ds.toString();
+   }
+
+   public String getState() throws Exception
+   {
+      Thread.sleep(1000);
+      return state;
+   }
+
+   public void setState(String state) throws Exception
+   {
+      Thread.sleep(1000);
+      this.state = state;
+   }
+
+   public boolean interceptorAccessed()
+   {
+      return RemoteBindingInterceptor.accessed;
+   }
+
+   public void testThrownException() throws Exception
+   {
+      throw new Exception();
+   }
+
+   public void testExceptionCause() throws Exception
+   {
+      Object o = null;
+      o.toString();
+   }
+
+   @PrePassivate
+   public void passivate()
+   {
+      log.info("************ passivating");
+      wasPassivated = true;
+   }
+
+   @PostActivate
+   public void activate()
+   {
+      log.info("************ activating");
+   }
+
+   private static boolean wasPassivated = false;
+
+   public void testSerializedState(String state)
+   {
+      this.state = state;
+
+      TreeCacheStatefulBase bean = null;
+      try
+      {
+         ObjectOutputStream out;
+
+         ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+         out = new JBossObjectOutputStream(baos, false);
+         out.writeObject(this);
+         out.flush();
+
+         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+         JBossObjectInputStream is = new JBossObjectInputStream(bais);
+         bean = (TreeCacheStatefulBase) is.readObject();
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+
+      if (!state.equals(bean.state))
+         throw new RuntimeException("failed to serialize: " + bean.state);
+   }
+
+   public boolean wasPassivated()
+   {
+      return wasPassivated;
+   }
+
+   public void clearPassivated()
+   {
+      wasPassivated = false;
+   }
+
+   @Init
+   public void ejbCreate(Integer state)
+   {
+      this.state = state.toString();
+   }
+
+   @Init
+   public void ejbCreate(State state)
+   {
+      this.state = state.getState();
+   }
+
+   @Init
+   public void ejbCreate(String state)
+   {
+      this.state = state;
+   }
+
+   @Remove
+   public void removeMe()
+   {
+      ++beansRemoved;
+   }
+   
+   public int beansRemoved()
+   {
+      return beansRemoved;
+   }
+
+   public void lookupStateful() throws Exception
+   {
+      // FIXME: NYI
+      throw new RuntimeException("NYI");
+   }
+
+   public void testStateful() throws Exception
+   {
+      // FIXME: NYI
+      throw new RuntimeException("NYI");
+   }
+}


Property changes on: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBase.java
___________________________________________________________________
Name: svn:keywords
   + 

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java	2009-04-16 03:00:44 UTC (rev 87397)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java	2009-04-16 03:47:55 UTC (rev 87398)
@@ -61,174 +61,6 @@
 @Resources(
 {@Resource(name = "jdbc/ds", mappedName = "java:/DefaultDS")})
 @Cache("StatefulTreeCache")
-public class TreeCacheStatefulBean implements org.jboss.ejb3.test.stateful.Stateful
+public class TreeCacheStatefulBean extends TreeCacheStatefulBase
 {
-   private static final Logger log = Logger.getLogger(TreeCacheStatefulBean.class);
-   
-   private static int beansRemoved = 0;
-
-   @Resource
-   private SessionContext sessionContext;
-
-   @Resource(mappedName = "java:/DefaultDS")
-   private transient javax.sql.DataSource datasource;
-
-   @Resource(mappedName = "java:/ConnectionFactory")
-   public transient javax.jms.QueueConnectionFactory connectionFactory;
-
-   private String state;
-
-   @Interceptors(MyInterceptor.class)
-   public String getInterceptorState()
-   {
-      throw new RuntimeException("NOT REACHABLE");
-   }
-
-   @Interceptors(MyInterceptor.class)
-   public void setInterceptorState(String param)
-   {
-      throw new RuntimeException("NOT REACHABLE");
-   }
-
-   public boolean testSessionContext()
-   {
-      return sessionContext.isCallerInRole("role");
-   }
-
-   public void testResources() throws Exception
-   {
-      datasource.toString();
-      connectionFactory.toString();
-
-      javax.sql.DataSource ds = (javax.sql.DataSource) new InitialContext().lookup(Container.ENC_CTX_NAME
-            + "/env/jdbc/ds");
-      ds.toString();
-   }
-
-   public String getState() throws Exception
-   {
-      Thread.sleep(1000);
-      return state;
-   }
-
-   public void setState(String state) throws Exception
-   {
-      Thread.sleep(1000);
-      this.state = state;
-   }
-
-   public boolean interceptorAccessed()
-   {
-      return RemoteBindingInterceptor.accessed;
-   }
-
-   public void testThrownException() throws Exception
-   {
-      throw new Exception();
-   }
-
-   public void testExceptionCause() throws Exception
-   {
-      Object o = null;
-      o.toString();
-   }
-
-   @PrePassivate
-   public void passivate()
-   {
-      log.info("************ passivating");
-      wasPassivated = true;
-   }
-
-   @PostActivate
-   public void activate()
-   {
-      log.info("************ activating");
-   }
-
-   private static boolean wasPassivated = false;
-
-   public void testSerializedState(String state)
-   {
-      this.state = state;
-
-      TreeCacheStatefulBean bean = null;
-      try
-      {
-         ObjectOutputStream out;
-
-         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
-         out = new JBossObjectOutputStream(baos, false);
-         out.writeObject(this);
-         out.flush();
-
-         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
-         JBossObjectInputStream is = new JBossObjectInputStream(bais);
-         bean = (TreeCacheStatefulBean) is.readObject();
-      }
-      catch (IOException e)
-      {
-         throw new RuntimeException(e);
-      }
-      catch (ClassNotFoundException e)
-      {
-         throw new RuntimeException(e);
-      }
-
-      if (!state.equals(bean.state))
-         throw new RuntimeException("failed to serialize: " + bean.state);
-   }
-
-   public boolean wasPassivated()
-   {
-      return wasPassivated;
-   }
-
-   public void clearPassivated()
-   {
-      wasPassivated = false;
-   }
-
-   @Init
-   public void ejbCreate(Integer state)
-   {
-      this.state = state.toString();
-   }
-
-   @Init
-   public void ejbCreate(State state)
-   {
-      this.state = state.getState();
-   }
-
-   @Init
-   public void ejbCreate(String state)
-   {
-      this.state = state;
-   }
-
-   @Remove
-   public void removeMe()
-   {
-      ++beansRemoved;
-   }
-   
-   public int beansRemoved()
-   {
-      return beansRemoved;
-   }
-
-   public void lookupStateful() throws Exception
-   {
-      // FIXME: NYI
-      throw new RuntimeException("NYI");
-   }
-
-   public void testStateful() throws Exception
-   {
-      // FIXME: NYI
-      throw new RuntimeException("NYI");
-   }
 }

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java	2009-04-16 03:00:44 UTC (rev 87397)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java	2009-04-16 03:47:55 UTC (rev 87398)
@@ -79,6 +79,7 @@
       
       // Get the start cache size 
       int startCacheSize = (Integer)server.getAttribute(testerName, "CacheSize");
+      int startTotalSize = (Integer)server.getAttribute(testerName, "TotalSize");
       
       // Establish how many beans are already active
       int prevCount = (Integer)server.getAttribute(testerName, "CreateCount");
@@ -89,13 +90,16 @@
       assertNotNull(stateful);
       stateful.setState("state");
       
-      int count = (Integer)server.getAttribute(testerName, "CreateCount");
-      assertEquals(1, count - prevCount);
+      int createCount = (Integer)server.getAttribute(testerName, "CreateCount");
+      assertEquals(1, createCount - prevCount);
       
       // Ensure cache is incremented
       int newCacheSize = (Integer)server.getAttribute(testerName, "CacheSize");
       assertEquals(startCacheSize+1, newCacheSize);
       
+      int totalSize = (Integer)server.getAttribute(testerName, "TotalSize");
+      assertEquals(startTotalSize+1, totalSize);
+      
       assertEquals("state", stateful.getState());
       stateful.testSerializedState("state");
       stateful.clearPassivated();
@@ -107,12 +111,18 @@
       int cacheSize = (Integer)server.getAttribute(testerName, "CacheSize");
       assertEquals(0, cacheSize);
       
-      count = (Integer)server.getAttribute(testerName, "PassivatedCount");
-      assertEquals(1, count - prevCount);
+      int passivatedCount = (Integer)server.getAttribute(testerName, "PassivatedCount");
+      assertEquals(1, passivatedCount - prevCount);
       assertTrue(stateful.wasPassivated());
       
+      totalSize = (Integer)server.getAttribute(testerName, "TotalSize");
+      assertEquals(cacheSize + passivatedCount, totalSize);
+      
       assertEquals("state", stateful.getState());
       assertEquals("hello world", stateful.getInterceptorState());
+      
+      passivatedCount = (Integer)server.getAttribute(testerName, "PassivatedCount");
+      assertEquals(0, passivatedCount - prevCount);
 
       Stateful another = (Stateful)getInitialContext().lookup(jndiBinding);
       assertEquals(null, another.getInterceptorState());
@@ -124,8 +134,8 @@
       
       stateful.testResources();
       
-      count = (Integer)server.getAttribute(testerName, "CreateCount");
-      assertEquals(2, count - prevCount);
+      createCount = (Integer)server.getAttribute(testerName, "CreateCount");
+      assertEquals(2, createCount - prevCount);
       
       // the injected beans are passivated at this point in time
       
@@ -134,23 +144,29 @@
       
       // keep in mind, we're not removing already injected beans
       
-      cacheSize = (Integer)server.getAttribute(testerName, "RemoveCount");
-      assertEquals(0, cacheSize);
+      int removeCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+      assertEquals(0, removeCount);
       
       another.removeMe();
       cacheSize = (Integer)server.getAttribute(testerName, "CacheSize");
       assertEquals(1, cacheSize);
       
-      cacheSize = (Integer)server.getAttribute(testerName, "RemoveCount");
-      assertEquals(1, cacheSize);
+      removeCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+      assertEquals(1, removeCount);
       
+      totalSize = (Integer)server.getAttribute(testerName, "TotalSize");
+      assertEquals(cacheSize + passivatedCount, totalSize);
+      
       stateful.removeMe();
       cacheSize = (Integer)server.getAttribute(testerName, "CacheSize");
       assertEquals(0, cacheSize);
       
-      cacheSize = (Integer)server.getAttribute(testerName, "RemoveCount");
-      assertEquals(2, cacheSize);
+      removeCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+      assertEquals(2, removeCount);
       
+      totalSize = (Integer)server.getAttribute(testerName, "TotalSize");
+      assertEquals(cacheSize + passivatedCount, totalSize);
+      
    }
 
    public void testJmxMetricsStateful() throws Exception
@@ -168,4 +184,11 @@
 
       testJmxMetrics(server, "TreeCacheStateful", "jboss.j2ee:jar=stateful-test.jar,name=TreeCacheStatefulBean,service=EJB3");
    }
+   
+   public void testJmxMetricsTreeCacheRemovalStateful() throws Exception
+   {
+      MBeanServerConnection server = getServer();
+
+      testJmxMetrics(server, "TreeCacheRemovalStateful", "jboss.j2ee:jar=stateful-test.jar,name=TreeCacheRemovalStatefulBean,service=EJB3");
+   }
 }




More information about the jboss-cvs-commits mailing list