1 22 package org.jboss.ejb3.test.cache; 23 24 import java.io.File ; 25 26 import javax.management.ObjectName ; 27 import javax.naming.InitialContext ; 28 29 import org.jboss.cache.Cache; 30 import org.jboss.cache.Fqn; 31 import org.jboss.cache.jmx.CacheJmxWrapperMBean; 32 import org.jboss.cache.loader.FileCacheLoader; 33 import org.jboss.mx.util.MBeanProxy; 34 import org.jboss.system.ServiceMBeanSupport; 35 import org.jboss.system.server.ServerConfig; 36 37 43 public class Tester extends ServiceMBeanSupport implements TesterMBean 44 { 45 public void test() throws Exception 46 { 47 ObjectName cacheON = new ObjectName ("jboss.cache:service=EJB3TreeCache"); 48 CacheJmxWrapperMBean mbean = (CacheJmxWrapperMBean) MBeanProxy.get(CacheJmxWrapperMBean.class, cacheON, server); 49 Cache cache = mbean.getCache(); 50 53 Fqn mysfbf1234 = Fqn.fromString("/mySFSB/1234"); 54 cache.put(mysfbf1234, "hello", "world"); 55 System.out.println("After PUT"); 56 Thread.sleep(5000); 57 58 System.out.println("WAKE UP!"); 59 File fp = new File (System.getProperty(ServerConfig.SERVER_TEMP_DIR) + "/stateful/mySFSB." + FileCacheLoader.DIR_SUFFIX + "/1234." + FileCacheLoader.DIR_SUFFIX); 60 System.out.println("exists in DB: " + fp.exists()); 61 if (!fp.exists()) throw new RuntimeException ("No passivation happened."); 62 System.out.println(cache.get(mysfbf1234, "hello")); 63 System.out.println("exists in DB: " + fp.exists()); 64 if (fp.exists()) throw new RuntimeException ("Should have been removed on activation."); 65 if (cache.hasChild(mysfbf1234)) 66 { 67 cache.remove("/mySFSB/1234"); 68 cache.remove("/mySFSB"); 73 } 74 } 75 76 public void testSimpleRemote() throws Exception 77 { 78 SimpleStatefulRemote remote = (SimpleStatefulRemote) new InitialContext ().lookup("SimpleStatefulBean/remote"); 79 remote.reset(); 80 remote.setState("hello"); 81 remote.longRunning(); 82 if (!"hello".equals(remote.getState())) throw new RuntimeException ("failed state"); 83 if (!remote.getPostActivate()) throw new RuntimeException ("failed to postActivate"); 84 if (!remote.getPrePassivate()) throw new RuntimeException ("failed to prePassivate"); 85 86 } 87 88 public void testSimpleLocal() throws Exception 89 { 90 SimpleStatefulLocal local = (SimpleStatefulLocal) new InitialContext ().lookup("SimpleStatefulBean/local"); 91 local.reset(); 92 local.setState("hello"); 93 local.longRunning(); 94 if (!"hello".equals(local.getState())) throw new RuntimeException ("failed state"); 95 if (!local.getPostActivate()) throw new RuntimeException ("failed to postActivate"); 96 if (!local.getPrePassivate()) throw new RuntimeException ("failed to prePassivate"); 97 98 } 99 } 100 | Popular Tags |