001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.cache;
023:
024: import java.io.File;
025: import javax.management.ObjectName;
026: import javax.naming.InitialContext;
027:
028: import org.jboss.cache.TreeCache;
029: import org.jboss.cache.TreeCacheMBean;
030: import org.jboss.cache.loader.FileCacheLoader; //import org.jboss.ejb3.cache.tree.PassivationEvictionPolicy;
031: import org.jboss.mx.util.MBeanProxy;
032: import org.jboss.system.ServiceMBeanSupport;
033: import org.jboss.system.server.ServerConfig;
034:
035: /**
036: * Comment
037: *
038: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
039: * @version $Revision: 60233 $
040: */
041: public class Tester extends ServiceMBeanSupport implements TesterMBean {
042: public void test() throws Exception {
043: ObjectName cacheON = new ObjectName(
044: "jboss.cache:service=EJB3TreeCache");
045: TreeCacheMBean mbean = (TreeCacheMBean) MBeanProxy.get(
046: TreeCacheMBean.class, cacheON, server);
047: TreeCache cache = (TreeCache) mbean.getInstance();
048: // PassivationEvictionPolicy policy = (PassivationEvictionPolicy) cache.getEvictionPolicy();
049: // policy.createRegion("/mySFSB", 100, 1L);
050:
051: cache.put("/mySFSB/1234", "hello", "world");
052: System.out.println("After PUT");
053: Thread.sleep(5000);
054:
055: System.out.println("WAKE UP!");
056: File fp = new File(System
057: .getProperty(ServerConfig.SERVER_TEMP_DIR)
058: + "/stateful/mySFSB."
059: + FileCacheLoader.DIR_SUFFIX
060: + "/1234." + FileCacheLoader.DIR_SUFFIX);
061: System.out.println("exists in DB: " + fp.exists());
062: if (!fp.exists())
063: throw new RuntimeException("No passivation happened.");
064: System.out.println(cache.get("/mySFSB/1234", "hello"));
065: System.out.println("exists in DB: " + fp.exists());
066: if (fp.exists())
067: throw new RuntimeException(
068: "Should have been removed on activation.");
069: if (cache.exists("/mySFSB/1234")) {
070: cache.remove("/mySFSB/1234");
071: // synchronized (policy)
072: // {
073: // policy.removeRegion("/mySFSB");
074: // }
075: cache.remove("/mySFSB");
076: }
077: }
078:
079: public void testSimpleRemote() throws Exception {
080: SimpleStatefulRemote remote = (SimpleStatefulRemote) new InitialContext()
081: .lookup("SimpleStatefulBean/remote");
082: remote.reset();
083: remote.setState("hello");
084: remote.longRunning();
085: if (!"hello".equals(remote.getState()))
086: throw new RuntimeException("failed state");
087: if (!remote.getPostActivate())
088: throw new RuntimeException("failed to postActivate");
089: if (!remote.getPrePassivate())
090: throw new RuntimeException("failed to prePassivate");
091:
092: }
093:
094: public void testSimpleLocal() throws Exception {
095: SimpleStatefulLocal local = (SimpleStatefulLocal) new InitialContext()
096: .lookup("SimpleStatefulBean/local");
097: local.reset();
098: local.setState("hello");
099: local.longRunning();
100: if (!"hello".equals(local.getState()))
101: throw new RuntimeException("failed state");
102: if (!local.getPostActivate())
103: throw new RuntimeException("failed to postActivate");
104: if (!local.getPrePassivate())
105: throw new RuntimeException("failed to prePassivate");
106:
107: }
108: }
|