[jboss-cvs] JBossAS SVN: r87528 - in projects/ejb3/trunk/testsuite/src/test: java/org/jboss/ejb3/test/clusteredsession/nested/base/std and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Apr 19 00:08:43 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-04-19 00:08:43 -0400 (Sun, 19 Apr 2009)
New Revision: 87528

Added:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1053/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1053/unit/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1053/unit/ConsistentPassivatedStateUnitTestCase.java
Modified:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/clusteredsession/nested/base/std/ClusteredLocalNestedStatefulBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/clusteredsession/nested/base/std/ClusteredRemoteNestedStatefulBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/base/std/NestedStateful.java
   projects/ejb3/trunk/testsuite/src/test/resources/known-issues.xml
Log:
[EJBTHREE-1053] Port test from Branch_4_2; include as a known issue

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/clusteredsession/nested/base/std/ClusteredLocalNestedStatefulBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/clusteredsession/nested/base/std/ClusteredLocalNestedStatefulBean.java	2009-04-19 02:32:33 UTC (rev 87527)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/clusteredsession/nested/base/std/ClusteredLocalNestedStatefulBean.java	2009-04-19 04:08:43 UTC (rev 87528)
@@ -7,11 +7,14 @@
 
 package org.jboss.ejb3.test.clusteredsession.nested.base.std;
 
+import java.rmi.dgc.VMID;
+
 import javax.ejb.Local;
 import javax.ejb.Stateful;
 
 import org.jboss.ejb3.annotation.CacheConfig;
 import org.jboss.ejb3.annotation.Clustered;
+import org.jboss.ejb3.test.stateful.nested.base.VMTracker;
 import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
 import org.jboss.ejb3.test.stateful.nested.base.std.NestedStatefulBean;
 
@@ -31,4 +34,9 @@
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 1L;
+   
+   public VMID getVMID()
+   {
+      return VMTracker.VMID;
+   }
 }

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/clusteredsession/nested/base/std/ClusteredRemoteNestedStatefulBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/clusteredsession/nested/base/std/ClusteredRemoteNestedStatefulBean.java	2009-04-19 02:32:33 UTC (rev 87527)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/clusteredsession/nested/base/std/ClusteredRemoteNestedStatefulBean.java	2009-04-19 04:08:43 UTC (rev 87528)
@@ -7,11 +7,14 @@
 
 package org.jboss.ejb3.test.clusteredsession.nested.base.std;
 
+import java.rmi.dgc.VMID;
+
 import javax.ejb.Remote;
 import javax.ejb.Stateful;
 
 import org.jboss.ejb3.annotation.CacheConfig;
 import org.jboss.ejb3.annotation.Clustered;
+import org.jboss.ejb3.test.stateful.nested.base.VMTracker;
 import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
 import org.jboss.ejb3.test.stateful.nested.base.std.OptimizedNestedStatefulBean;
 
