[jboss-cvs] JBossAS SVN: r112538 - 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 22 06:24:02 EST 2011


Author: wolfc
Date: 2011-12-22 06:24:01 -0500 (Thu, 22 Dec 2011)
New Revision: 112538

Added:
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/PassivatingStatefulBean.java
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/PassivatingStatefulLocal.java
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/DoubleActivationTestCase.java
Modified:
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
Log:
JBPAPP-7523 / JBPAPP-7602: fix regression on multiple passivations

Modified: projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2011-12-22 06:44:53 UTC (rev 112537)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2011-12-22 11:24:01 UTC (rev 112538)
@@ -484,6 +484,7 @@
                   @Override
                   public StatefulBeanContext call() throws Exception {
                       StatefulBeanContext entry;
+                      // has someone already activated it?
                       synchronized (cacheMap)
                       {
                          entry = cacheMap.get(key);
@@ -507,6 +508,9 @@
                          synchronized (cacheMap)
                          {
                             cacheMap.put(key, entry);
+                            // remove the activation, worst case a new task will be constructed and
+                            // the check whether someone has already activated it will prevent actual activation.
+                            activations.remove(key);
                          }
                       }
                       return entry;

Added: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/PassivatingStatefulBean.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/PassivatingStatefulBean.java	                        (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/PassivatingStatefulBean.java	2011-12-22 11:24:01 UTC (rev 112538)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2011, Red Hat, Inc., 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.core.test.jbpapp7523;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.ejb.PostActivate;
+import javax.ejb.Stateful;
+
+import org.jboss.ejb3.annotation.Cache;
+import org.jboss.ejb3.annotation.CacheConfig;
+import org.jboss.ejb3.core.test.jbpapp1561.TestCacheFactory;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateful
+ at CacheConfig(idleTimeoutSeconds=1)
+ at Cache(TestCacheFactory.NAME)
+public class PassivatingStatefulBean extends org.jboss.ejb3.core.test.jbpapp1561.PassivatingStatefulBean implements PassivatingStatefulLocal {
+    public static final AtomicInteger postActivations = new AtomicInteger(0);
+
+    @Override
+    public void activate() {
+        System.out.println("Ready");
+    }
+
+    @PostActivate
+    protected void postActivate() {
+        postActivations.incrementAndGet();
+    }
+}

Copied: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/PassivatingStatefulLocal.java (from rev 112537, projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp1561/PassivatingStatefulLocal.java)
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/PassivatingStatefulLocal.java	                        (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/PassivatingStatefulLocal.java	2011-12-22 11:24:01 UTC (rev 112538)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.jbpapp7523;
+
+import javax.ejb.Local;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Local
+public interface PassivatingStatefulLocal {
+    void activate();
+}

Added: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/DoubleActivationTestCase.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/DoubleActivationTestCase.java	                        (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/core/test/jbpapp7523/unit/DoubleActivationTestCase.java	2011-12-22 11:24:01 UTC (rev 112538)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2011, Red Hat, Inc., 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.core.test.jbpapp7523.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Assert;
+import org.jboss.ejb3.cache.CacheFactoryRegistry;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.jbpapp1561.TestCache;
+import org.jboss.ejb3.core.test.jbpapp1561.TestCacheFactory;
+import org.jboss.ejb3.core.test.jbpapp7523.PassivatingStatefulBean;
+import org.jboss.ejb3.core.test.jbpapp7523.PassivatingStatefulLocal;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class DoubleActivationTestCase extends AbstractEJB3TestCase {
+    @Before
+    public void before() {
+        PassivatingStatefulBean.postActivations.set(0);
+    }
+
+    @BeforeClass
+    public static void beforeClass() throws Exception {
+        AbstractEJB3TestCase.beforeClass();
+
+        // Add the Force Passivation Cache
+        CacheFactoryRegistry cacheFactoryRegistry = Ejb3RegistrarLocator.locateRegistrar().lookup("EJB3CacheFactoryRegistry", CacheFactoryRegistry.class);
+        cacheFactoryRegistry.getFactories().put(TestCacheFactory.NAME, TestCacheFactory.class);
+
+        // Deploy the test SLSB
+        deploySessionEjb(PassivatingStatefulBean.class);
+    }
+
+    @Test
+    public void testPassivateTwice() throws Exception {
+        PassivatingStatefulLocal bean = lookup("PassivatingStatefulBean/local", PassivatingStatefulLocal.class);
+        Assert.assertNotNull(bean);
+
+        PassivatingStatefulBean.barrier.await(10, TimeUnit.SECONDS);
+        synchronized (TestCache.passivationCompleteNotification) {
+            TestCache.passivationCompleteNotification.wait(10000);
+        }
+
+        assertEquals(0, PassivatingStatefulBean.postActivations.get());
+
+        bean.activate();
+        assertEquals(1, PassivatingStatefulBean.postActivations.get());
+
+        PassivatingStatefulBean.barrier.await(10, TimeUnit.SECONDS);
+        synchronized (TestCache.passivationCompleteNotification) {
+            TestCache.passivationCompleteNotification.wait(10000);
+        }
+
+        bean.activate();
+        assertEquals(2, PassivatingStatefulBean.postActivations.get());
+    }
+}



More information about the jboss-cvs-commits mailing list