Commit 2dd9843d authored by Guillaume Surrel's avatar Guillaume Surrel
Browse files

Add sleep time to let the server start.

Code cleaning.
parent 5da1d809
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2008 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2010 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -20,10 +20,8 @@
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s): Badolle Fabien (ScalAgent D.T.)
*/
package jndi2.nocoupling;
import java.util.Hashtable;
import javax.naming.InitialContext;
......@@ -31,12 +29,12 @@ import javax.naming.NameNotFoundException;
import framework.TestCase;
/**
* Tests: Simple test with 2 servers
* - bind and createsubcontext
* - rebind, unbind, destroysubcontext
*
* <ul>
* <li>bind and createsubcontext</li>
* <li>rebind, unbind, destroysubcontext</li>
* </ul>
*/
public class JndiTest1 extends TestCase {
public static String NAMING_FACTORY_PROP = "java.naming.factory.initial";
......@@ -51,130 +49,124 @@ public class JndiTest1 extends TestCase {
public void run() {
try {
startAgentServer(
(short)0, new String[]{"-DTransaction=fr.dyade.aaa.util.NTransaction"});
startAgentServer(
(short)1, new String[]{"-DTransaction=fr.dyade.aaa.util.NTransaction"});
Hashtable env1 = new Hashtable();
env1.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env1.put(NAMING_HOST_PROP, LOCALHOST);
env1.put(NAMING_PORT_PROP, "16401");
Hashtable env0 = new Hashtable();
env0.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env0.put(NAMING_HOST_PROP, LOCALHOST);
env0.put(NAMING_PORT_PROP, "16400");
InitialContext ctx1 = new InitialContext(env1);
InitialContext ctx0 = new InitialContext(env0);
Exception excp=null;
try{
ctx0.bind("/B","B");
ctx0.createSubcontext("/A");
ctx0.createSubcontext("/A/C");
ctx0.createSubcontext("/A/C/F");
ctx0.createSubcontext("/A/C/U");
ctx0.bind("/A/D","D");
ctx0.bind("/A/E","E");
ctx0.bind("/A/C/G","G");
ctx0.bind("/A/C/F/I","I");
Thread.sleep(10000);
ctx1.bind("/H","H");
ctx1.createSubcontext("/A/C/F/L");
ctx1.createSubcontext("/A/C/F/P");
ctx1.bind("/A/M","M");
ctx1.bind("/A/C/N","N");
ctx1.bind("/A/C/F/L/O","O");
Thread.sleep(10000);
}catch(Exception exc){
excp=exc;
}
assertEquals(null,excp);
// check element is created with lookup method
String look = (String) ctx0.lookup("/A/C/F/L/O");
assertEquals("O",look);
look = (String) ctx0.lookup("/A/C/F/I");
assertEquals("I",look);
look = (String) ctx1.lookup("/A/C/G");
assertEquals("G",look);
look = (String) ctx1.lookup("/A/M");
assertEquals("M",look);
Thread.sleep(6000);
try{
ctx0.rebind("/A/D","D");
ctx1.rebind("/B","B"); // rebind a element bind with ctx0
ctx0.rebind("/H","H"); // rebind a element bind with ctx1
ctx1.rebind("/A/M","M");
}catch(Exception exc){
excp=exc;
}
assertEquals(null,excp);
ctx0.destroySubcontext("/A/C/F/P");
Thread.sleep(6000);
// check context destroy
try{
look=((fr.dyade.aaa.jndi2.client.NamingContextImpl) ctx1.lookup("/A/C/F/P")).getNameInNamespace();
}catch(NameNotFoundException nnfe){
excp=nnfe;
}
assertTrue(excp instanceof NameNotFoundException);
ctx1.destroySubcontext("/A/C/U");
Thread.sleep(6000);
try{
look=((fr.dyade.aaa.jndi2.client.NamingContextImpl) ctx0.lookup("/A/C/U")).getNameInNamespace();
}catch(NameNotFoundException nnfe){
excp=nnfe;
}
assertTrue(excp instanceof NameNotFoundException);
ctx1.unbind("/A/D");
Thread.sleep(6000);
try{
look= (String)ctx0.lookup("/A/D");
}catch(NameNotFoundException nnfe){
excp=nnfe;
}
assertTrue(excp instanceof NameNotFoundException);
ctx0.unbind("/H");
Thread.sleep(6000);
try{
look= (String)ctx1.lookup("/H");
}catch(NameNotFoundException nnfe){
excp=nnfe;
}
assertTrue(excp instanceof NameNotFoundException);
System.out.println("End test1");
} catch (Exception exc) {
exc.printStackTrace();
error(exc);
startAgentServer((short) 0, new String[] { "-DTransaction=fr.dyade.aaa.util.NTransaction" });
startAgentServer((short) 1, new String[] { "-DTransaction=fr.dyade.aaa.util.NTransaction" });
Thread.sleep(2000);
Hashtable env1 = new Hashtable();
env1.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env1.put(NAMING_HOST_PROP, LOCALHOST);
env1.put(NAMING_PORT_PROP, "16401");
Hashtable env0 = new Hashtable();
env0.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env0.put(NAMING_HOST_PROP, LOCALHOST);
env0.put(NAMING_PORT_PROP, "16400");
InitialContext ctx1 = new InitialContext(env1);
InitialContext ctx0 = new InitialContext(env0);
Exception excp = null;
try {
ctx0.bind("/B", "B");
ctx0.createSubcontext("/A");
ctx0.createSubcontext("/A/C");
ctx0.createSubcontext("/A/C/F");
ctx0.createSubcontext("/A/C/U");
ctx0.bind("/A/D", "D");
ctx0.bind("/A/E", "E");
ctx0.bind("/A/C/G", "G");
ctx0.bind("/A/C/F/I", "I");
Thread.sleep(10000);
ctx1.bind("/H", "H");
ctx1.createSubcontext("/A/C/F/L");
ctx1.createSubcontext("/A/C/F/P");
ctx1.bind("/A/M", "M");
ctx1.bind("/A/C/N", "N");
ctx1.bind("/A/C/F/L/O", "O");
Thread.sleep(10000);
} catch (Exception exc) {
excp = exc;
}
assertEquals(null, excp);
// check element is created with lookup method
String look = (String) ctx0.lookup("/A/C/F/L/O");
assertEquals("O", look);
look = (String) ctx0.lookup("/A/C/F/I");
assertEquals("I", look);
look = (String) ctx1.lookup("/A/C/G");
assertEquals("G", look);
look = (String) ctx1.lookup("/A/M");
assertEquals("M", look);
Thread.sleep(6000);
try {
ctx0.rebind("/A/D", "D");
ctx1.rebind("/B", "B"); // rebind a element bind with ctx0
ctx0.rebind("/H", "H"); // rebind a element bind with ctx1
ctx1.rebind("/A/M", "M");
} catch (Exception exc) {
excp = exc;
}
assertEquals(null, excp);
ctx0.destroySubcontext("/A/C/F/P");
Thread.sleep(6000);
// check context destroy
try {
look = ((fr.dyade.aaa.jndi2.client.NamingContextImpl) ctx1.lookup("/A/C/F/P")).getNameInNamespace();
} catch (NameNotFoundException nnfe) {
excp = nnfe;
}
assertTrue(excp instanceof NameNotFoundException);
ctx1.destroySubcontext("/A/C/U");
Thread.sleep(6000);
try {
look = ((fr.dyade.aaa.jndi2.client.NamingContextImpl) ctx0.lookup("/A/C/U")).getNameInNamespace();
} catch (NameNotFoundException nnfe) {
excp = nnfe;
}
assertTrue(excp instanceof NameNotFoundException);
ctx1.unbind("/A/D");
Thread.sleep(6000);
try {
look = (String) ctx0.lookup("/A/D");
} catch (NameNotFoundException nnfe) {
excp = nnfe;
}
assertTrue(excp instanceof NameNotFoundException);
ctx0.unbind("/H");
Thread.sleep(6000);
try {
look = (String) ctx1.lookup("/H");
} catch (NameNotFoundException nnfe) {
excp = nnfe;
}
assertTrue(excp instanceof NameNotFoundException);
System.out.println("End test1");
} catch (Exception exc) {
exc.printStackTrace();
error(exc);
} finally {
stopAgentServer((short)0);
stopAgentServer((short)1);
endTest();
stopAgentServer((short) 0);
stopAgentServer((short) 1);
endTest();
}
}
public static void main(String args[]) {
new JndiTest1().run();
}
public static void main(String args[]) {
new JndiTest1().run();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2009 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2010 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -20,23 +20,21 @@
* Initial developer(s): (ScalAgent D.T.)
* Contributor(s): Badolle Fabien (ScalAgent D.T.)
*/
package jndi2.nocoupling;
import java.util.Hashtable;
import javax.naming.InitialContext;
import framework.TestCase;
/**
* Tests: test with 2 servers
* - start server 0. bind and create subcontext
* - start server 1 and kill server 0
* - lookup with server 1
*
* <ul>
* <li>start server 0. bind and create subcontext</li>
* <li>start server 1 and kill server 0</li>
* <li>lookup with server 1</li>
* </ul>
*/
public class JndiTest2 extends TestCase {
public static String NAMING_FACTORY_PROP = "java.naming.factory.initial";
......@@ -51,54 +49,48 @@ public class JndiTest2 extends TestCase {
public void run() {
try {
startAgentServer(
(short)0, new String[]{"-DTransaction=fr.dyade.aaa.util.NTransaction"});
Hashtable env0 = new Hashtable();
env0.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env0.put(NAMING_HOST_PROP, LOCALHOST);
env0.put(NAMING_PORT_PROP, "16400");
InitialContext ctx0 = new InitialContext(env0);
Exception excp=null;
try{
ctx0.bind("/B","B");
ctx0.createSubcontext("/A");
ctx0.bind("/A/D","D");
Thread.sleep(3000);
}catch(Exception exc){
excp=exc;
}
assertEquals(null,excp);
startAgentServer(
(short)1, new String[]{"-DTransaction=fr.dyade.aaa.util.NTransaction"});
Hashtable env1 = new Hashtable();
env1.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env1.put(NAMING_HOST_PROP, LOCALHOST);
env1.put(NAMING_PORT_PROP, "16401");
InitialContext ctx1 = new InitialContext(env1);
Thread.sleep(5000);
stopAgentServer((short)0);
String look = (String) ctx1.lookup("/B");
assertEquals("B",look);
look = (String) ctx1.lookup("/A/D");
assertEquals("D",look);
System.out.println("End test2");
} catch (Exception exc) {
startAgentServer((short) 0, new String[] { "-DTransaction=fr.dyade.aaa.util.NTransaction" });
Thread.sleep(1000);
Hashtable env0 = new Hashtable();
env0.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env0.put(NAMING_HOST_PROP, LOCALHOST);
env0.put(NAMING_PORT_PROP, "16400");
InitialContext ctx0 = new InitialContext(env0);
Exception excp = null;
try {
ctx0.bind("/B", "B");
ctx0.createSubcontext("/A");
ctx0.bind("/A/D", "D");
Thread.sleep(3000);
} catch (Exception exc) {
excp = exc;
}
assertEquals(null, excp);
startAgentServer((short) 1, new String[] { "-DTransaction=fr.dyade.aaa.util.NTransaction" });
Hashtable env1 = new Hashtable();
env1.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env1.put(NAMING_HOST_PROP, LOCALHOST);
env1.put(NAMING_PORT_PROP, "16401");
InitialContext ctx1 = new InitialContext(env1);
Thread.sleep(5000);
stopAgentServer((short) 0);
String look = (String) ctx1.lookup("/B");
assertEquals("B", look);
look = (String) ctx1.lookup("/A/D");
assertEquals("D", look);
System.out.println("End test2");
} catch (Exception exc) {
exc.printStackTrace();
error(exc);
// In case the exception occurred before stopping the server 0
......@@ -108,8 +100,8 @@ public class JndiTest2 extends TestCase {
endTest();
}
}
public static void main(String args[]) {
new JndiTest2().run();
new JndiTest2().run();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2010 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -20,9 +20,7 @@
* Initial developer(s): (ScalAgent D.T.)
* Contributor(s): Badolle Fabien (ScalAgent D.T.)
*/
package jndi2.nocoupling;
package jndi2.nocoupling;
import java.util.Hashtable;
......@@ -30,11 +28,8 @@ import javax.naming.InitialContext;
import framework.TestCase;
/**
* Tests:
* - bind and createsobcontext with a no master server
*
* Tests: - bind and create subcontext with a no master server
*/
public class JndiTest3 extends TestCase {
public static String NAMING_FACTORY_PROP = "java.naming.factory.initial";
......@@ -50,39 +45,40 @@ public class JndiTest3 extends TestCase {
public void run() {
try {
startAgentServer(
(short)2, new String[]{"-DTransaction=fr.dyade.aaa.util.NTransaction"});
Hashtable env1 = new Hashtable();
env1.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env1.put(NAMING_HOST_PROP, LOCALHOST);
env1.put(NAMING_PORT_PROP, "16402");
InitialContext ctx1 = new InitialContext(env1);
Exception excp=null;
try{
Thread.sleep(3000);
ctx1.bind("/U","U");
ctx1.createSubcontext("/A");
ctx1.bind("/A/W","W");
}catch(Exception exc){
excp=exc;
}
assertEquals(null,excp);
System.out.println("End test3");
} catch (Exception exc) {
exc.printStackTrace();
error(exc);
startAgentServer((short) 2, new String[] { "-DTransaction=fr.dyade.aaa.util.NTransaction" });
Thread.sleep(1000);
Hashtable env1 = new Hashtable();
env1.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env1.put(NAMING_HOST_PROP, LOCALHOST);
env1.put(NAMING_PORT_PROP, "16402");
InitialContext ctx1 = new InitialContext(env1);
Exception excp = null;
try {
Thread.sleep(3000);
ctx1.bind("/U", "U");
ctx1.createSubcontext("/A");
ctx1.bind("/A/W", "W");
} catch (Exception exc) {
excp = exc;
}
assertEquals(null, excp);
System.out.println("End test3");
} catch (Exception exc) {
exc.printStackTrace();
error(exc);
} finally {
stopAgentServer((short)2);
endTest();
stopAgentServer((short) 2);
endTest();
}
}
public static void main(String args[]) {
new JndiTest3().run();
}
public static void main(String args[]) {
new JndiTest3().run();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2010 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -20,7 +20,6 @@
* Initial developer(s): (ScalAgent D.T.)
* Contributor(s): Badolle Fabien (ScalAgent D.T.)
*/
package jndi2.nocoupling;
import java.util.Hashtable;
......@@ -31,14 +30,16 @@ import javax.naming.NamingEnumeration;
import framework.TestCase;
/**
* Tests: Simple test with 2 servers
* - bind and createsubcontext
* - rebind, unbind, destroysubcontext
*
* <ul>
* <li>bind and create subcontext</li>
* <li>rebind, unbind, destroy subcontext
* <li>
* </ul>
*/
public class JndiTest4 extends TestCase {
public static String NAMING_FACTORY_PROP = "java.naming.factory.initial";
public static String NAMING_FACTORY = "fr.dyade.aaa.jndi2.client.NamingContextFactory";
public static String NAMING_HOST_PROP = "java.naming.factory.host";
......@@ -51,99 +52,97 @@ public class JndiTest4 extends TestCase {
public void run() {
try {
startAgentServer(
(short)0, new String[]{"-DTransaction=fr.dyade.aaa.util.NTransaction"});
startAgentServer(
(short)1, new String[]{"-DTransaction=fr.dyade.aaa.util.NTransaction"});
startAgentServer(
(short)2, new String[]{"-DTransaction=fr.dyade.aaa.util.NTransaction"});
Hashtable env1 = new Hashtable();
env1.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env1.put(NAMING_HOST_PROP, LOCALHOST);
env1.put(NAMING_PORT_PROP, "16401");
Hashtable env0 = new Hashtable();
env0.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env0.put(NAMING_HOST_PROP, LOCALHOST);
env0.put(NAMING_PORT_PROP, "16400");
Hashtable env2 = new Hashtable();
env2.put(NAMING_FACTORY_PROP, NAMING_FACTORY);
env2.put(NAMING_HOST_PROP, LOCALHOST);
env2.put(NAMING_PORT_PROP, "16402");
InitialContext ctx1 = new InitialContext(env1);
InitialContext ctx0 = new InitialContext(env0);
InitialContext ctx2 = new InitialContext(env2);
Exception excp=null;
try{
ctx0.bind("/B","B");
// ctx0.bind("/C","C");
// ctx0.bind("/D","D");
// ctx0.createSubcontext("/A");
// ctx0.bind("/A/C","C");
Thread.sleep(2000);
ctx1.bind("/D","D");
// ctx1.createSubcontext("/A/E");
// ctx1.bind("/A/E/S","S");
Thread