[jboss-cvs] JBossAS SVN: r93617 - in projects/ejb3/trunk: core/src/main/java/org/jboss/ejb3 and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 16 12:13:18 EDT 2009
Author: pferraro
Date: 2009-09-16 12:13:14 -0400 (Wed, 16 Sep 2009)
New Revision: 93617
Modified:
projects/ejb3/trunk/core/pom.xml
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java
projects/ejb3/trunk/testsuite/pom.xml
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/MyStateful.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/MyStatefulBean.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/unit/ContainerShutdownTestCase.java
Log:
[EJBTHREE-1894] NPE on client invoking remote SFSB method during shutdown
Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml 2009-09-16 15:59:12 UTC (rev 93616)
+++ projects/ejb3/trunk/core/pom.xml 2009-09-16 16:13:14 UTC (rev 93617)
@@ -405,7 +405,7 @@
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-interceptors</artifactId>
- <version>1.0.4</version>
+ <version>1.0.5-SNAPSHOT</version>
</dependency>
<dependency>
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2009-09-16 15:59:12 UTC (rev 93616)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2009-09-16 16:13:14 UTC (rev 93617)
@@ -965,8 +965,11 @@
// TODO: clean up BeanContainer?
//super.cleanup();
+ /*
+ * EJBTHREE-1984: Leave invocations blocked
+ */
// Restore to pre- create() state
- this.allowInvocations();
+ // this.allowInvocations();
}
@SuppressWarnings("unchecked")
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2009-09-16 15:59:12 UTC (rev 93616)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2009-09-16 16:13:14 UTC (rev 93617)
@@ -258,6 +258,13 @@
public StatefulCache getCache()
{
+ /*
+ * EJBTHREE-1894
+ * Avoid access by multiple threads to createAndStartCache(), which is not
+ * thread-safe. If called on a stopped container, just return the stopped
+ * cache instead of creating and starting a new one - which causes more
+ * problems than it attempts to hide.
+ *
// Ensure initialized
try
{
@@ -267,7 +274,7 @@
{
throw new RuntimeException(e);
}
-
+ */
// Return
return cache;
}
@@ -548,28 +555,22 @@
//newSi.setAdvisor(getAdvisor());
/*
- * Ensure ID exists (useful for catching problems while we have context as
- * to the caller, whereas in Interceptors we do not)
+ * Perform Invocation
*/
+
+ // Create an object to hold the return value
+ Object returnValue = null;
+
try
{
- this.getCache().get(sessionId);
+ // Invoke
+ returnValue = newSi.invokeNext();
}
catch (NoSuchEJBException nsee)
{
throw this.constructProperNoSuchEjbException(nsee, invokedMethod.getActualClassName());
}
-
- /*
- * Perform Invocation
- */
-
- // Create an object to hold the return value
- Object returnValue = null;
-
- // Invoke
- returnValue = newSi.invokeNext();
-
+
// Marshall the response
response = marshallResponse(invocation, returnValue, newSi.getResponseContextInfo());
if (sessionId != null)
Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java 2009-09-16 15:59:12 UTC (rev 93616)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerMethodInvocation.java 2009-09-16 16:13:14 UTC (rev 93617)
@@ -85,7 +85,6 @@
public BeanContext<?> getBeanContext()
{
- assert beanContext != null : "beanContext has not been set";
return beanContext;
}
Modified: projects/ejb3/trunk/testsuite/pom.xml
===================================================================
--- projects/ejb3/trunk/testsuite/pom.xml 2009-09-16 15:59:12 UTC (rev 93616)
+++ projects/ejb3/trunk/testsuite/pom.xml 2009-09-16 16:13:14 UTC (rev 93617)
@@ -220,7 +220,7 @@
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-core</artifactId>
- <version>1.1.9</version>
+ <version>1.1.18-SNAPSHOT</version>
<scope>test</scope>
</dependency>
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/MyStateful.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/MyStateful.java 2009-09-16 15:59:12 UTC (rev 93616)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/MyStateful.java 2009-09-16 16:13:14 UTC (rev 93617)
@@ -30,6 +30,9 @@
@Remote
public interface MyStateful
{
- public int getCount();
- public void increment();
+ int getCount();
+
+ void increment();
+
+ void remove();
}
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/MyStatefulBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/MyStatefulBean.java 2009-09-16 15:59:12 UTC (rev 93616)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/MyStatefulBean.java 2009-09-16 16:13:14 UTC (rev 93617)
@@ -21,6 +21,7 @@
*/
package org.jboss.ejb3.test.ejbthree1116;
+import javax.ejb.Remove;
import javax.ejb.Stateful;
/**
@@ -40,4 +41,10 @@
{
this.count++;
}
+
+ @Remove
+ public void remove()
+ {
+ // nothing
+ }
}
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/unit/ContainerShutdownTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/unit/ContainerShutdownTestCase.java 2009-09-16 15:59:12 UTC (rev 93616)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1116/unit/ContainerShutdownTestCase.java 2009-09-16 16:13:14 UTC (rev 93617)
@@ -21,25 +21,37 @@
*/
package org.jboss.ejb3.test.ejbthree1116.unit;
-import java.lang.reflect.UndeclaredThrowableException;
+import java.util.HashSet;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
import javax.naming.InitialContext;
+import javax.naming.NamingException;
import junit.framework.Test;
import org.jboss.aop.DispatcherConnectException;
+import org.jboss.aop.NotFoundInDispatcherException;
import org.jboss.ejb3.test.ejbthree1116.MyStateful;
+import org.jboss.remoting.CannotConnectException;
import org.jboss.test.JBossTestCase;
/**
- * Test verifying fix of EJBTHREE-1116.
+ * Test verifying fix of EJBTHREE-1116 & EJBTHREE-1894.
* @author Paul Ferraro
*/
public class ContainerShutdownTestCase extends JBossTestCase
{
private static final String JAR = "ejbthree1116.jar";
+ private static final int ITERATIONS = 100;
+ private final Set<Class<? extends Exception>> allowedExceptions = new HashSet<Class<? extends Exception>>();
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(ContainerShutdownTestCase.class, JAR);
+ }
+
/**
* Create a new ContainerShutdownTestCase.
*
@@ -48,111 +60,254 @@
public ContainerShutdownTestCase(String name)
{
super(name);
+
+ this.allowedExceptions.add(CannotConnectException.class);
+ this.allowedExceptions.add(DispatcherConnectException.class);
+ this.allowedExceptions.add(NotFoundInDispatcherException.class);
}
- public void testSimple() throws Exception
+ public void testSimpleRemoteInvocation() throws Exception
{
MyStateful bean = (MyStateful) new InitialContext().lookup("MyStatefulBean/remote");
- bean.increment();
-
this.undeploy(JAR);
try
{
bean.increment();
}
- catch (UndeclaredThrowableException e)
+ catch (RuntimeException e)
{
- assertInstanceOf(e.getUndeclaredThrowable(), DispatcherConnectException.class);
+ Throwable cause = e.getCause();
+
+ if ((cause == null) || !this.allowedExceptions.contains(cause.getClass())) throw e;
}
- catch (Exception e)
- {
- this.log.error(e.getMessage(), e);
-
- assertTrue(e.toString(), false);
- }
finally
{
this.deploy(JAR);
}
}
- public void testConcurrent() throws Exception
+ public void testConcurrentRemoteInvocation() throws Exception
{
- MyStateful bean = (MyStateful) new InitialContext().lookup("MyStatefulBean/remote");
-
- bean.increment();
-
- final CountDownLatch latch = new CountDownLatch(2);
-
- Thread thread = new Thread()
+ for (int i = 0; i < ITERATIONS; ++i)
{
- @Override
- public void run()
+ MyStateful bean = (MyStateful) new InitialContext().lookup("MyStatefulBean/remote");
+
+ final CountDownLatch latch = new CountDownLatch(2);
+
+ Thread thread = new Thread(new UndeployTask(latch));
+
+ thread.start();
+
+ latch.countDown();
+
+ try
{
+ latch.await();
+
+ while (!Thread.currentThread().isInterrupted())
+ {
+ bean.increment();
+ }
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ catch (RuntimeException e)
+ {
+ Throwable cause = e.getCause();
+
+ if ((cause == null) || !this.allowedExceptions.contains(cause.getClass())) throw e;
+ }
+ finally
+ {
try
{
- latch.countDown();
- latch.await();
-
- ContainerShutdownTestCase.this.undeploy(JAR);
+ thread.join();
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();
}
- catch (Exception e)
- {
- ContainerShutdownTestCase.this.log.error(e.getMessage(), e);
- }
+
+ this.deploy(JAR);
}
- };
+ }
+ }
+
+ public void testSimpleRemove() throws Exception
+ {
+ MyStateful bean = (MyStateful) new InitialContext().lookup("MyStatefulBean/remote");
- thread.start();
+ this.undeploy(JAR);
- latch.countDown();
-
try
{
- latch.await();
+ bean.remove();
+ }
+ catch (RuntimeException e)
+ {
+ Throwable cause = e.getCause();
- while (!Thread.currentThread().isInterrupted())
- {
- bean.increment();
- }
-
- this.log.warn("Test was interrupted");
+ if ((cause == null) || !this.allowedExceptions.contains(cause.getClass())) throw e;
}
- catch (InterruptedException e)
+ finally
{
- this.log.warn("Test was interrupted");
+ this.deploy(JAR);
}
- catch (Exception e)
+ }
+
+ public void testConcurrentRemove() throws Exception
+ {
+ for (int i = 0; i < ITERATIONS; ++i)
{
- this.log.error(e.getMessage(), e);
+ final CountDownLatch latch = new CountDownLatch(2);
- assertInstanceOf(e, UndeclaredThrowableException.class);
+ Thread thread = new Thread(new UndeployTask(latch));
- assertInstanceOf(((UndeclaredThrowableException) e).getUndeclaredThrowable(), DispatcherConnectException.class);
+ thread.start();
+
+ try
+ {
+ MyStateful[] beans = new MyStateful[ITERATIONS];
+
+ for (int j = 0; j < ITERATIONS; ++j)
+ {
+ beans[j] = (MyStateful) new InitialContext().lookup("MyStatefulBean/remote");
+ }
+
+ latch.countDown();
+ latch.await();
+
+ for (int j = 0; j < ITERATIONS; ++j)
+ {
+ beans[j].remove();
+ }
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ catch (RuntimeException e)
+ {
+ Throwable cause = e.getCause();
+
+ if ((cause == null) || !this.allowedExceptions.contains(cause.getClass())) throw e;
+ }
+ finally
+ {
+ try
+ {
+ thread.join();
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+
+ this.deploy(JAR);
+ }
}
+ }
+
+ public void testSimpleCreate() throws Exception
+ {
+ this.undeploy(JAR);
+
+ try
+ {
+ new InitialContext().lookup("MyStatefulBean/remote");
+ }
+ catch (NamingException e)
+ {
+ // Expected
+ }
finally
{
+ this.deploy(JAR);
+ }
+ }
+
+ public void testConcurrentCreate() throws Exception
+ {
+ for (int i = 0; i < ITERATIONS; ++i)
+ {
+ final CountDownLatch latch = new CountDownLatch(2);
+
+ Thread thread = new Thread(new UndeployTask(latch));
+
+ thread.start();
+
+ latch.countDown();
+
try
{
- thread.join();
+ latch.await();
- this.deploy(JAR);
+ while (!Thread.currentThread().isInterrupted())
+ {
+ new InitialContext().lookup("MyStatefulBean/remote");
+ }
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();
}
+ catch (NamingException e)
+ {
+ // Expected
+ }
+ catch (RuntimeException e)
+ {
+ Throwable cause = e.getCause();
+
+ if ((cause == null) || !this.allowedExceptions.contains(cause.getClass())) throw e;
+ }
+ finally
+ {
+ try
+ {
+ thread.join();
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+
+ this.deploy(JAR);
+ }
}
}
- public static Test suite() throws Exception
+ private class UndeployTask implements Runnable
{
- return getDeploySetup(ContainerShutdownTestCase.class, JAR);
+ private final CountDownLatch latch;
+
+ UndeployTask(CountDownLatch latch)
+ {
+ this.latch = latch;
+ }
+
+ public void run()
+ {
+ latch.countDown();
+
+ try
+ {
+ latch.await();
+
+ ContainerShutdownTestCase.this.undeploy(JAR);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.err);
+ }
+ }
}
}
More information about the jboss-cvs-commits
mailing list