[jboss-cvs] JBossAS SVN: r90049 - in projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test: ejbthree1846 and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 10 06:06:44 EDT 2009
Author: wolfc
Date: 2009-06-10 06:06:44 -0400 (Wed, 10 Jun 2009)
New Revision: 90049
Added:
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/MyStateful.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/MyStatefulBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/PassivateContextTestCase.java
Log:
EJBTHREE-1846: unit test
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/MyStateful.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/MyStateful.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/MyStateful.java 2009-06-10 10:06:44 UTC (rev 90049)
@@ -0,0 +1,34 @@
+/*
+ * 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.ejbthree1846;
+
+import javax.ejb.Local;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Local
+public interface MyStateful
+{
+ MyStateful getBusinessObject();
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/MyStatefulBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/MyStatefulBean.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/MyStatefulBean.java 2009-06-10 10:06:44 UTC (rev 90049)
@@ -0,0 +1,93 @@
+/*
+ * 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.ejbthree1846;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.annotation.Resource;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+
+import org.jboss.ejb3.annotation.CacheConfig;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at CacheConfig(idleTimeoutSeconds=1)
+public class MyStatefulBean implements MyStateful
+{
+ private static final Logger log = Logger.getLogger(MyStatefulBean.class);
+
+ /*
+ * for unit test only
+ */
+ public static volatile int activations = 0;
+ public static volatile int passivations = 0;
+
+ public static CyclicBarrier barrier = new CyclicBarrier(2);
+
+ @Resource
+ private SessionContext ctx;
+
+ public MyStateful getBusinessObject()
+ {
+ return ctx.getBusinessObject(MyStateful.class);
+ }
+
+ @PostActivate
+ public void postActivate()
+ {
+ log.info("postActivate");
+ activations++;
+ }
+
+ @PrePassivate
+ public void prePassivate()
+ {
+ log.info("prePassivate");
+ passivations++;
+ try
+ {
+ barrier.await(5000, TimeUnit.MILLISECONDS);
+ }
+ catch (BrokenBarrierException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch(InterruptedException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (TimeoutException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/PassivateContextTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/PassivateContextTestCase.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/PassivateContextTestCase.java 2009-06-10 10:06:44 UTC (rev 90049)
@@ -0,0 +1,80 @@
+/*
+ * 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.ejbthree1846.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.ejbthree1846.MyStateful;
+import org.jboss.ejb3.core.test.ejbthree1846.MyStatefulBean;
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class PassivateContextTestCase extends AbstractEJB3TestCase
+{
+ private static StatefulContainer container;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ AbstractEJB3TestCase.beforeClass();
+
+ container = (StatefulContainer) deploySessionEjb(MyStatefulBean.class);
+ }
+
+ @Before
+ public void before()
+ {
+ MyStatefulBean.activations = 0;
+ MyStatefulBean.passivations = 0;
+ }
+
+ @Test
+ public void test1() throws Throwable
+ {
+ Serializable id = container.getSessionFactory().createSession(null, null);
+
+ Method method = MyStateful.class.getMethod("getBusinessObject");
+ MyStateful bean = (MyStateful) container.invoke(id, MyStateful.class, method, null);
+
+ MyStatefulBean.barrier.await(5000, TimeUnit.MILLISECONDS);
+
+ assertEquals(0, MyStatefulBean.activations);
+ assertEquals(1, MyStatefulBean.passivations);
+
+ MyStateful bean2 = bean.getBusinessObject();
+
+ assertEquals(1, MyStatefulBean.activations);
+
+ assertEquals(bean, bean2);
+ }
+}
More information about the jboss-cvs-commits
mailing list