Methods Summary |
---|
protected void | _sleep(long time)
try {
Thread.sleep(time);
} catch (InterruptedException e) {
e.printStackTrace();
}
|
private void | basicTest(java.lang.String jndiBinding)
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "
+"Trying the context...");
// Connect to the server0 JNDI
InitialContext ctx = getInitialContext(0);
getLog().debug("Basic Test with " + jndiBinding);
getLog().debug("==================================");
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "
+"Looking up " + jndiBinding + "...");
StatefulRemote stateful = (StatefulRemote) ctx.lookup(jndiBinding);
stateful.setName("The Code");
_sleep(300);
NodeAnswer node1 = stateful.getNodeState ();
getLog ().debug ("Node 1 ID: " +node1);
assertEquals("Counter: ", 1, stateful.increment());
assertEquals("Counter: ", 2, stateful.increment());
stateful.remove();
getLog().debug("ok");
|
protected javax.naming.InitialContext | getInitialContext(int node)
// Connect to the server0 JNDI
String[] urls = getNamingURLs();
Properties env1 = new Properties();
env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env1.setProperty(Context.PROVIDER_URL, urls[node]);
return new InitialContext(env1);
|
private void | statefulBeanCounterFailoverTest(java.lang.String jndiBinding)
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "+"Trying the context...");
// Connect to the server0 JNDI
InitialContext ctx = getInitialContext(0);
getLog().debug("Test Stateful Bean Counter Failover with " + jndiBinding);
getLog().debug("=========================================================");
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "
+"Looking up " + jndiBinding + "...");
StatefulRemote stateful = (StatefulRemote) ctx.lookup(jndiBinding);
stateful.setName("The Code");
NodeAnswer node1 = stateful.getNodeState ();
getLog ().debug ("Node 1 ID: " +node1);
assertEquals("Counter: ", 1, stateful.increment());
assertEquals("Counter: ", 2, stateful.increment());
_sleep(300);
// Now we switch to the other node, simulating a failure on node 1
//
stateful.setUpFailover("once");
NodeAnswer node2 = stateful.getNodeState ();
assertNotNull("State node: ", node2);
getLog ().debug ("Node 2 ID : " +node2);
assertFalse("Failover has occured", node1.nodeId.equals(node2.nodeId));
assertEquals ("Node 1: ", "The Code", node1.answer);
assertEquals ("Node 2: ", "The Code", node2.answer);
assertEquals("Counter: ", 3, stateful.increment());
assertEquals("Counter: ", 4, stateful.increment());
stateful.remove();
getLog().debug("ok");
|
private void | statefulBeanFailoverTest(java.lang.String jndiBinding)
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "+"Trying the context...");
// Connect to the server0 JNDI
InitialContext ctx = getInitialContext(0);
getLog().debug("Test Stateful Bean Failover with " + jndiBinding);
getLog().debug("================================================");
getLog().debug(++org.jboss.ejb3.test.clusteredsession.unit.BeanUnitTestCase.test +"- "
+"Looking up " + jndiBinding + "...");
StatefulRemote stateful = (StatefulRemote) ctx.lookup(jndiBinding);
stateful.setName("Bupple-Dupple");
_sleep(300);
NodeAnswer node1 = stateful.getNodeState ();
getLog ().debug ("Node 1 ID: " +node1);
// Now we switch to the other node, simulating a failure on node 1
//
stateful.setUpFailover("once");
NodeAnswer node2 = stateful.getNodeState ();
assertNotNull("State node: ", node2);
getLog ().debug ("Node 2 ID : " +node2);
assertFalse("Failover has occured", node1.nodeId.equals(node2.nodeId));
assertEquals ("Node 1: ", "Bupple-Dupple", node1.answer);
assertEquals ("Node 2: ", "Bupple-Dupple", node2.answer);
// we change our name to see if it replicates to node 1
//
stateful.setName ("Changed");
_sleep(300);
// now we travel back on node 1
//
stateful.setUpFailover("once");
node1 = stateful.getNodeState ();
assertNotNull("State node id should not be null: ", node1.nodeId);
getLog ().debug (node1);
_sleep(300);
assertNotSame ("No failover has occured!", node1.nodeId, node2.nodeId);
assertEquals ("Value is not identical on replicated node", "Changed", node1.answer );
stateful.remove();
getLog().debug("ok");
|
public static junit.framework.Test | suite()
final String jarName = "clusteredsession-test.jar";
Test t1 = JBossClusteredTestCase.getDeploySetup(BeanUnitTestCase.class,
jarName);
return t1;
|
public void | testBasic()
basicTest("testStateful/remote");
|
public void | testBasicWithEjbJarXMLOverride()
basicTest("EjbJarOverrideAnnotationStateful/remote");
|
public void | testBasicWithXMLOverride()
basicTest("OverrideAnnotationStateful/remote");
|
public void | testBasicWithoutAnnotation()
basicTest("NonAnnotationStateful/remote");
|
public void | testStatefulBeanCounterFailover()
statefulBeanCounterFailoverTest("testStateful/remote");
|
public void | testStatefulBeanCounterFailoverWithEjbJarXMLOverride()
statefulBeanCounterFailoverTest("EjbJarOverrideAnnotationStateful/remote");
|
public void | testStatefulBeanCounterFailoverWithXMLOverride()
statefulBeanCounterFailoverTest("OverrideAnnotationStateful/remote");
|
public void | testStatefulBeanCounterFailoverWithoutAnnotation()
statefulBeanCounterFailoverTest("NonAnnotationStateful/remote");
|
public void | testStatefulBeanFailover()
statefulBeanFailoverTest("testStateful/remote");
|
public void | testStatefulBeanFailoverWithEjbJarXMLOverride()
statefulBeanFailoverTest("EjbJarOverrideAnnotationStateful/remote");
|
public void | testStatefulBeanFailoverWithXMLOverride()
statefulBeanFailoverTest("OverrideAnnotationStateful/remote");
|
public void | testStatefulBeanFailoverWithoutAnnotation()
statefulBeanFailoverTest("NonAnnotationStateful/remote");
|