summaryrefslogtreecommitdiff
path: root/RC9/qpid/dotnet/client-010/test/interop
diff options
context:
space:
mode:
Diffstat (limited to 'RC9/qpid/dotnet/client-010/test/interop')
-rw-r--r--RC9/qpid/dotnet/client-010/test/interop/Admin.cs90
-rw-r--r--RC9/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs83
-rw-r--r--RC9/qpid/dotnet/client-010/test/interop/Message.cs179
-rw-r--r--RC9/qpid/dotnet/client-010/test/interop/TestCase.cs117
4 files changed, 469 insertions, 0 deletions
diff --git a/RC9/qpid/dotnet/client-010/test/interop/Admin.cs b/RC9/qpid/dotnet/client-010/test/interop/Admin.cs
new file mode 100644
index 0000000000..93b24ea505
--- /dev/null
+++ b/RC9/qpid/dotnet/client-010/test/interop/Admin.cs
@@ -0,0 +1,90 @@
+/*
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*/
+
+using NUnit.Framework;
+using org.apache.qpid.client;
+using org.apache.qpid.transport;
+using org.apache.qpid.transport.util;
+
+namespace test.interop
+{
+ public class Admin:TestCase
+ {
+ private static readonly Logger _log = Logger.get(typeof(Admin));
+
+ [Test]
+ public void createSession()
+ {
+ _log.debug("Running: createSession");
+ ClientSession ssn = Client.createSession(0);
+ ssn.close();
+ // This test fails if an exception is thrown
+ }
+
+ [Test]
+ public void queueLifecycle()
+ {
+ _log.debug("Running: queueLifecycle");
+ ClientSession ssn = Client.createSession(0);
+ ssn.queueDeclare("queue1", null, null);
+ ssn.sync();
+ ssn.queueDelete("queue1");
+ ssn.sync();
+ try
+ {
+ ssn.exchangeBind("queue1", "amq.direct", "queue1", null);
+ ssn.sync();
+ }
+ catch (SessionException e)
+ {
+ // as expected
+ }
+ // This test fails if an exception is thrown
+ }
+
+ [Test]
+ public void exchangeCheck()
+ {
+ _log.debug("Running: exchangeCheck");
+ ClientSession ssn = Client.createSession(0);
+ ExchangeQueryResult query = (ExchangeQueryResult) ssn.exchangeQuery("amq.direct").Result;
+ Assert.IsFalse(query.getNotFound());
+ Assert.IsTrue(query.getDurable());
+ query = (ExchangeQueryResult)ssn.exchangeQuery("amq.topic").Result;
+ Assert.IsFalse(query.getNotFound());
+ Assert.IsTrue(query.getDurable());
+ query = (ExchangeQueryResult) ssn.exchangeQuery("foo").Result;
+ Assert.IsTrue(query.getNotFound());
+ }
+
+ [Test]
+ public void exchangeBind()
+ {
+ _log.debug("Running: exchangeBind");
+ ClientSession ssn = Client.createSession(0);
+ ssn.queueDeclare("queue1", null, null);
+ ssn.exchangeBind("queue1", "amq.direct", "queue1", null);
+ // This test fails if an exception is thrown
+ }
+
+
+ }
+}
diff --git a/RC9/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs b/RC9/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs
new file mode 100644
index 0000000000..9e27673a49
--- /dev/null
+++ b/RC9/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs
@@ -0,0 +1,83 @@
+/*
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*/
+using System;
+using common.org.apache.qpid.transport.util;
+using NUnit.Framework;
+using org.apache.qpid.client;
+using org.apache.qpid.transport.util;
+
+namespace test.interop
+{
+ public class ApplicationHeaders:TestCase
+ {
+ private static readonly Logger _log = Logger.get(typeof(ApplicationHeaders));
+
+ [Test]
+ public void setHeaders()
+ {
+ _log.debug("Running: setHeaders");
+ ClientSession ssn = Client.createSession(0);
+ ssn.queueDeclare("queue1");
+ ssn.exchangeBind("queue1", "amq.direct", "queue1");
+ ssn.sync();
+ CircularBuffer<IMessage> buff = new CircularBuffer<IMessage>(10);
+ SyncListener listener = new SyncListener(ssn, buff);
+ ssn.attachMessageListener(listener, "queue1");
+ ssn.messageSubscribe("queue1");
+
+ IMessage message = new org.apache.qpid.client.Message();
+ message.DeliveryProperties.setRoutingKey("queue1");
+ const long someLong = 14444444;
+ message.ApplicationHeaders.Add("someLong", someLong);
+ const int someInt = 14;
+ message.ApplicationHeaders.Add("soneInt", someInt);
+ const float someFloat = 14.001F;
+ message.ApplicationHeaders.Add("soneFloat", someFloat);
+ const double someDouble = 14.5555555;
+ message.ApplicationHeaders.Add("someDouble", someDouble);
+ const byte someByte = 2;
+ message.ApplicationHeaders.Add("someByte", someByte);
+ const string someString = "someString";
+ message.ApplicationHeaders.Add("someString", someString);
+ const char someChar = 'a';
+ message.ApplicationHeaders.Add("someChar", someChar);
+ const Boolean someBoolean = true;
+ message.ApplicationHeaders.Add("someBoolean", someBoolean);
+
+ // transfer the message
+ ssn.messageTransfer("amq.direct", message);
+
+ // get the message and check the headers
+ IMessage messageBack = buff.Dequeue();
+ Assert.IsTrue(((string) messageBack.ApplicationHeaders["someString"]).Equals(someString));
+ Assert.IsTrue(((char)messageBack.ApplicationHeaders["someChar"]).Equals(someChar));
+ Assert.IsTrue((long)messageBack.ApplicationHeaders["someLong"] == someLong);
+ Assert.IsTrue((int)messageBack.ApplicationHeaders["soneInt"] == someInt);
+ Assert.IsTrue((double)messageBack.ApplicationHeaders["someDouble"] == someDouble);
+ Assert.IsTrue((byte) messageBack.ApplicationHeaders["someByte"] == someByte);
+ Assert.IsTrue((Boolean)messageBack.ApplicationHeaders["someBoolean"]);
+ // c# has an conversion precision issue with decimal
+ Assert.IsTrue((float) messageBack.ApplicationHeaders["soneFloat"] <= someFloat);
+ float b = (float) messageBack.ApplicationHeaders["soneFloat"];
+ Assert.IsTrue(Convert.ToInt32(b) == Convert.ToInt32(someFloat));
+ }
+ }
+}
diff --git a/RC9/qpid/dotnet/client-010/test/interop/Message.cs b/RC9/qpid/dotnet/client-010/test/interop/Message.cs
new file mode 100644
index 0000000000..3267af9c0c
--- /dev/null
+++ b/RC9/qpid/dotnet/client-010/test/interop/Message.cs
@@ -0,0 +1,179 @@
+/*
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*/
+using System;
+using System.Text;
+using System.Threading;
+using NUnit.Framework;
+using org.apache.qpid.client;
+using org.apache.qpid.transport;
+using org.apache.qpid.transport.util;
+
+namespace test.interop
+{
+ public class Message : TestCase
+ {
+ private static readonly Logger _log = Logger.get(typeof (Message));
+
+ [Test]
+ public void sendAndPurge()
+ {
+ _log.debug("Running: exchangeBind");
+ ClientSession ssn = Client.createSession(0);
+ ssn.queueDelete("queue1");
+ QueueQueryResult result = (QueueQueryResult) ssn.queueQuery("queue1").Result;
+ Assert.IsNull(result.getQueue());
+ ssn.queueDeclare("queue1", null, null);
+ ssn.exchangeBind("queue1", "amq.direct", "queue1", null);
+ for (int i = 0; i < 10; i++)
+ {
+ ssn.messageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
+ new Header(new DeliveryProperties().setRoutingKey("queue1"),
+ new MessageProperties().setMessageId(UUID.randomUUID())),
+ Encoding.UTF8.GetBytes("test: " + i));
+ }
+ ssn.sync();
+ result = (QueueQueryResult) ssn.queueQuery("queue1").Result;
+ Assert.IsTrue(result.getMessageCount() == 10);
+ ssn.queuePurge("queue1");
+ ssn.sync();
+ result = (QueueQueryResult) ssn.queueQuery("queue1").Result;
+ Assert.IsTrue(result.getMessageCount() == 0);
+ }
+
+ [Test]
+ public void sendAndReceiveSmallMessages()
+ {
+ _log.debug("Running: sendAndReceiveSmallMessages");
+ byte[] smallMessage = Encoding.UTF8.GetBytes("test");
+ sendAndReceive(smallMessage, 100);
+ }
+
+ [Test]
+ public void sendAndReceiveLargeMessages()
+ {
+ _log.debug("Running: sendAndReceiveSmallMessages");
+ byte[] largeMessage = new byte[100 * 1024];
+ Random random = new Random();
+ random.NextBytes(largeMessage);
+ sendAndReceive(largeMessage, 10);
+ }
+
+ [Test]
+ public void sendAndReceiveVeryLargeMessages()
+ {
+ _log.debug("Running: sendAndReceiveSmallMessages");
+ byte[] verylargeMessage = new byte[1000 * 1024];
+ Random random = new Random();
+ random.NextBytes(verylargeMessage);
+ sendAndReceive(verylargeMessage, 2);
+ }
+
+ private void sendAndReceive(byte[] messageBody, int count)
+ {
+ ClientSession ssn = Client.createSession(0);
+ ssn.sync();
+ ssn.queueDeclare("queue1", null, null);
+ ssn.queueDelete("queue1");
+ QueueQueryResult result = (QueueQueryResult) ssn.queueQuery("queue1").Result;
+ Assert.IsNull(result.getQueue());
+ ssn.queueDeclare("queue1", null, null);
+ ssn.exchangeBind("queue1", "amq.direct", "queue1", null);
+ Object myLock = new Object();
+ MyListener myListener = new MyListener(myLock, count);
+ ssn.attachMessageListener(myListener, "myDest");
+
+ ssn.messageSubscribe("queue1", "myDest", MessageAcceptMode.EXPLICIT, MessageAcquireMode.PRE_ACQUIRED, null,
+ 0, null);
+
+
+ // issue credits
+ ssn.messageSetFlowMode("myDest", MessageFlowMode.WINDOW);
+ ssn.messageFlow("myDest", MessageCreditUnit.BYTE, ClientSession.MESSAGE_FLOW_MAX_BYTES);
+ ssn.messageFlow("myDest", MessageCreditUnit.MESSAGE, 10000);
+ ssn.sync();
+
+ for (int i = 0; i < count; i++)
+ {
+ ssn.messageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
+ new Header(new DeliveryProperties().setRoutingKey("queue1"),
+ new MessageProperties().setMessageId(UUID.randomUUID())),
+ messageBody);
+ }
+ ssn.sync();
+
+ lock (myLock)
+ {
+ if (myListener.Count != 0)
+ {
+ Monitor.Wait(myLock, 10000000);
+ }
+ }
+ Assert.IsTrue(myListener.Count == 0);
+ ssn.messageAccept(myListener.UnAck);
+ ssn.sync();
+ // the queue should be empty
+ result = (QueueQueryResult)ssn.queueQuery("queue1").Result;
+ Assert.IsTrue(result.getMessageCount() == 0);
+ ssn.close();
+ }
+
+
+
+ private class MyListener : IMessageListener
+ {
+ private static readonly Logger _log = Logger.get(typeof (MyListener));
+ private readonly Object _wl;
+ private int _count;
+ private RangeSet _rs = new RangeSet();
+
+ public MyListener(Object wl, int count)
+ {
+ _wl = wl;
+ _count = count;
+ }
+
+ public void messageTransfer(IMessage m)
+ {
+ byte[] body = new byte[m.Body.Length - m.Body.Position];
+ _log.debug("Got a message of size: " + body.Length + " count = " + _count);
+ _rs.add(m.Id);
+ lock (_wl)
+ {
+ _count--;
+ if (_count == 0)
+ {
+ Monitor.PulseAll(_wl);
+ }
+ }
+ }
+
+ public int Count
+ {
+ get { return _count; }
+ }
+
+ public RangeSet UnAck
+ {
+ get { return _rs; }
+ }
+ }
+ }
+}
diff --git a/RC9/qpid/dotnet/client-010/test/interop/TestCase.cs b/RC9/qpid/dotnet/client-010/test/interop/TestCase.cs
new file mode 100644
index 0000000000..8877de50cb
--- /dev/null
+++ b/RC9/qpid/dotnet/client-010/test/interop/TestCase.cs
@@ -0,0 +1,117 @@
+/*
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading;
+using System.Xml;
+using common.org.apache.qpid.transport.util;
+using log4net.Config;
+using NUnit.Framework;
+using org.apache.qpid.client;
+using org.apache.qpid.transport;
+using org.apache.qpid.transport.util;
+
+namespace test.interop
+{
+ [TestFixture]
+
+ public class TestCase
+ {
+ private readonly Dictionary<string,string> _properties = new Dictionary<string, string>();
+ private Client _client;
+
+ [TestFixtureSetUp]
+ public void Init()
+ {
+ XmlConfigurator.Configure(new FileInfo("/log.xml"));
+ // populate default properties
+ _properties.Add("UserName", "guest");
+ _properties.Add("Password", "guest");
+ _properties.Add("Host", "localhost");
+ _properties.Add("Port", "5672");
+ _properties.Add("VirtualHost", "test");
+ //Read the test config file
+ XmlTextReader reader = new XmlTextReader(Environment.CurrentDirectory + "/test.config");
+ while (reader.Read())
+ {
+ // if node type is an element
+ if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("add"))
+ {
+ if (_properties.ContainsKey(reader.GetAttribute("key")))
+ {
+ _properties[reader.GetAttribute("key")] = reader.GetAttribute("value");
+ }
+ else
+ {
+ _properties.Add(reader.GetAttribute("key"), reader.GetAttribute("value"));
+ }
+
+ }
+ }
+ // create a client and connect to the broker
+ _client = new Client();
+ _client.connect(Properties["Host"], Convert.ToInt16(Properties["Port"]), Properties["VirtualHost"],
+ Properties["UserName"], Properties["Password"]);
+
+ }
+
+ [TestFixtureTearDown]
+ public void Cleanup()
+ {
+ _client.close();
+ }
+
+ public Client Client
+ {
+ get{ return _client;}
+ }
+
+ public Dictionary<string,string> Properties
+ {
+ get { return _properties; }
+ }
+
+
+ public class SyncListener : IMessageListener
+ {
+ private static readonly Logger _log = Logger.get(typeof(SyncListener));
+ private readonly CircularBuffer<IMessage> _buffer;
+ private readonly RangeSet _range = new RangeSet();
+ private readonly ClientSession _session;
+
+ public SyncListener(ClientSession session, CircularBuffer<IMessage> buffer)
+ {
+ _buffer = buffer;
+ _session = session;
+ }
+
+ public void messageTransfer(IMessage m)
+ {
+ _range.clear();
+ _range.add(m.Id);
+ _session.messageAccept(_range);
+ _buffer.Enqueue(m);
+ }
+ }
+ }
+}