@@ -31,4 +34,9 @@
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 1L;
+   
+   public VMID getVMID()
+   {
+      return VMTracker.VMID;
+   }
 }

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1053/unit/ConsistentPassivatedStateUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1053/unit/ConsistentPassivatedStateUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1053/unit/ConsistentPassivatedStateUnitTestCase.java	2009-04-19 04:08:43 UTC (rev 87528)
@@ -0,0 +1,213 @@
+/*
+ * 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.ejbthree1053.unit;
+
+import java.rmi.dgc.VMID;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedBeanMonitor;
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
+import org.jboss.ejb3.test.stateful.nested.base.std.ParentStatefulRemote;
+import org.jboss.ejb3.test.stateful.unit.NestedBeanTestRunner;
+import org.jboss.ejb3.test.stateful.unit.NestedBeanTestRunner.NestedBeanSet;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jnp.interfaces.NamingContext;
+
+/**
+ * FIXME This is a very weak test for EJBTHREE-1053; 
+ * replace with something better when EJBTHREE-1053 is fixed 
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 68169 $
+ */
+public class ConsistentPassivatedStateUnitTestCase 
+   extends JBossClusteredTestCase
+{
+   private NestedBeanTestRunner runner;
+   
+   
+   public ConsistentPassivatedStateUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ConsistentPassivatedStateUnitTestCase.class,
+                            "clusteredsession-nested.jar");
+   }
+   
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      runner = new NestedBeanTestRunner(getInitialContext(0), getLog());
+      runner.setUp();
+      // Use a sleep time equal to 2 thread runs + a 100 ms fudge
+      runner.setSleepTime(10100L);
+      // For clustered beans, an invocation is a passivation
+      runner.setPassivationPerInvocation(1);
+      // For clustered beans, passivation occurs after already called
+      // @PrePassivate for replication, so don't get a 2nd event
+      runner.setPassivationPerSleep(0);
+   }
+
+   private InitialContext getInitialContext(int node) throws Exception {
+      // Connect to the serverX JNDI
+      String[] urls = getNamingURLs();
+      Properties env1 = new Properties();
+      env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+         "org.jnp.interfaces.NamingContextFactory");
+      env1.setProperty(Context.PROVIDER_URL, urls[node]);
+      return new InitialContext(env1);
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      if (runner != null)
+         runner.tearDown();
+   }
+   
+   /**
+    * 
+    * 
+    * @throws Exception
+    */
+   public void testConsistentPassivatedState()
+   throws Exception
+   {
+      getLog().debug("Running testConsistentPassivatedState()");
+      getLog().debug("=======================================");
+      
+      int parentInv = 0;
+      int nestedInv = 0;
+      
+
+      String[] namingURLS = this.getNamingURLs();
+      
+      Properties env = new Properties();
+      env.put(NamingContext.PROVIDER_URL, namingURLS[0]);
+      
+      Context ctx = new InitialContext(env); 
+      
+      getLog().debug("Looking up NestedBeanMonitorBean...");
+      NestedBeanMonitor monitor = (NestedBeanMonitor) ctx.lookup("NestedBeanMonitorBean/remote");
+      VMID monitorVM = monitor.getVMID();
+      runner.addRemovable(monitor);
+      ParentStatefulRemote parent = null;      
+      boolean vmMatch = true;
+      for (int i = 0; i < 20 && vmMatch; i++)
+      {
+         env.put(NamingContext.PROVIDER_URL, namingURLS[i % 2]);         
+         ctx = new InitialContext(env); 
+         
+         getLog().debug("Looking up testParentStateful... Attempt " + (i + 1));
+         parent = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
+
+         VMID parentVM = parent.getVMID();
+         vmMatch = monitorVM.equals(parentVM);
+         runner.addRemovable(parent);
+         if (vmMatch)
+         {
+            runner.removeBean(parent);
+         }
+      }
+      
+      assertFalse("Monitor and SFSB in same VM", vmMatch);
+      
+      // Reset the parent to initialize all the beans
+      parent.reset();
+      
+      // Monitor the parent
+      monitor.monitor(parent);
+      
+      // Reset the parent to clean things up
+      parent.reset();
+      parentInv++;
+      nestedInv++;
+      
+      NestedStateful nested = (NestedStateful) parent.getNested();
+      parentInv++;
+      runner.addRemovable(nested);
+      
+      NestedBeanSet beanSet = runner.getNestedBeanSet();
+      
+      int attempts = 0;
+      while (beanSet.parent.getVMID().equals(beanSet.nested.getVMID()))
+      {
+         if (++attempts == 20)
+         {
+            System.err.println("Unable to obtain nested bean running on separate VM from parent");
+            log.warn("Unable to obtain nested bean running on separate VM from parent");
+            return;
+         }
+         beanSet = runner.getNestedBeanSet();
+      }
+
+      // Exercise the beans, trigger replication
+      assertEquals("Remote counter: ", 1, parent.increment());
+      parentInv++;
+      nestedInv++;
+      assertEquals("Remote counter: ", 2, parent.increment());
+      parentInv++;
+      nestedInv++;
+      assertEquals("Local counter: ", 1, parent.incrementLocal());
+      parentInv++;
+      assertEquals("Local counter: ", 2, parent.incrementLocal());
+      parentInv++;
+      
+      // This call activates the nested bean without triggering the @PrePassivate
+      // callback at the end of the call because of the way the bean
+      // implements Optimized
+      nested.getPrePassivate();
+      
+      // Passivate. The nested bean will get the @PrePassivate callback since
+      // the previous call activated it
+      sleep(runner.getSleepTime());
+      
+      // NOTE: here the invocation goes through the monitor, which has a
+      // different proxy.  It may pick a different target server than that
+      // used by our 'nested' variable's proxy.  If so, we then test if the 
+      // state is as expected on the 2nd server.
+      // If by chance it picks the same target as 'nested', this test is meaningless
+      // So, any failures will be transient
+      // TODO if JBCACHE-1190 is fixed this test may need some re-work
+      int prePass = monitor.getNestedPassivations();
+      assertTrue("EJBTHREE-1053 Deep nested passivate count (" + prePass +
+            ") incorrect, expected " + (nestedInv + 1) + " or " + (parentInv + 1), 
+            prePass == nestedInv + 1 || prePass == parentInv + 1);
+      
+      getLog().debug("ok");
+   }
+
+}


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

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java	2009-04-19 02:32:33 UTC (rev 87527)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java	2009-04-19 04:08:43 UTC (rev 87528)
@@ -7,10 +7,13 @@
 
 package org.jboss.ejb3.test.stateful.nested;
 
