Commit 253dca97 authored by afreyssin's avatar afreyssin

Fit to new Joram administration API.

parent db9052e4
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2006 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2006 - 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
......@@ -40,6 +40,7 @@ import javax.naming.InitialContext;
import joram.framework.TestCase;
import org.objectweb.joram.client.jms.Destination;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.DeadMQueue;
import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
......@@ -128,21 +129,19 @@ public class AdminTest1 extends TestCase {
connection.start();
List destinations = AdminModule.getDestinations(0);
Destination[] destinations = AdminModule.getDestinations(0);
System.out.println("destinations=" + destinations);
assertTrue("Wrong destinations count (" + destinations.size() + ')',
destinations.size() == 5);
assertTrue("Wrong destinations count (" + destinations.length + ')', destinations.length == 5);
boolean topicFound = false;
boolean queueFound = false;
boolean tmpTopicFound = false;
boolean tmpQueueFound = false;
boolean deadMQueueFound = false;
for (int i = 0; i < destinations.size(); i++) {
org.objectweb.joram.client.jms.Destination dest =
(org.objectweb.joram.client.jms.Destination)destinations.get(i);
for (int i = 0; i < destinations.length; i++) {
Destination dest = destinations[i];
if (dest.getAdminName().equals("queue")) {
assertTrue(
"Wrong queue type: " + dest,
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 ScalAgent Distributed Technologies
* Copyright (C) 2007 - 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
......@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s):Badolle Fabien (ScalAgent D.T.)
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package joram.base;
......@@ -33,6 +33,8 @@ import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.objectweb.joram.client.jms.admin.AdminModule;
import joram.framework.TestCase;
......@@ -43,106 +45,101 @@ import joram.framework.TestCase;
*/
public class Test_Temp_T2 extends TestCase {
static Topic adminTopic= null;
public static void main(String[] args) {
new Test_Temp_T2().run();
}
public void run() {
try {
System.out.println("server start");
startAgentServer((short)0);
admin();
System.out.println("admin config ok");
Context ictx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
ictx.close();
Connection cnx = cf.createConnection();
org.objectweb.joram.client.jms.admin.AdminModule.connect("localhost", 2560,
"root", "root", 60);
List<Destination> destinations = org.objectweb.joram.client.jms.admin.AdminModule.getDestinations();
TemporaryTopic topic = (TemporaryTopic)destinations.get(0);
adminTopic=topic;
// temporary topic is creating by a session
cnx.start();
Session sessionp = cnx.createSession(false,
Session.AUTO_ACKNOWLEDGE);
TemporaryTopic temptopic = sessionp.createTemporaryTopic();
cnx.close();
testTempTopic();
cnx = cf.createConnection();
cnx.start();
sessionp = cnx.createSession(false,
Session.AUTO_ACKNOWLEDGE);
temptopic = sessionp.createTemporaryTopic();
TemporaryTopic temptopic1 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic2 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic3 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic4 = sessionp.createTemporaryTopic();
cnx.close();
testTempTopic();
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
System.out.println("Server stop ");
stopAgentServer((short)0);
endTest();
}
}
/**
* Admin : Create a user anonymous
* use jndi
*/
public void admin() throws Exception {
// conexion
org.objectweb.joram.client.jms.admin.AdminModule.connect("localhost", 2560,
"root", "root", 60);
// create a user
org.objectweb.joram.client.jms.admin.User user =
org.objectweb.joram.client.jms.admin.User.create("anonymous", "anonymous");
javax.jms.ConnectionFactory cf =
org.objectweb.joram.client.jms.tcp.TcpConnectionFactory.create("localhost", 2560);
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
jndiCtx.bind("cf", cf);
jndiCtx.close();
org.objectweb.joram.client.jms.admin.AdminModule.disconnect();
static Topic adminTopic= null;
public static void main(String[] args) {
new Test_Temp_T2().run();
}
public void run() {
try {
System.out.println("server start");
startAgentServer((short)0);
admin();
System.out.println("admin config ok");
Context ictx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
ictx.close();
Connection cnx = cf.createConnection();
org.objectweb.joram.client.jms.admin.AdminModule.connect("localhost", 2560, "root", "root", 60);
Destination[] destinations = AdminModule.getDestinations();
TemporaryTopic topic = (TemporaryTopic) destinations[0];
adminTopic=topic;
// temporary topic is creating by a session
cnx.start();
Session sessionp = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryTopic temptopic = sessionp.createTemporaryTopic();
cnx.close();
testTempTopic();
cnx = cf.createConnection();
cnx.start();
sessionp = cnx.createSession(false,
Session.AUTO_ACKNOWLEDGE);
temptopic = sessionp.createTemporaryTopic();
TemporaryTopic temptopic1 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic2 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic3 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic4 = sessionp.createTemporaryTopic();
cnx.close();
testTempTopic();
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
System.out.println("Server stop ");
stopAgentServer((short)0);
endTest();
}
private static void testTempTopic() throws Exception{
int j=0;
List<Destination> destinations =org.objectweb.joram.client.jms.admin.AdminModule.getDestinations();
for (Destination destination : destinations) {
j++;
TemporaryTopic topic = (TemporaryTopic)destination;
assertEquals(adminTopic,topic);
}
assertEquals(1,j);
}
/**
* Admin : Create a user anonymous
* use jndi
*/
public void admin() throws Exception {
// conexion
org.objectweb.joram.client.jms.admin.AdminModule.connect("localhost", 2560, "root", "root", 60);
// create a user
org.objectweb.joram.client.jms.admin.User user =
org.objectweb.joram.client.jms.admin.User.create("anonymous", "anonymous");
javax.jms.ConnectionFactory cf =
org.objectweb.joram.client.jms.tcp.TcpConnectionFactory.create("localhost", 2560);
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
jndiCtx.bind("cf", cf);
jndiCtx.close();
org.objectweb.joram.client.jms.admin.AdminModule.disconnect();
}
private static void testTempTopic() throws Exception{
int j=0;
Destination[] destinations = AdminModule.getDestinations();
for (Destination destination : destinations) {
j++;
TemporaryTopic topic = (TemporaryTopic)destination;
assertEquals(adminTopic,topic);
}
assertEquals(1,j);
}
}
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 ScalAgent Distributed Technologies
* Copyright (C) 2007 - 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
......@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s):Badolle Fabien (ScalAgent D.T.)
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package joram.dmq;
......@@ -50,9 +50,9 @@ public class TestDmq6 extends TestCase {
System.out.println("admin ok");
// check
List liste = AdminModule.getDestinations();
for(int i = 0;i < liste.size(); i++){
Destination dest = (Destination)liste.get(i);
Destination[] list1 = AdminModule.getDestinations();
for(int i = 0;i < list1.length; i++){
Destination dest = list1[i];
if(dest.getType().equals("queue")){
assertTrue( dest.isFreelyWriteable() );
......@@ -85,9 +85,9 @@ public class TestDmq6 extends TestCase {
assertTrue(dmq1);
liste = AdminModule.getUsers();
for(int i = 0;i < liste.size();i++){
User user = (User)liste.get(i);
User[] list2 = AdminModule.getUsers();
for(int i = 0;i < list2.length;i++){
User user = list2[i];
if(user.getName().equals("anonymous")){
assertEquals(2,user.getThreshold());
}
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2005 - 2008 ScalAgent Distributed Technologies
* Copyright (C) 2005 - 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
......@@ -23,7 +23,6 @@
package joram.ha;
import java.io.File;
import java.util.Vector;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
......@@ -33,7 +32,6 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import org.objectweb.joram.client.jms.admin.User;
import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
import org.objectweb.joram.client.jms.ha.tcp.HATcpConnectionFactory;
import org.objectweb.joram.client.jms.Queue;
......@@ -69,14 +67,15 @@ public class HATest extends TestCase {
Thread.sleep(1000);
AdminModule.connect("localhost", 2560, "root", "root", 60);
User user = User.create("anonymous", "anonymous", 0);
ConnectionFactory cf = HATcpConnectionFactory.create("hajoram://localhost:2560,localhost:2561,localhost:2562");
((HATcpConnectionFactory) cf).getParameters().cnxPendingTimer = 500;
((HATcpConnectionFactory) cf).getParameters().connectingTimer = 30;
AdminModule.connect(cf, "root", "root");
// AdminModule.connect("localhost", 2560, "root", "root", 60);
User user = User.create("anonymous", "anonymous", 0);
Queue queue = Queue.create(0, "queue");
queue.setFreeReading();
queue.setFreeWriting();
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2006 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2006 - 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
......@@ -17,14 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Feliot David (ScalAgent D.T.)
* Contributor(s): Badolle Fabien (ScalAgent D.T.)
*/
/*
* Created on 27 avr. 2006
*
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package joram.local;
......@@ -39,7 +33,10 @@ import javax.jms.TextMessage;
import joram.framework.TestCase;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.User;
import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
/**
......@@ -51,29 +48,29 @@ import org.objectweb.joram.client.jms.admin.AdminModule;
*
*/
public class CommitTest extends TestCase {
public static void main(String[] args) {
new CommitTest().run();
}
private void startServers() throws Exception {
System.out.println("start server 0");
startAgentServer(
(short)0, (File)null,
new String[]{
"-DTransaction=fr.dyade.aaa.util.NTransaction"});
(short)0, (File)null,
new String[]{
"-DTransaction=fr.dyade.aaa.util.NTransaction"});
System.out.println("start server 1");
startAgentServer(
(short)1, (File)null,
new String[]{
"-DTransaction=fr.dyade.aaa.util.NTransaction"});
(short)1, (File)null,
new String[]{
"-DTransaction=fr.dyade.aaa.util.NTransaction"});
Thread.sleep(2000);
}
public void run() {
try {
startServers();
......@@ -81,84 +78,79 @@ public class CommitTest extends TestCase {
AdminModule.connect("localhost", 2560,
"root", "root", 60);
org.objectweb.joram.client.jms.admin.User user =
org.objectweb.joram.client.jms.admin.User.create(
"anonymous", "anonymous", 0);
User user = User.create("anonymous", "anonymous", 0);
org.objectweb.joram.client.jms.Queue localQueue =
org.objectweb.joram.client.jms.Queue.create(0);
Queue localQueue = Queue.create(0);
localQueue.setFreeReading();
localQueue.setFreeWriting();
org.objectweb.joram.client.jms.Topic localTopic =
org.objectweb.joram.client.jms.Topic.create(0);
localTopic.setFreeReading();
localTopic.setFreeWriting();
org.objectweb.joram.client.jms.Queue remoteQueue =
org.objectweb.joram.client.jms.Queue.create(1);
Queue remoteQueue = Queue.create(1);
remoteQueue.setFreeReading();
remoteQueue.setFreeWriting();
org.objectweb.joram.client.jms.Topic remoteTopic =
org.objectweb.joram.client.jms.Topic.create(1);
remoteTopic.setFreeReading();
remoteTopic.setFreeWriting();
ConnectionFactory cf = org.objectweb.joram.client.jms.tcp.TcpConnectionFactory.create(
"localhost", 2560);
ConnectionFactory cf = TcpConnectionFactory.create("localhost", 2560);
Connection c = cf.createConnection();
Session s = c.createSession(true, 0);
MessageProducer lqp = s.createProducer(localQueue);
MessageConsumer lqc = s.createConsumer(localQueue);
MessageProducer ltp = s.createProducer(localTopic);
MessageConsumer ltc = s.createDurableSubscriber(localTopic, "ltc");
MessageProducer rqp = s.createProducer(remoteQueue);
MessageConsumer rqc = s.createConsumer(remoteQueue);
MessageProducer rtp = s.createProducer(remoteTopic);
MessageConsumer rtc = s.createDurableSubscriber(remoteTopic, "rtc");
System.out.println("Start test");
c.start();
// Producing towards remote destinations: no local replies
rqp.send(s.createTextMessage("rq1"));
rtp.send(s.createTextMessage("rt1"));
System.out.println("Commit 1");
s.commit();
// Consuming from topics: no local replies
TextMessage tm = (TextMessage)rtc.receive();
System.out.println("Commit 2");
s.commit();
// Consuming from remote queues: no local replies
tm = (TextMessage)rqc.receive();
System.out.println("Commit 3");
s.commit();
// Producing towards local topic: local reply
ltp.send(s.createTextMessage("lt1"));
System.out.println("Commit 4");
s.commit();
// Consuming from local topic: no local reply
tm = (TextMessage)ltc.receive();
System.out.println("Commit 5");
s.commit();
// Producing towards local queue: local reply
ltp.send(s.createTextMessage("lq1"));
System.out.println("Commit 6");
s.commit();
// Consuming from local queue: no local reply (from ack)
tm = (TextMessage)ltc.receive();
System.out.println("Commit 7");
s.commit();
// Mixing everything
rqp.send(s.createTextMessage("rq2"));
rtp.send(s.createTextMessage("rt2"));
......@@ -166,7 +158,7 @@ public class CommitTest extends TestCase {
lqp.send(s.createTextMessage("lq2"));
System.out.println("Commit 8");
s.commit();
System.out.println(" -> receive rt2");
tm = (TextMessage)rtc.receive();
System.out.println(" -> receive rq2");
......@@ -181,46 +173,46 @@ public class CommitTest extends TestCase {
lqp.send(s.createTextMessage("lq3"));
System.out.println("Commit 9");
s.commit();
tm = (TextMessage)rtc.receive();
tm = (TextMessage)rqc.receive();
tm = (TextMessage)ltc.receive();
tm = (TextMessage)lqc.receive();
System.out.println("Commit 10");
s.commit();
c.close();
c = cf.createConnection();
s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
lqc = s.createConsumer(localQueue);
ltc = s.createDurableSubscriber(localTopic, "ltc");
rqc = s.createConsumer(remoteQueue);
rtc = s.createDurableSubscriber(remoteTopic, "rtc");
c.start();
tm = (TextMessage)lqc.receiveNoWait();
assertTrue("local queue not empty: " + tm, tm == null);
tm = (TextMessage)ltc.receiveNoWait();
assertTrue("local sub not empty: " + tm, tm == null);
tm = (TextMessage)rqc.receiveNoWait();
assertTrue("remote queue not empty: " + tm, tm == null);
tm = (TextMessage)rtc.receiveNoWait();
assertTrue("remote sub not empty: " + tm, tm == null);
c.close();
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
stopAgentServer((short)0);
stopAgentServer((short)1);
endTest();
}
}
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2005 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2005 - 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
......@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): (ScalAgent D.T.)
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s): Badolle Fabien (ScalAgent D.T.)
*/
......@@ -26,13 +26,18 @@ package joram.local;
import java.util.Enumeration;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.QueueBrowser;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
......@@ -42,116 +47,127 @@ import javax.jms.TopicSubscriber;
import joram.framework.TestCase;
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.local.LocalConnectionFactory;
import org.objectweb.joram.client.jms.local.QueueLocalConnectionFactory;
import org.objectweb.joram.client.jms.local.TopicLocalConnectionFactory;
/**
* Test local : try to send a message and receive it with a queue and with a topic
*
*/
public class LocalTest extends TestCase {
public static final String TRANSACTION = "Transaction";
public static final String NULL_TRANSACTION =
"fr.dyade.aaa.util.NullTransaction";
public static final int MESSAGE_NUMBER = 10;
public LocalTest() {
super();
}
public void run() {
try {
System.getProperties().put(TRANSACTION, NULL_TRANSACTION);
System.getProperties().put("Transaction", "fr.dyade.aaa.util.NullTransaction");
fr.dyade.aaa.agent.AgentServer.init(new String[]{"0", "s0"});
fr.dyade.aaa.agent.AgentServer.start();
AdminModule.connect("localhost", 2560,
"root", "root", 60);
AdminModule.connect("localhost", 2560, "root", "root", 60);
org.objectweb.joram.client.jms.admin.User user =
org.objectweb.joram.client.jms.admin.User.create("anonymous", "anonymous", 0);
User user = User.create("anonymous", "anonymous", 0);
TopicConnectionFactory tcf =
org.objectweb.joram.client.jms.local.TopicLocalConnectionFactory.create();
QueueConnectionFactory qcf =
org.objectweb.joram.client.jms.local.QueueLocalConnectionFactory.create();
ConnectionFactory cf = LocalConnectionFactory.create();
QueueConnectionFactory qcf = QueueLocalConnectionFactory.create();
TopicConnectionFactory tcf = TopicLocalConnectionFactory.create();
org.objectweb.joram.client.jms.Topic topic =
org.objectweb.joram.client.jms.Topic.create(0);
Topic topic = Topic.create(0);
topic.setFreeReading();
topic.setFreeWriting();
org.objectweb.joram.client.jms.Queue queue =
org.objectweb.joram.client.jms.Queue.create(0);
Queue queue = Queue.create(0);
queue.setFreeReading();
queue.setFreeWriting();
// Test1 - Queue sender-receiver
QueueConnection qc = qcf.createQueueConnection();
final QueueSession sendQs = qc.createQueueSession(true, 0);
final QueueSender qsend = sendQs.createSender(queue);
QueueSession recQs = qc.createQueueSession(true, 0);
QueueReceiver qrec = recQs.createReceiver(queue);
QueueBrowser qb = recQs.createBrowser(queue);
qc.start();
new Thread(new Runnable() {
public void run() {
//System.out.println("Producer");
try {
for (int i = 0; i < MESSAGE_NUMBER; i++) {
TextMessage msg = sendQs.createTextMessage();
msg.setText("Test number " + i);
//System.out.println("Test number " + i);
qsend.send(msg);
}
//System.out.println("Commit");
sendQs.commit();
} catch (Exception exc) {
exc.printStackTrace();
}
}
}).start();
//if (checkQueue(qb, MESSAGE_NUMBER) == MESSAGE_NUMBER) {
//System.out.println("Consumer");
for (int i = 0; i < MESSAGE_NUMBER; i++) {
TextMessage msg = (TextMessage)qrec.receive();