1 7 8 package org.jboss.ejb3.test.clusteredsession.unit; 9 10 import org.jboss.test.JBossClusteredTestCase; 11 import org.jboss.ejb3.test.clusteredsession.StatefulRemote; 12 import org.jboss.ejb3.test.clusteredsession.NodeAnswer; 13 14 import javax.naming.Context ; 15 import javax.naming.InitialContext ; 16 import java.util.Date ; 17 import java.util.Properties ; 18 19 import junit.framework.Test; 20 21 27 public class PassivationUnitTestCase extends JBossClusteredTestCase 28 { 29 static boolean deployed = false; 30 public static int test = 0; 31 static Date startDate = new Date (); 32 33 protected final String namingFactory = 34 System.getProperty(Context.INITIAL_CONTEXT_FACTORY); 35 36 protected final String providerURL = 37 System.getProperty(Context.PROVIDER_URL); 38 39 public PassivationUnitTestCase (String name) 40 { 41 super(name); 42 } 43 44 public static Test suite() throws Exception 45 { 46 final String jarName = "clusteredsession-test.jar"; 47 Test t1 = JBossClusteredTestCase.getDeploySetup(PassivationUnitTestCase.class, 48 jarName); 49 return t1; 50 } 51 52 protected InitialContext getInitialContext(int node) throws Exception { 53 String [] urls = getNamingURLs(); 55 Properties env1 = new Properties (); 56 env1.setProperty(Context.INITIAL_CONTEXT_FACTORY, 57 "org.jnp.interfaces.NamingContextFactory"); 58 env1.setProperty(Context.PROVIDER_URL, urls[node]); 59 return new InitialContext (env1); 60 } 61 62 64 public void testStatefulPassivation() 65 throws Exception 66 { 67 log.info("+++ testStatefulPassivation"); 68 69 InitialContext ctx = getInitialContext(0); 71 72 getLog().debug("=================================="); 73 getLog().debug(++PassivationUnitTestCase.test +"- " 74 +"Looking up testStateful..."); 75 StatefulRemote remote = (StatefulRemote) ctx.lookup("testStateful/remote"); 76 77 remote.reset(); 78 remote.setState("hello"); 79 sleep_(11000); 80 assertEquals("hello", remote.getState()); 81 assertEquals(1, remote.getPrePassivate()); 82 assertEquals(1, remote.getPostActivate()); 83 84 sleep_(11000); 85 remote.remove(); 86 87 } 88 89 91 public void XtestFailoverStatefulPassivation() 92 throws Exception 93 { 94 log.info("+++ testFiloverStatefulPassivation"); 95 96 InitialContext ctx = getInitialContext(0); 98 99 getLog().debug("=================================="); 100 getLog().debug(++PassivationUnitTestCase.test +"- " 101 +"Looking up testStateful..."); 102 StatefulRemote stateful = (StatefulRemote) ctx.lookup("testStateful/remote"); 103 stateful.reset(); 104 105 stateful.setName("The Code"); 106 NodeAnswer node1 = stateful.getNodeState (); 107 getLog ().debug ("Node 1 ID: " +node1); 108 109 assertEquals("Counter: ", 1, stateful.increment()); 110 assertEquals("Counter: ", 2, stateful.increment()); 111 sleep_(10000); 112 113 stateful.setUpFailover("once"); 116 NodeAnswer node2 = stateful.getNodeState (); 117 assertNotNull("State node: ", node2); 118 getLog ().debug ("Node 2 ID : " +node2); 119 120 assertNotSame ("No failover has occured!", node1.nodeId, node2.nodeId); 121 122 assertEquals ("Node 1: ", "The Code", node1.answer); 123 assertEquals ("Node 2: ", "The Code", node2.answer); 124 125 stateful.resetActivationCounter(); sleep_(10000); assertEquals("Counter: ", 3, stateful.increment()); 128 assertEquals("Counter: ", 4, stateful.increment()); 129 assertEquals(1, stateful.getPostActivate()); 130 assertEquals(1, stateful.getPrePassivate()); 131 132 stateful.remove(); 133 } 134 135 protected void sleep_(long msec) 136 { 137 try { 138 Thread.sleep(msec); 139 } catch (InterruptedException e) { 140 e.printStackTrace(); 141 } 142 } 143 } 144 | Popular Tags |