[jboss-cvs] jboss-ejb3/src/test/org/jboss/ejb3/test/cache ...
Ben Wang
bwang at jboss.com
Tue Jul 25 12:47:19 EDT 2006
User: bwang
Date: 06/07/25 12:47:19
Modified: src/test/org/jboss/ejb3/test/cache
SimpleStatefulBean.java SimpleStatefulLocal.java
SimpleStatefulRemote.java StatefulBean.java
StatefulLocal.java StatefulRemote.java Tester.java
TesterMBean.java
Log:
Ported fixes from 4.0
Revision Changes Path
1.10 +11 -19 jboss-ejb3/src/test/org/jboss/ejb3/test/cache/SimpleStatefulBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SimpleStatefulBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss-ejb3/src/test/org/jboss/ejb3/test/cache/SimpleStatefulBean.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- SimpleStatefulBean.java 13 Apr 2006 23:23:23 -0000 1.9
+++ SimpleStatefulBean.java 25 Jul 2006 16:47:19 -0000 1.10
@@ -25,17 +25,15 @@
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.ejb.Remote;
-import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.naming.InitialContext;
import org.jboss.annotation.ejb.cache.simple.CacheConfig;
-import org.jboss.logging.Logger;
/**
* Comment
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
@Stateful
@CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
@@ -43,10 +41,8 @@
@Remote(SimpleStatefulRemote.class)
public class SimpleStatefulBean implements java.io.Serializable, SimpleStatefulRemote, SimpleStatefulLocal
{
- private static final Logger log = Logger.getLogger(SimpleStatefulBean.class);
-
- public static int postActivateCalled = 0;
- public static int prePassivateCalled = 0;
+ public static boolean postActivateCalled = false;
+ public static boolean prePassivateCalled = false;
private String state;
@@ -66,15 +62,15 @@
public void longRunning() throws Exception
{
- Thread.sleep(5000);
+ Thread.sleep(11000);
}
- public int getPostActivate()
+ public boolean getPostActivate()
{
return postActivateCalled;
}
- public int getPrePassivate()
+ public boolean getPrePassivate()
{
return prePassivateCalled;
}
@@ -92,25 +88,21 @@
public void reset()
{
state = null;
- postActivateCalled = 0;
- prePassivateCalled = 0;
+ postActivateCalled = false;
+ prePassivateCalled = false;
}
@PostActivate
public void postActivate()
{
- ++postActivateCalled;
+ postActivateCalled = true;
}
@PrePassivate
public void prePassivate()
{
- ++prePassivateCalled;
+ prePassivateCalled = true;
}
- @Remove
- public void remove()
- {
- }
}
1.6 +3 -5 jboss-ejb3/src/test/org/jboss/ejb3/test/cache/SimpleStatefulLocal.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SimpleStatefulLocal.java
===================================================================
RCS file: /cvsroot/jboss/jboss-ejb3/src/test/org/jboss/ejb3/test/cache/SimpleStatefulLocal.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- SimpleStatefulLocal.java 13 Apr 2006 23:23:23 -0000 1.5
+++ SimpleStatefulLocal.java 25 Jul 2006 16:47:19 -0000 1.6
@@ -27,13 +27,13 @@
* Comment
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public interface SimpleStatefulLocal
{
- int getPostActivate();
+ boolean getPostActivate();
- int getPrePassivate();
+ boolean getPrePassivate();
void setState(String state);
@@ -42,6 +42,4 @@
void reset();
void longRunning() throws Exception;
-
- void remove();
}
1.6 +3 -5 jboss-ejb3/src/test/org/jboss/ejb3/test/cache/SimpleStatefulRemote.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SimpleStatefulRemote.java
===================================================================
RCS file: /cvsroot/jboss/jboss-ejb3/src/test/org/jboss/ejb3/test/cache/SimpleStatefulRemote.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- SimpleStatefulRemote.java 13 Apr 2006 23:23:23 -0000 1.5
+++ SimpleStatefulRemote.java 25 Jul 2006 16:47:19 -0000 1.6
@@ -27,13 +27,13 @@
* Comment
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public interface SimpleStatefulRemote
{
- int getPostActivate();
+ boolean getPostActivate();
- int getPrePassivate();
+ boolean getPrePassivate();
void setState(String state);
@@ -44,6 +44,4 @@
long bench(int iterations) throws Exception;
void longRunning() throws Exception;
-
- void remove();
}
1.13 +16 -16 jboss-ejb3/src/test/org/jboss/ejb3/test/cache/StatefulBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StatefulBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss-ejb3/src/test/org/jboss/ejb3/test/cache/StatefulBean.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- StatefulBean.java 16 May 2006 15:03:00 -0000 1.12
+++ StatefulBean.java 25 Jul 2006 16:47:19 -0000 1.13
@@ -25,8 +25,8 @@
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.ejb.Remote;
-import javax.ejb.Remove;
import javax.ejb.Stateful;
+import javax.ejb.Remove;
import javax.naming.InitialContext;
import org.jboss.annotation.ejb.cache.Cache;
import org.jboss.annotation.ejb.cache.tree.CacheConfig;
@@ -35,8 +35,7 @@
* Comment
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 1.12 $
- * @deprecated We have moved the clustered unit tests to clusteredsession.
+ * @version $Revision: 1.13 $
*/
@Stateful
@Cache(org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
@@ -45,8 +44,8 @@
@Remote(StatefulRemote.class)
public class StatefulBean implements StatefulRemote, java.io.Serializable, StatefulLocal
{
- public static int postActivateCalled = 0;
- public static int prePassivateCalled = 0;
+ public static boolean postActivateCalled = false;
+ public static boolean prePassivateCalled = false;
private String state;
@@ -66,15 +65,19 @@
public void longRunning() throws Exception
{
- Thread.sleep(5000);
+ Thread.sleep(11000);
+ }
+
+ @Remove
+ public void done() {
}
- public int getPostActivate()
+ public boolean getPostActivate()
{
return postActivateCalled;
}
- public int getPrePassivate()
+ public boolean getPrePassivate()
{
return prePassivateCalled;
}
@@ -92,24 +95,21 @@
public void reset()
{
state = null;
- postActivateCalled = 0;
- prePassivateCalled = 0;
+ postActivateCalled = false;
+ prePassivateCalled = false;
}
@PostActivate
public void postActivate()
{
- ++postActivateCalled;
+ postActivateCalled = true;
}
@PrePassivate
public void prePassivate()
{
- ++prePassivateCalled;
+ prePassivateCalled = true;
}
- @Remove
- public void remove()
- {
- }
+
}
1.5 +5 -5 jboss-ejb3/src/test/org/jboss/ejb3/test/cache/StatefulLocal.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StatefulLocal.java
===================================================================
RCS file: /cvsroot/jboss/jboss-ejb3/src/test/org/jboss/ejb3/test/cache/StatefulLocal.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- StatefulLocal.java 13 Apr 2006 23:23:23 -0000 1.4
+++ StatefulLocal.java 25 Jul 2006 16:47:19 -0000 1.5
@@ -27,13 +27,13 @@
* Comment
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public interface StatefulLocal
{
- int getPostActivate();
+ boolean getPostActivate();
- int getPrePassivate();
+ boolean getPrePassivate();
void setState(String state);
@@ -41,5 +41,5 @@
void reset();
- void remove();
+ void done();
}
1.6 +5 -5 jboss-ejb3/src/test/org/jboss/ejb3/test/cache/StatefulRemote.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StatefulRemote.java
===================================================================
RCS file: /cvsroot/jboss/jboss-ejb3/src/test/org/jboss/ejb3/test/cache/StatefulRemote.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- StatefulRemote.java 13 Apr 2006 23:23:23 -0000 1.5
+++ StatefulRemote.java 25 Jul 2006 16:47:19 -0000 1.6
@@ -27,13 +27,13 @@
* Comment
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public interface StatefulRemote
{
- int getPostActivate();
+ boolean getPostActivate();
- int getPrePassivate();
+ boolean getPrePassivate();
void setState(String state);
@@ -45,5 +45,5 @@
void longRunning() throws Exception;
- void remove();
+ void done();
}
1.11 +48 -15 jboss-ejb3/src/test/org/jboss/ejb3/test/cache/Tester.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Tester.java
===================================================================
RCS file: /cvsroot/jboss/jboss-ejb3/src/test/org/jboss/ejb3/test/cache/Tester.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- Tester.java 10 May 2006 01:06:46 -0000 1.10
+++ Tester.java 25 Jul 2006 16:47:19 -0000 1.11
@@ -22,20 +22,13 @@
package org.jboss.ejb3.test.cache;
import java.io.File;
-
import javax.management.ObjectName;
import javax.naming.InitialContext;
-
import org.jboss.cache.TreeCacheMBean;
import org.jboss.cache.loader.FileCacheLoader;
-import org.jboss.cache.TreeCache;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.LRUPolicy;
-import org.jboss.cache.eviction.Region;
-import org.jboss.cache.eviction.RegionNameConflictException;
-import org.jboss.ejb3.cache.tree.PassivationEvictionPolicy;
+//import org.jboss.ejb3.cache.tree.PassivationEvictionPolicy;
import org.jboss.ejb3.cache.tree.PassivationTreeCache;
-import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanProxy;
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.system.server.ServerConfig;
@@ -43,10 +36,52 @@
* Comment
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class Tester extends ServiceMBeanSupport implements TesterMBean
{
+ public void test() throws Exception
+ {
+ ObjectName cacheON = new ObjectName("jboss.cache:service=EJB3TreeCache");
+ TreeCacheMBean mbean = (TreeCacheMBean) MBeanProxy.get(TreeCacheMBean.class, cacheON, server);
+ PassivationTreeCache cache = (PassivationTreeCache) mbean.getInstance();
+// PassivationEvictionPolicy policy = (PassivationEvictionPolicy) cache.getEvictionPolicy();
+// policy.createRegion("/mySFSB", 100, 1L);
+
+ cache.put("/mySFSB/1234", "hello", "world");
+ System.out.println("After PUT");
+ Thread.sleep(5000);
+
+ System.out.println("WAKE UP!");
+ File fp = new File(System.getProperty(ServerConfig.SERVER_TEMP_DIR) + "/stateful/mySFSB." + FileCacheLoader.DIR_SUFFIX + "/1234." + FileCacheLoader.DIR_SUFFIX);
+ System.out.println("exists in DB: " + fp.exists());
+ if (!fp.exists()) throw new RuntimeException("No passivation happened.");
+ System.out.println(cache.get("/mySFSB/1234", "hello"));
+ System.out.println("exists in DB: " + fp.exists());
+ if (fp.exists()) throw new RuntimeException("Should have been removed on activation.");
+ if (cache.exists("/mySFSB/1234"))
+ {
+ cache.remove("/mySFSB/1234");
+// synchronized (policy)
+// {
+// policy.removeRegion("/mySFSB");
+// }
+ cache.remove("/mySFSB");
+ }
+ }
+
+ public void testSimpleRemote() throws Exception
+ {
+ SimpleStatefulRemote remote = (SimpleStatefulRemote) new InitialContext().lookup("SimpleStatefulBean/remote");
+ remote.reset();
+ remote.setState("hello");
+ remote.longRunning();
+ if (!"hello".equals(remote.getState())) throw new RuntimeException("failed state");
+ if (!remote.getPostActivate()) throw new RuntimeException("failed to postActivate");
+ if (!remote.getPrePassivate()) throw new RuntimeException("failed to prePassivate");
+
+ }
+
public void testSimpleLocal() throws Exception
{
SimpleStatefulLocal local = (SimpleStatefulLocal) new InitialContext().lookup("SimpleStatefulBean/local");
@@ -54,10 +89,8 @@
local.setState("hello");
local.longRunning();
if (!"hello".equals(local.getState())) throw new RuntimeException("failed state");
- if (local.getPostActivate() != 1) throw new RuntimeException("failed to postActivate:" + local.getPostActivate());
- if (local.getPrePassivate() != 1) throw new RuntimeException("failed to prePassivate:" + local.getPrePassivate());
+ if (!local.getPostActivate()) throw new RuntimeException("failed to postActivate");
+ if (!local.getPrePassivate()) throw new RuntimeException("failed to prePassivate");
- local.remove();
}
-
}
1.5 +5 -1 jboss-ejb3/src/test/org/jboss/ejb3/test/cache/TesterMBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TesterMBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss-ejb3/src/test/org/jboss/ejb3/test/cache/TesterMBean.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- TesterMBean.java 10 May 2006 01:06:46 -0000 1.4
+++ TesterMBean.java 25 Jul 2006 16:47:19 -0000 1.5
@@ -27,9 +27,13 @@
* Comment
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public interface TesterMBean extends ServiceMBean
{
+ void test() throws Exception;
+
void testSimpleLocal() throws Exception;
+
+ void testSimpleRemote() throws Exception;
}
More information about the jboss-cvs-commits
mailing list