diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2007-09-21 02:41:41 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2007-09-21 02:41:41 +0000 |
commit | 75d71dd695da1612d8ff6768a1a4b8082b2d2d65 (patch) | |
tree | 68a6fb4567715a7ff686fa952e3e1770b1fc04f8 | |
parent | ee644f8dcae4b0eea97751ab96ff29afc9c7879d (diff) | |
download | qpid-python-75d71dd695da1612d8ff6768a1a4b8082b2d2d65.tar.gz |
added isolated test cases for interop with c++ broker
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@577963 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | java/client/src/main/java/org/apache/qpidity/nclient/interop/BasicInteropTest.java | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/java/client/src/main/java/org/apache/qpidity/nclient/interop/BasicInteropTest.java b/java/client/src/main/java/org/apache/qpidity/nclient/interop/BasicInteropTest.java new file mode 100644 index 0000000000..a5bb12e116 --- /dev/null +++ b/java/client/src/main/java/org/apache/qpidity/nclient/interop/BasicInteropTest.java @@ -0,0 +1,126 @@ +package org.apache.qpidity.nclient.interop; + +import org.apache.qpidity.QpidException; +import org.apache.qpidity.api.Message; +import org.apache.qpidity.nclient.Client; +import org.apache.qpidity.nclient.Connection; +import org.apache.qpidity.nclient.ExceptionListener; +import org.apache.qpidity.nclient.Session; +import org.apache.qpidity.nclient.util.MessageListener; +import org.apache.qpidity.nclient.util.MessagePartListenerAdapter; +import org.apache.qpidity.transport.DeliveryProperties; +import org.apache.qpidity.transport.ExchangeQueryResult; +import org.apache.qpidity.transport.Future; +import org.apache.qpidity.transport.RangeSet; + +public class BasicInteropTest implements ExceptionListener +{ + + private Session session; + private Connection conn; + private String host; + + public BasicInteropTest(String host) + { + this.host = host; + } + + public void testCreateConnection(){ + System.out.println("------- Creating connection--------"); + conn = Client.createConnection(); + try{ + conn.connect(host, 5672, "test", "guest", "guest"); + }catch(Exception e){ + System.out.println("------- Error Creating connection--------"); + e.printStackTrace(); + System.exit(1); + } + System.out.println("------- Connection created Suscessfully --------"); + } + + public void testCreateSession(){ + System.out.println("------- Creating session --------"); + session = conn.createSession(0); + System.out.println("------- Session created sucessfully --------"); + } + + public void testExchange(){ + System.out.println("------- Creating an exchange --------"); + session.exchangeDeclare("test", "amq.direct", "", null); + session.sync(); + System.out.println("------- Exchange created --------"); + } + + public void testQueue(){ + System.out.println("------- Creating a queue --------"); + session.queueDeclare("testQueue", "", null); + session.sync(); + System.out.println("------- Queue created --------"); + + System.out.println("------- Binding a queue --------"); + session.queueBind("testQueue", "test", "testKey", null); + session.sync(); + System.out.println("------- Queue bound --------"); + } + + public void testSendMessage(){ + System.out.println("------- Sending a message --------"); + session.messageTransfer("test", Session.TRANSFER_CONFIRM_MODE_REQUIRED, Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE); + session.header(new DeliveryProperties().setRoutingKey("testKey")); + session.data("TestMessage"); + session.endData(); + session.sync(); + System.out.println("------- Message sent --------"); + } + + public void testSubscribe(){ + System.out.println("------- Sending a subscribe --------"); + session.messageSubscribe("testQueue", "myDest", + Session.TRANSFER_CONFIRM_MODE_REQUIRED, + Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE, + new MessagePartListenerAdapter(new MessageListener(){ + + public void onMessage(Message message) + { + System.out.println("--------Message Received--------"); + System.out.println(message.toString()); + System.out.println("--------/Message Received--------"); + RangeSet ack = new RangeSet(); + ack.add(message.getMessageTransferId(),message.getMessageTransferId()); + session.messageAcknowledge(ack); + } + + }), + null); + + System.out.println("------- Setting Credit mode --------"); + session.messageFlowMode("myDest", Session.MESSAGE_FLOW_MODE_WINDOW); + System.out.println("------- Setting Credit --------"); + session.messageFlow("myDest", Session.MESSAGE_FLOW_UNIT_MESSAGE, 1); + } + + public void onException(QpidException e) + { + System.out.println("------- Broker Notified an error --------"); + System.out.println("------- " + e.getErrorCode() + " --------"); + System.out.println("------- " + e.getMessage() + " --------"); + System.out.println("------- /Broker Notified an error --------"); + } + + public static void main(String[] args) + { + String host = "0.0.0.0"; + if (args.length>0) + { + host = args[0]; + } + + BasicInteropTest t = new BasicInteropTest(host); + t.testCreateConnection(); + t.testCreateSession(); + t.testExchange(); + t.testQueue(); + t.testSubscribe(); + t.testSendMessage(); + } +} |