+import java.rmi.dgc.VMID;
+
 import javax.ejb.Local;
 import javax.ejb.Stateful;
 
 import org.jboss.ejb3.annotation.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.VMTracker;
 import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
 import org.jboss.ejb3.test.stateful.nested.base.std.NestedStatefulBean;
 
@@ -29,4 +32,9 @@
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 1L;
+   
+   public VMID getVMID()
+   {
+      return VMTracker.VMID;
+   }
 }

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java	2009-04-19 02:32:33 UTC (rev 87527)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java	2009-04-19 04:08:43 UTC (rev 87528)
@@ -7,10 +7,13 @@
 
 package org.jboss.ejb3.test.stateful.nested;
 
+import java.rmi.dgc.VMID;
+
 import javax.ejb.Remote;
 import javax.ejb.Stateful;
 
 import org.jboss.ejb3.annotation.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.VMTracker;
 import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
 import org.jboss.ejb3.test.stateful.nested.base.std.OptimizedNestedStatefulBean;
 
@@ -29,4 +32,9 @@
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 1L;
+   
+   public VMID getVMID()
+   {
+      return VMTracker.VMID;
+   }
 }

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/base/std/NestedStateful.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/base/std/NestedStateful.java	2009-04-19 02:32:33 UTC (rev 87527)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/stateful/nested/base/std/NestedStateful.java	2009-04-19 04:08:43 UTC (rev 87528)
@@ -7,6 +7,8 @@
 
 package org.jboss.ejb3.test.stateful.nested.base.std;
 
+import java.rmi.dgc.VMID;
+
 import org.jboss.ejb3.test.stateful.nested.base.MidLevel;
 
 
@@ -18,5 +20,6 @@
  */
 public interface NestedStateful extends MidLevel
 {
+   VMID getVMID();
    int increment();
 }

Modified: projects/ejb3/trunk/testsuite/src/test/resources/known-issues.xml
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/known-issues.xml	2009-04-19 02:32:33 UTC (rev 87527)
+++ projects/ejb3/trunk/testsuite/src/test/resources/known-issues.xml	2009-04-19 04:08:43 UTC (rev 87528)
@@ -48,5 +48,7 @@
   <entry key="org.jboss.ejb3.test.ejbthree1647.unit.ResourceInjectionIntoPrimitivesTestCase.testStringInjectionUsingResourceMappedName">show</entry>
   <entry key="org.jboss.ejb3.test.ejbthree1647.unit.ResourceInjectionIntoPrimitivesTestCase.testIntInjectionUsingResourceMappedName">show</entry>
   <entry key="org.jboss.ejb3.test.ejbthree1647.unit.ResourceInjectionIntoPrimitivesTestCase.testIntegerInjectionUsingResourceMappedName">show</entry>
+  <!-- EJBTHREE-1053 -->
+  <entry key="org.jboss.ejb3.test.ejbthree1053.unit.ConsistentPassivatedStateUnitTestCase.testConsistentPassivatedState">show</entry>
   
 </properties>




More information about the jboss-cvs-commits mailing list