Commit 48e3ed27 authored by afreyssin's avatar afreyssin

Adds reconf.Test9, noreg.test58 and dmq.TestDmq7:

 - Successively adds stopped servers.
 - Verify that the use of bad destination identifier no longer block the MOM.
 - Verify that a message recv from DMQ can be correctly used anew.
parent c06cd181
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 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
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s):Badolle Fabien (ScalAgent D.T.)
* Contributor(s):
*/
package joram.dmq;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.Topic;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.User;
import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
import framework.TestCase;
/**
* Test : Set 2 specifics DMQs, one for queue and another for user.
* Set threshold either for queue and user, verify that messages are
* well forwarded to the right DMQ.
* Send anew the message and verify that the threshold mechanism works.
*
*/
public class TestDmq7 extends TestCase {
public static void main(String[] args) {
new TestDmq7().run();
}
public void run() {
try {
System.out.println("server start");
startAgentServer((short)0);
// open an administration connection
AdminModule.connect("localhost", 2560, "root", "root", 60);
// create a Queue
Queue queue =Queue.create("queue");
Topic topic = Topic.create("topic");
Queue dmq = Queue.create("dmq");
// create a user
User user = User.create("anonymous", "anonymous");
// set permissions
queue.setFreeReading();
queue.setFreeWriting();
topic.setFreeReading();
topic.setFreeWriting();
queue.setDMQId(dmq.getName());
queue.setThreshold(2);
user.setDMQId(dmq.getName());
user.setThreshold(2);
dmq.setFreeReading();
dmq.setFreeWriting();
org.objectweb.joram.client.jms.admin.AdminModule.disconnect();
System.out.println("admin config ok");
ConnectionFactory cf = TcpConnectionFactory.create("localhost", 2560);
// creates connection, session, messages producers and consumers needed
// for tests.
Connection cnx = cf.createConnection();
Session session1 = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session1.createProducer(null);
Session session2 = cnx.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons_queue = session2.createConsumer(queue);
MessageConsumer cons_topic= session2.createConsumer(topic);
cnx.start();
// Creates connection, session and messages consumer needed to read messages
// from dmq.
Connection cnx_dmq = cf.createConnection();
Session session_dmq = cnx_dmq.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons_dmq = session_dmq.createConsumer(dmq);
cnx_dmq.start();
// Part 1 - Test the Queue.
// create a text message and send it to the queue
TextMessage msg1 = session1.createTextMessage("test to queue");
producer.send(queue, msg1);
System.out.println("msg sent: " + msg1.getJMSMessageID());
// read the message and rollback it x2
TextMessage msg2 = (TextMessage) cons_queue.receive();
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
System.out.println("msg recv and rollback #1: " + msg2.getJMSMessageID());
session2.rollback();
msg2 = (TextMessage) cons_queue.receive();
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
System.out.println("msg recv and rollback #2: " + msg2.getJMSMessageID());
session2.rollback();
// read the message on the DMQ
msg2 = (TextMessage) cons_dmq.receive();
System.out.println("msg recv on dmq: " + msg2.getJMSMessageID());
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
// send anew the message on the queue
msg1 = msg2;
producer.send(queue, msg1);
System.out.println("msg sent #2: " + msg1.getJMSMessageID() + " -> " + msg1.getIntProperty("JMSXDeliveryCount"));
// read the message and rollback it x2
msg2 = (TextMessage) cons_queue.receive();
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
System.out.println("msg recv and rollback #3: " + msg2.getJMSMessageID());
session2.rollback();
msg2 = (TextMessage) cons_queue.receive();
System.out.println("msg recv and rollback #4: " + msg2.getJMSMessageID());
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
session2.rollback();
// Then verify that it is correctly sent to the dmq
msg2 = (TextMessage) cons_dmq.receive();
System.out.println("msg recv on dmq #2: " + msg2.getJMSMessageID());
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
// Part 2 - Test the Topic.
// create a text message and send it to the queue
msg1 = session1.createTextMessage("test to topic");
producer.send(topic, msg1);
System.out.println("msg sent: " + msg1.getJMSMessageID());
// read the message and rollback it x2
msg2 = (TextMessage) cons_topic.receive();
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
System.out.println("msg recv and rollback #1: " + msg2.getJMSMessageID());
session2.rollback();
msg2 = (TextMessage) cons_topic.receive();
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
System.out.println("msg recv and rollback #2: " + msg2.getJMSMessageID());
session2.rollback();
// read the message on the DMQ
msg2 = (TextMessage) cons_dmq.receive();
System.out.println("msg recv on dmq: " + msg2.getJMSMessageID());
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
// send anew the message on the queue
msg1 = msg2;
producer.send(topic, msg1);
System.out.println("msg sent #2: " + msg1.getJMSMessageID() + " -> " + msg1.getIntProperty("JMSXDeliveryCount"));
// read the message and rollback it x2
msg2 = (TextMessage) cons_topic.receive();
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
System.out.println("msg recv and rollback #3: " + msg2.getJMSMessageID());
session2.rollback();
msg2 = (TextMessage) cons_topic.receive();
System.out.println("msg recv and rollback #4: " + msg2.getJMSMessageID());
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
session2.rollback();
// Then verify that it is correctly sent to the dmq
msg2 = (TextMessage) cons_dmq.receive();
System.out.println("msg recv on dmq #2: " + msg2.getJMSMessageID());
assertTrue("bad message id", (msg1.getJMSMessageID().equals(msg2.getJMSMessageID())));
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
System.out.println("Server stop ");
stopAgentServer((short)0);
endTest();
}
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2008 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
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package joram.noreg;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.InvalidDestinationException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.QueueBrowser;
import javax.jms.Session;
import javax.jms.TopicSubscriber;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.Topic;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.User;
import framework.TestCase;
/**
* Try to build a producers and consumers with bad queue or topic.
* The client should get an exception and the server should continue to work.
*/
public class Test58 extends BaseTest {
public static void main(String[] args) throws Exception {
new Test58().run(args);
}
public void run(String[] args) {
try{
writeIntoFile("===================== start test 58 =====================");
TestCase.startAgentServer((short)0);
ConnectionFactory cf = TcpBaseTest.createConnectionFactory();
AdminModule.connect(cf);
User user = User.create("anonymous", "anonymous", 0);
AdminModule.disconnect();
Connection cnx = cf.createConnection();
Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic1 = new Topic();
try {
MessageConsumer cons = sess.createConsumer(topic1);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().equals("Undefined (null) destination identifier."));
}
try {
MessageProducer prod = sess.createProducer(topic1);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().equals("Undefined (null) destination identifier."));
}
try {
TopicSubscriber sub = sess.createDurableSubscriber(topic1, "sub");
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().equals("Undefined (null) destination identifier."));
}
Topic topic2 = new Topic("#0.0-1025");
try {
MessageConsumer cons = sess.createConsumer(topic2);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().startsWith("Bad destination identifier:"));
}
try {
MessageProducer prod = sess.createProducer(topic2);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().startsWith("Bad destination identifier:"));
}
try {
TopicSubscriber sub = sess.createDurableSubscriber(topic2, "sub");
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().startsWith("Bad destination identifier:"));
}
Queue queue1 = new Queue();
try {
MessageConsumer cons = sess.createConsumer(queue1);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().equals("Undefined (null) destination identifier."));
}
try {
MessageProducer prod = sess.createProducer(queue1);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().equals("Undefined (null) destination identifier."));
}
try {
QueueBrowser browser = sess.createBrowser(queue1);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().equals("Undefined (null) destination identifier."));
}
Queue queue2 = new Queue("#0.0-1025");
try {
MessageConsumer cons = sess.createConsumer(queue2);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().startsWith("Bad destination identifier:"));
}
try {
MessageProducer prod = sess.createProducer(queue2);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().startsWith("Bad destination identifier:"));
}
try {
QueueBrowser browser = sess.createBrowser(queue2);
assertTrue("unreachable", false);
} catch (JMSException exc) {
assertTrue("Bad exception: " + exc, exc instanceof InvalidDestinationException);
assertTrue("Bad exception's message: " + exc.getMessage(),
exc.getMessage().startsWith("Bad destination identifier:"));
}
cnx.start();
sess.close();
cnx.close();
} catch (JMSException exc) {
exc.printStackTrace();
assertTrue("Bad exception message",
exc.getMessage().equals("Cannot subscribe to an undefined topic (null)."));
} catch(Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
TestCase.stopAgentServer((short)0);
endTest();
}
System.exit(0);
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2009 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
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package joram.reconf;
import java.io.File;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.User;
/**
* Tests basic server reconfiguration: 2 initial servers in a domain
* - Successively adds N server in the domain D0.
*
* - Adds a third server (S3) in the domain D0, then removes it.
* - Removes S2 and the useless dommain (D0).
*
* This test works with classic networks: SimpleNetwork, PoolNetwork, etc.
*/
public class ReconfTest9 extends ReconfTestBase {
public static void main(String[] args) {
new ReconfTest9().run();
}
public void run() {
try {
startAgentServer((short) 0, (File) null, new String[0]);
startAgentServer((short) 1, (File) null, new String[0]);
Thread.sleep(1000L);
AdminModule.connect("localhost", 2560, "root", "root", 60);
User.create("anonymous", "anonymous", 0);
checkQueue((short) 0);
checkQueue((short) 1);
long start, end;
for (int i=2; i<20; i++) {
start = System.currentTimeMillis();
AdminModule.addServer(i, "localhost", "D0", 17771 + i, "s" + i);
deployAgentServer((short) i, "./s" + i);
end = System.currentTimeMillis();
System.out.println("Adds server#" + i + "-> " + (end - start));
}
// start = System.currentTimeMillis();
// for (int i=2; i<10; i++) {
// startAgentServer((short) i, new File("./s" + i), new String[0]);
// }
// end = System.currentTimeMillis();
// System.out.println("starts servers -> " + (end - start));
//
// for (int i=0; i<10; i++) {
// start = System.currentTimeMillis();
// checkQueue((short) i);
// end = System.currentTimeMillis();
//
// System.out.println("checkQueue#" + i + "-> " + (end - start));
// }
//
// for (int i=2; i<10; i++) {
// // First stop the server because it must be reachable in order to be stopped.
// AdminModule.stopServer(i);
// // Then clean the configuration: the server is not reachable anymore.
// AdminModule.removeServer(i);
// }
//
// checkQueue((short) 0);
// checkQueue((short) 1);
//
// for (int i=2; i<10; i++) {
// start = System.currentTimeMillis();
// AdminModule.addServer(i, "localhost", "D0", 17771 + i, "s" + i);
// deployAgentServer((short) i, "./s" + i);
// end = System.currentTimeMillis();
//
// startAgentServer((short) i, new File("./s" + i), new String[0]);
// System.out.println("Adds server#" + i + "-> " + (end - start));
// }
//
// for (int i=0; i<10; i++) {
// start = System.currentTimeMillis();
// checkQueue((short) i);
// end = System.currentTimeMillis();
//
// System.out.println("checkQueue#" + i + "-> " + (end - start));
// }
//
// for (int i=2; i<10; i++) {
// // First stop the server because it must be reachable in order to be stopped.
// AdminModule.stopServer(i);
// // Then clean the configuration: the server is not reachable anymore.
// AdminModule.removeServer(i);
// }
//
// checkQueue((short) 1);
//
//
//
//
//// AdminModule.addServer(3, "localhost", "D0", 17773, "./s3");
//// deployAgentServer((short) 3, "s3");
//// startAgentServer((short) 3, new File("./s3"), new String[0]);
////
//// checkQueue((short) 3);
//// checkQueue((short) 1);
////
//// // First stop the server because it must be reachable in order to be stopped.
//// AdminModule.stopServer(3);
//// // Then clean the configuration: the server is not reachable anymore.
//// AdminModule.removeServer(3);
////
//// checkQueue((short) 1);
//
AdminModule.stopServer(1);
AdminModule.removeServer(1);
// AdminModule.removeDomain("D0");
checkQueue((short) 0);
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
System.out.println("Stop server s0");
stopAgentServer((short) 0);
endTest();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment