Commit 2279af28 authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Minor changes, increase test stability.

parent f96cf959
......@@ -80,13 +80,13 @@ public class AliasTestQ2 extends TestCase {
for (int i = 0; i < 10; i++) {
TextMessage msg = sessionp.createTextMessage();
msg.setText("Message n�" + i);
msg.setText("Message #" + i);
producer.send(msg);
}
for (int i = 0; i < 10; i++) {
Message msg = consumer.receive();
assertEquals("Message n�" + i, ((TextMessage) msg).getText());
assertEquals("Message #" + i, ((TextMessage) msg).getText());
}
Thread.sleep(1000);
......@@ -96,12 +96,12 @@ public class AliasTestQ2 extends TestCase {
for (int i = 0; i < 10; i++) {
TextMessage msg = sessionp.createTextMessage();
msg.setText("Message n�" + i);
msg.setText("Message #" + i);
producer.send(msg);
}
// Let some time for the notifications to expire in the network and go back in the alias queue
Thread.sleep(5000);
Thread.sleep(10000);
AdminModule.connect(cf0, "root", "root");
......@@ -115,7 +115,7 @@ public class AliasTestQ2 extends TestCase {
// Alias queue should transmit the waiting messages to the final queue
for (int i = 0; i < 10; i++) {
Message msg = consumer.receive(10000);
assertEquals("Message n�" + i, ((TextMessage) msg).getText());
assertEquals("Message #" + i, ((TextMessage) msg).getText());
}
cnx0.close();
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2018 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):
* Contributor(s):
*/
package joram.jms2;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.JMSProducer;
import javax.jms.Message;
import javax.jms.TextMessage;
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;
import framework.TestCase;
/**
* Test the queue delivery delay mechanism.
*/
public class QueueDeliveryDelay extends TestCase implements javax.jms.MessageListener {
public static void main(String[] args) {
new QueueDeliveryDelay().run();
}
JMSContext context;
JMSConsumer consumer;
public void run() {
try {
startAgentServer((short) 0);
Thread.sleep(1000);
admin();
test();
Thread.sleep(1000);
stopAgentServer((short) 0);
Thread.sleep(1000);
startAgentServer((short) 0);
Thread.sleep(1000);
System.out.println("Server restarted.");
test();
assertTrue("Should receive 2 messages: " + nbrecv, (nbrecv == 2));
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
stopAgentServer((short) 0);
endTest();
}
}
ConnectionFactory cf = null;
Queue dest = null;
void admin() throws Exception {
cf = TcpConnectionFactory.create("localhost", 2560);
AdminModule.connect(cf, "root", "root");
User.create("anonymous", "anonymous", 0);
dest = Queue.create("queue");
dest.setDeliveryDelay(5000);
dest.setFreeReading();
dest.setFreeWriting();
AdminModule.disconnect();
}
long send = 0L;
long recv = 0L;
void test() throws InterruptedException {
context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
consumer = context.createConsumer(dest);
consumer.setMessageListener(this);
context.start();
JMSContext prodCtx = cf.createContext();
JMSProducer producer = prodCtx.createProducer();
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
send = System.currentTimeMillis();
producer.send(dest, msg);
// Wait to receive the message.
Thread.sleep(10000);
assertTrue("The message is received before the delivery delay", (recv - send) > 5000);
context.close();
prodCtx.close();
}
int nbrecv = 0;
public void onMessage(Message message) {
try {
nbrecv += 1;
System.out.println("#" + nbrecv + " - " + message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered() +
", JMSTimestamp = " + message.getJMSTimestamp());
System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
} catch (JMSException e) {
e.printStackTrace();
}
recv = System.currentTimeMillis();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2018 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):
* Contributor(s):
*/
package joram.jms2;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.JMSProducer;
import javax.jms.Message;
import javax.jms.TextMessage;
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;
import framework.TestCase;
/**
* Test the queue delivery delay mechanism.
*/
public class QueueDeliveryDelay extends TestCase implements javax.jms.MessageListener {
public static void main(String[] args) {
new QueueDeliveryDelay().run();
}
JMSContext context;
JMSConsumer consumer;
public void run() {
try {
startAgentServer((short) 0);
Thread.sleep(1000);
admin();
test();
Thread.sleep(1000);
stopAgentServer((short) 0);
Thread.sleep(1000);
startAgentServer((short) 0);
Thread.sleep(1000);
System.out.println("Server restarted.");
test();
assertTrue("Should receive 2 messages: " + nbrecv, (nbrecv == 2));
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
stopAgentServer((short) 0);
endTest();
}
}
ConnectionFactory cf = null;
Queue dest = null;
void admin() throws Exception {
cf = TcpConnectionFactory.create("localhost", 2560);
AdminModule.connect(cf, "root", "root");
User.create("anonymous", "anonymous", 0);
dest = Queue.create("queue");
dest.setDeliveryDelay(5000);
dest.setFreeReading();
dest.setFreeWriting();
AdminModule.disconnect();
}
long send = 0L;
long recv = 0L;
void test() throws InterruptedException {
context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
consumer = context.createConsumer(dest);
consumer.setMessageListener(this);
context.start();
JMSContext prodCtx = cf.createContext();
JMSProducer producer = prodCtx.createProducer();
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
send = System.currentTimeMillis();
producer.send(dest, msg);
// Wait to receive the message.
Thread.sleep(10000);
assertTrue("The message is received before the delivery delay", (recv - send) >= 5000);
context.close();
prodCtx.close();
}
int nbrecv = 0;
public void onMessage(Message message) {
try {
nbrecv += 1;
System.out.println("#" + nbrecv + " - " + message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered() +
", JMSTimestamp = " + message.getJMSTimestamp());
System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
} catch (JMSException e) {
e.printStackTrace();
}
recv = System.currentTimeMillis();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2018 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):
* Contributor(s):
*/
package joram.jms2;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.JMSProducer;
import javax.jms.Message;
import javax.jms.TextMessage;
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;
import framework.TestCase;
/**
* Test the queue delivery delay mechanism.
*/
public class QueueDeliveryDelay2 extends TestCase {
public static void main(String[] args) {
new QueueDeliveryDelay2().run();
}
JMSContext context;
JMSConsumer consumer;
public void run() {
try {
startAgentServer((short) 0);
Thread.sleep(1000);
admin();
test();
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
stopAgentServer((short) 0);
endTest();
}
}
ConnectionFactory cf = null;
Queue dest = null;
void admin() throws Exception {
cf = TcpConnectionFactory.create("localhost", 2560);
AdminModule.connect(cf, "root", "root");
User.create("anonymous", "anonymous", 0);
dest = Queue.create("queue");
dest.setDeliveryDelay(10000);
dest.setFreeReading();
dest.setFreeWriting();
AdminModule.disconnect();
}
long send = 0L;
long recv = 0L;
void test() throws Exception {
JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
JMSProducer producer = context.createProducer();
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
Message msg = context.createTextMessage("test DeliveryDelay");
send = System.currentTimeMillis();
producer.send(dest, msg);
System.out.println("Message sent.");
context.close();
Thread.sleep(1000);
stopAgentServer((short) 0);
Thread.sleep(1000);
startAgentServer((short) 0);
Thread.sleep(1000);
System.out.println("Server restarted.");
context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
consumer = context.createConsumer(dest);
context.start();
msg = consumer.receive(10000);
System.out.println("Message received: " + msg);
assertTrue("Don't receive delayed message", (msg != null));
context.close();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2018 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):
* Contributor(s):
*/
package joram.jms2;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSProducer;
import javax.jms.Message;
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;
import framework.TestCase;
/**
* Test the queue delivery delay mechanism.
*/
public class QueueDeliveryDelay2 extends TestCase {
public static void main(String[] args) {
new QueueDeliveryDelay2().run();
}
JMSContext context;
JMSConsumer consumer;
public void run() {
try {
startAgentServer((short) 0);
Thread.sleep(1000);
admin();
test();
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
stopAgentServer((short) 0);
endTest();
}
}
ConnectionFactory cf = null;
Queue dest = null;
void admin() throws Exception {
cf = TcpConnectionFactory.create("localhost", 2560);
AdminModule.connect(cf, "root", "root");
User.create("anonymous", "anonymous", 0);
dest = Queue.create("queue");
dest.setDeliveryDelay(10000);
dest.setFreeReading();
dest.setFreeWriting();
AdminModule.disconnect();
}
long send = 0L;
long recv = 0L;
void test() throws Exception {
JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
JMSProducer producer = context.createProducer();
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
Message msg = context.createTextMessage("test DeliveryDelay");
send = System.currentTimeMillis();
producer.send(dest, msg);
System.out.println("Message sent.");
context.close();
Thread.sleep(1000);
stopAgentServer((short) 0);
Thread.sleep(1000);
startAgentServer((short) 0);
Thread.sleep(1000);
System.out.println("Server restarted.");
context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
consumer = context.createConsumer(dest);
context.start();
msg = consumer.receive(10000);
System.out.println("Message received: " + msg);
assertTrue("Don't receive delayed message", (msg != null));
context.close();
}
}
Supports Markdown
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