Commit 1724b114 authored by afreyssin's avatar afreyssin

Test JORAM-281.

parent e7b2f581
......@@ -310,7 +310,10 @@
<antcall target="client.ClientTest27"/>
<antcall target="client.ClientTest28"/>
<antcall target="client.ClientTest29"/>
<antcall target="client.ClientTestAsyncSend"/>
<antcall target="client.ClientTestAsyncSend"/>
<antcall target="client.ClientTest30"/>
<antcall target="client.ClientTest31"/>
<antcall target="client.ClientTest32"/>
</target>
<target name="tests.connection"
......@@ -413,10 +416,13 @@
<antcall target="noreg.test50"/>
<antcall target="noreg.test51"/>
<antcall target="noreg.test56"/>
<antcall target="noreg.test57"/>
<antcall target="noreg.test58"/>
<antcall target="noreg.test59"/>
<antcall target="noreg.test60"/>
<antcall target="noreg.test61"/>
<antcall target="noreg.test62"/>
<antcall target="noreg.test63"/>
</target>
<target name="tests.xa"
......@@ -2182,6 +2188,42 @@
</antcall>
</target>
<target name="client.ClientTest30" depends="init.a3props,compile"
description=" --> Test message consumption after connection closes (JORAM-281).">
<antcall target="test.run" inheritAll="true">
<param name="transaction" value="fr.dyade.aaa.util.NullTransaction"/>
<param name="className" value="joram.client.ClientTest30"/>
<param name="jndiconf" value="client/jndi.properties"/>
<param name="a3conf" value="client/a3servers.xml"/>
<param name="testid" value="client.ClientTest30"/>
<param name="args" value=""/>
</antcall>
</target>
<target name="client.ClientTest31" depends="init.a3props,compile"
description=" --> Test message consumption after connection closes (JORAM-281).">
<antcall target="test.run" inheritAll="true">
<param name="transaction" value="fr.dyade.aaa.util.NullTransaction"/>
<param name="className" value="joram.client.ClientTest31"/>
<param name="jndiconf" value="client/jndi.properties"/>
<param name="a3conf" value="client/a3servers.xml"/>
<param name="testid" value="client.ClientTest31"/>
<param name="args" value=""/>
</antcall>
</target>
<target name="client.ClientTest32" depends="init.a3props,compile"
description=" --> Test message consumption after connection closes (JORAM-281).">
<antcall target="test.run" inheritAll="true">
<param name="transaction" value="fr.dyade.aaa.util.NullTransaction"/>
<param name="className" value="joram.client.ClientTest32"/>
<param name="jndiconf" value="client/jndi.properties"/>
<param name="a3conf" value="client/a3servers.xml"/>
<param name="testid" value="client.ClientTest32"/>
<param name="args" value=""/>
</antcall>
</target>
<target name="client.ClientTestAsyncSend" depends="init.a3props,compile"
description=" --> Test async send JMS 2.0 API.">
<antcall target="test.run" inheritAll="true">
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2017 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 D.T.
* Contributor(s):
*/
package joram.client;
import javax.jms.Session;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.TextMessage;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.admin.AdminModule;
import framework.TestCase;
/**
* After closing a MessageConsumer the queue shall not try to deliver the next message
* to this consumer (JORAM-281).
* In this test the message is delivered to the closed consumer then denied, so the
* delivered and denied counters are incremented.
*/
public class ClientTest32 extends TestCase {
public static void main(String[] args) {
new ClientTest32().run();
}
Queue queue = null;
public void run() {
try {
startAgentServer((short) 0, new String[] { "-DTransaction=fr.dyade.aaa.util.NullTransaction" });
Thread.sleep(1000);
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);
queue = Queue.create(0, "test_queue");
queue.setFreeReading();
queue.setFreeWriting();
ConnectionFactory cf = org.objectweb.joram.client.jms.tcp.TcpConnectionFactory.create("localhost", 2560);
testDelivered(queue, cf);
Thread.sleep(1000);
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
stopAgentServer((short) 0);
endTest();
}
}
public void testDelivered(final Destination dest, ConnectionFactory cf) throws Exception {
Connection connection1 = cf.createConnection();
connection1.start();
Session session1 = connection1.createSession();
try (MessageConsumer consumer = session1.createConsumer(queue)) {
new Thread(() -> {
try {
TextMessage jmsMessage = (TextMessage) consumer.receive();
System.out.println("Message received: " + jmsMessage);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}).start();
Thread.sleep(10L);
}
Thread.sleep(1000L);
try (Connection connection2 = cf.createConnection()) {
connection2.start();
Session session2 = connection2.createSession();
MessageProducer producer = session2.createProducer(queue);
producer.send(session2.createTextMessage("OK"));
System.out.println("Message sent");
}
System.out.println(queue.getStatistics());
assertTrue("Delivered message should be 0", queue.getDeliveredMessages() == 0);
connection1.close();
}
}
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