[jboss-cvs] JBossAS SVN: r112496 - in projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test: jbpapp7523 and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Dec 1 04:09:55 EST 2011
Author: wolfc
Date: 2011-12-01 04:09:54 -0500 (Thu, 01 Dec 2011)
New Revision: 112496
Added:
projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/
projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/SimpleSFSB.java
projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/
projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/SimpleCachePassivationDeadlockTestCase.java
Log:
JBPAPP-7523: test locking behavior with a small cache
Added: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/SimpleSFSB.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/SimpleSFSB.java (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/SimpleSFSB.java 2011-12-01 09:09:54 UTC (rev 112496)
@@ -0,0 +1,13 @@
+package org.jboss.ejb3.core.test.jbpapp7523;
+
+import javax.ejb.Stateful;
+
+import org.jboss.ejb3.annotation.CacheConfig;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateful
+ at CacheConfig(maxSize = 1) // passivate on second creation
+public class SimpleSFSB {
+}
Added: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/SimpleCachePassivationDeadlockTestCase.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/SimpleCachePassivationDeadlockTestCase.java (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/SimpleCachePassivationDeadlockTestCase.java 2011-12-01 09:09:54 UTC (rev 112496)
@@ -0,0 +1,149 @@
+package org.jboss.ejb3.core.test.jbpapp7523.unit;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.jboss.ejb3.cache.simple.SimpleStatefulCache;
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.jbpapp7523.SimpleSFSB;
+import org.jboss.ejb3.session.SessionContainer;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.junit.Assert.fail;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class SimpleCachePassivationDeadlockTestCase extends AbstractEJB3TestCase {
+ private static SessionContainer container;
+
+ private static SimpleStatefulCache cache;
+
+ private static final CyclicBarrier barrier = new CyclicBarrier(2);
+
+ private ExecutorService service;
+
+ @After
+ public void after() {
+ service.shutdown();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ cache.stop();
+
+ undeployEjb(container);
+
+ AbstractEJB3TestCase.afterClass();
+ }
+
+ private static int await(final CyclicBarrier barrier, final long timeout, final TimeUnit unit) {
+ try {
+ return barrier.await(timeout, unit);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } catch (BrokenBarrierException e) {
+ throw new RuntimeException(e);
+ } catch (TimeoutException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Before
+ public void before() {
+ service = Executors.newFixedThreadPool(2);
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ AbstractEJB3TestCase.beforeClass();
+
+ // Deploy the test SLSB
+ container = deploySessionEjb(SimpleSFSB.class);
+
+ cache = new SimpleStatefulCache() {
+ protected void passivate(final StatefulBeanContext ctx) {
+ if (!barrier.isBroken())
+ await(barrier, 10, SECONDS);
+ //await(barrier, 10, SECONDS);
+ super.passivate(ctx);
+ }
+ };
+ cache.initialize(container);
+ cache.start();
+ }
+
+ @Test
+ public void testSmallCacheCreates() throws Exception {
+ // Fill the cache.
+ final StatefulBeanContext bean1 = cache.create();
+ cache.release(bean1);
+ final Future<StatefulBeanContext> futureBean2 = service.submit(new Callable<StatefulBeanContext>() {
+ @Override
+ public StatefulBeanContext call() throws Exception {
+ final StatefulBeanContext ctx = cache.create();
+ cache.release(ctx);
+ return ctx;
+ }
+ });
+ // Force bean1 in the first cacheMap sync.
+ final Future<StatefulBeanContext> futureBean1 = service.submit(new Callable<StatefulBeanContext>() {
+ @Override
+ public StatefulBeanContext call() throws Exception {
+ return cache.get(bean1.getId());
+ }
+ });
+ // Setup another create run to lock the cacheMap after bean1 proceeds.
+ final Future<StatefulBeanContext> futureBean3 = service.submit(new Callable<StatefulBeanContext>() {
+ @Override
+ public StatefulBeanContext call() throws Exception {
+ final StatefulBeanContext ctx = cache.create();
+ cache.release(ctx);
+ return ctx;
+ }
+ });
+ // Go bean 2! This will make either bean1 or bean3 move forward as well.
+ barrier.await(10, SECONDS);
+ // bean1 should be at SimpleStatefulCachemap:492 (or bean3 moved).
+ // Since there is nothing in SimpleStatefulCache.get where we can control movement, we can only hope.
+ /*
+ final Future<StatefulBeanContext> futureBean4 = service.submit(new Callable<StatefulBeanContext>() {
+ @Override
+ public StatefulBeanContext call() throws Exception {
+ final StatefulBeanContext ctx = cache.create();
+ cache.release(ctx);
+ return ctx;
+ }
+ });
+ */
+ // Go bean 3!
+ barrier.await(10, SECONDS);
+ // Break the barrier (bean3 needs to be passivated to make room for bean1).
+ try {
+ barrier.await(0, SECONDS);
+ } catch (TimeoutException e) {
+ // good
+ }
+ // Now we should have a response within 10 seconds.
+ try {
+ futureBean1.get(10, SECONDS);
+ } catch (TimeoutException e) {
+ fail("JBPAPP-7523: cache failed to respond in time");
+ }
+ futureBean2.get(10, SECONDS);
+ futureBean3.get(10, SECONDS);
+ //futureBean4.get(10, SECONDS);
+ }
+}
More information about the jboss-cvs-commits
mailing list