From bb28820a8e2d3e06533159a110744d600711cc34 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Sat, 4 Mar 2006 08:19:09 +0000 Subject: [PATCH] Get it to compile after refactor git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@383072 13f79535-47bb-0310-9956-ffa450edef68 --- openwire-dotnet/OpenWire.build | 8 +- openwire-dotnet/src/src.csproj | 372 +++++------ .../tests/ActiveMQ/AsyncConsumeTest.cs | 168 ++--- .../tests/ActiveMQ/BadConsumeTest.cs | 82 ++- .../tests/ActiveMQ/BytesMessageTest.cs | 113 ++-- openwire-dotnet/tests/ActiveMQ/ClientTest.cs | 5 +- openwire-dotnet/tests/ActiveMQ/CommandTest.cs | 124 ++-- .../tests/ActiveMQ/ConsumerTest.cs | 181 +++--- openwire-dotnet/tests/ActiveMQ/EndianTest.cs | 154 ++--- .../tests/ActiveMQ/JMSPropertyTest.cs | 251 ++++---- .../tests/ActiveMQ/MapMessageTest.cs | 187 +++--- .../ActiveMQ/OpenWire/BooleanStreamTest.cs | 5 +- openwire-dotnet/tests/ActiveMQ/TestMain.cs | 159 +++-- openwire-dotnet/tests/ActiveMQ/TestSupport.cs | 6 +- .../tests/ActiveMQ/TransactionTest.cs | 577 +++++++++--------- openwire-dotnet/tests/tests.csproj | 30 +- 16 files changed, 1215 insertions(+), 1207 deletions(-) diff --git a/openwire-dotnet/OpenWire.build b/openwire-dotnet/OpenWire.build index 93affde66a..111fef7089 100644 --- a/openwire-dotnet/OpenWire.build +++ b/openwire-dotnet/OpenWire.build @@ -148,8 +148,8 @@ - - + + @@ -165,8 +165,8 @@ - - + + diff --git a/openwire-dotnet/src/src.csproj b/openwire-dotnet/src/src.csproj index f8c6e229ac..36a12a3d03 100644 --- a/openwire-dotnet/src/src.csproj +++ b/openwire-dotnet/src/src.csproj @@ -1,186 +1,186 @@ - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {F7BA9EF7-ADF7-40EF-9A9E-206649DBB10C} - Library - src - src - 4 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - false - - - false - true - bin\Release\ - TRACE - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {F7BA9EF7-ADF7-40EF-9A9E-206649DBB10C} + Library + src + src + 4 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + false + + + false + true + bin\Release\ + TRACE + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/openwire-dotnet/tests/ActiveMQ/AsyncConsumeTest.cs b/openwire-dotnet/tests/ActiveMQ/AsyncConsumeTest.cs index c97dbfd849..c90b06d78d 100644 --- a/openwire-dotnet/tests/ActiveMQ/AsyncConsumeTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/AsyncConsumeTest.cs @@ -1,77 +1,91 @@ -using System; -using System.IO; -using System.Threading; - -using NUnit.Framework; - -using OpenWire.Client; -using OpenWire.Client.Core; -namespace OpenWire.Client -{ - [TestFixture] - public class AsyncConsumeTest : TestSupport - { - protected Object semaphore = new Object(); - protected bool received; - - [Test] - public void TestAsynchronousConsume() - { - IConnectionFactory factory = new ConnectionFactory("localhost", 61616); - Assert.IsTrue(factory != null, "no factory created"); - - using (IConnection connection = factory.CreateConnection()) - { - Assert.IsTrue(connection != null, "no connection created"); - Console.WriteLine("Connected to ActiveMQ!"); - - ISession session = connection.CreateSession(); - IDestination destination = CreateDestination(session); - Assert.IsTrue(destination != null, "No queue available!"); - - // lets create an async consumer - // START SNIPPET: demo - IMessageConsumer consumer = session.CreateConsumer(destination); - consumer.Listener += new MessageListener(OnMessage); - // END SNIPPET: demo - - - // now lets send a message - session = connection.CreateSession(); - IMessageProducer producer = session.CreateProducer(destination); - IMessage request = CreateMessage(session); - request.JMSCorrelationID = "abc"; - request.JMSType = "Test"; - producer.Send(request); - - - WaitForMessageToArrive(); - } - - } - - protected void OnMessage(IMessage message) - { - Console.WriteLine("Received message: " + message); - lock (semaphore) - { - received = true; - Monitor.PulseAll(semaphore); - } - - } - - protected void WaitForMessageToArrive() - { - lock (semaphore) - { - if (!received) - { - Monitor.Wait(semaphore, 10000); - } - } - Assert.AreEqual(true, received, "Should have received a message by now!"); - } - - } -} +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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.IO; +using System.Threading; + +using NUnit.Framework; + +namespace ActiveMQ +{ + [TestFixture] + public class AsyncConsumeTest : TestSupport + { + protected Object semaphore = new Object(); + protected bool received; + + [Test] + public void TestAsynchronousConsume() + { + IConnectionFactory factory = new ConnectionFactory("localhost", 61616); + Assert.IsTrue(factory != null, "no factory created"); + + using (IConnection connection = factory.CreateConnection()) + { + Assert.IsTrue(connection != null, "no connection created"); + Console.WriteLine("Connected to ActiveMQ!"); + + ISession session = connection.CreateSession(); + IDestination destination = CreateDestination(session); + Assert.IsTrue(destination != null, "No queue available!"); + + // lets create an async consumer + // START SNIPPET: demo + IMessageConsumer consumer = session.CreateConsumer(destination); + consumer.Listener += new MessageListener(OnMessage); + // END SNIPPET: demo + + + // now lets send a message + session = connection.CreateSession(); + IMessageProducer producer = session.CreateProducer(destination); + IMessage request = CreateMessage(session); + request.JMSCorrelationID = "abc"; + request.JMSType = "Test"; + producer.Send(request); + + + WaitForMessageToArrive(); + } + + } + + protected void OnMessage(IMessage message) + { + Console.WriteLine("Received message: " + message); + lock (semaphore) + { + received = true; + Monitor.PulseAll(semaphore); + } + + } + + protected void WaitForMessageToArrive() + { + lock (semaphore) + { + if (!received) + { + Monitor.Wait(semaphore, 10000); + } + } + Assert.AreEqual(true, received, "Should have received a message by now!"); + } + + } +} diff --git a/openwire-dotnet/tests/ActiveMQ/BadConsumeTest.cs b/openwire-dotnet/tests/ActiveMQ/BadConsumeTest.cs index 1234250a94..3f4b3d22d1 100644 --- a/openwire-dotnet/tests/ActiveMQ/BadConsumeTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/BadConsumeTest.cs @@ -1,33 +1,49 @@ -using NUnit.Framework; -using System; - -namespace OpenWire.Client -{ - [TestFixture] - public class BadConsumeTest : TestSupport - { - [Test] - public void TestBadConsumeOperationToTestExceptions() - { - IConnectionFactory factory = new ConnectionFactory("localhost", 61616); - using (IConnection connection = factory.CreateConnection()) - { - ISession session = connection.CreateSession(); - - try - { - IMessageConsumer consumer = session.CreateConsumer(null); - Console.WriteLine("Created consumer: " + consumer); - - Assert.Fail("Should have thrown an exception!"); - } - catch (BrokerException e) - { - Console.WriteLine("Caught expected exception: " + e); - Console.WriteLine("Stack: " + e.StackTrace); - Console.WriteLine("Java Stack: " + e.JavaStackTrace); - } - } - } - } -} +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 System; + +namespace ActiveMQ +{ + [TestFixture] + public class BadConsumeTest : TestSupport + { + [Test] + public void TestBadConsumeOperationToTestExceptions() + { + IConnectionFactory factory = new ConnectionFactory("localhost", 61616); + using (IConnection connection = factory.CreateConnection()) + { + ISession session = connection.CreateSession(); + + try + { + IMessageConsumer consumer = session.CreateConsumer(null); + Console.WriteLine("Created consumer: " + consumer); + + Assert.Fail("Should have thrown an exception!"); + } + catch (BrokerException e) + { + Console.WriteLine("Caught expected exception: " + e); + Console.WriteLine("Stack: " + e.StackTrace); + Console.WriteLine("Java Stack: " + e.JavaStackTrace); + } + } + } + } +} diff --git a/openwire-dotnet/tests/ActiveMQ/BytesMessageTest.cs b/openwire-dotnet/tests/ActiveMQ/BytesMessageTest.cs index 4975ce0bd4..5c650d53e9 100644 --- a/openwire-dotnet/tests/ActiveMQ/BytesMessageTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/BytesMessageTest.cs @@ -1,58 +1,55 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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.IO; - -using NUnit.Framework; - -using OpenWire.Client; -using OpenWire.Client.Core; - -namespace OpenWire.Client -{ - [ TestFixture ] - public class BytesMessageTest : TestSupport - { - byte[] expected = {1, 2, 3, 4, 5, 6, 7, 8}; - - [ Test ] - public override void SendAndSyncReceive() - { - base.SendAndSyncReceive(); - } - - protected override IMessage CreateMessage(ISession session) - { - IBytesMessage request = session.CreateBytesMessage(expected); - return request; - } - - protected override void AssertValidMessage(IMessage message) - { - Assert.IsTrue(message is IBytesMessage, "Did not receive a IBytesMessage: " + message); - - Console.WriteLine("Received IBytesMessage: " + message); - - IBytesMessage bytesMessage = (IBytesMessage) message; - byte[] actual = bytesMessage.Content; - Console.WriteLine("Received message with content: " + actual); - Assert.AreEqual(expected, actual, "the message content"); - } - - } -} - +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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.IO; + +using NUnit.Framework; + +namespace ActiveMQ +{ + [ TestFixture ] + public class BytesMessageTest : TestSupport + { + byte[] expected = {1, 2, 3, 4, 5, 6, 7, 8}; + + [ Test ] + public override void SendAndSyncReceive() + { + base.SendAndSyncReceive(); + } + + protected override IMessage CreateMessage(ISession session) + { + IBytesMessage request = session.CreateBytesMessage(expected); + return request; + } + + protected override void AssertValidMessage(IMessage message) + { + Assert.IsTrue(message is IBytesMessage, "Did not receive a IBytesMessage: " + message); + + Console.WriteLine("Received IBytesMessage: " + message); + + IBytesMessage bytesMessage = (IBytesMessage) message; + byte[] actual = bytesMessage.Content; + Console.WriteLine("Received message with content: " + actual); + Assert.AreEqual(expected, actual, "the message content"); + } + + } +} + diff --git a/openwire-dotnet/tests/ActiveMQ/ClientTest.cs b/openwire-dotnet/tests/ActiveMQ/ClientTest.cs index 2770948820..edc6f5365d 100644 --- a/openwire-dotnet/tests/ActiveMQ/ClientTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/ClientTest.cs @@ -19,10 +19,7 @@ using System.IO; using NUnit.Framework; -using OpenWire.Client; -using OpenWire.Client.Core; - -namespace OpenWire.Client +namespace ActiveMQ { [ TestFixture ] public class ClientTest : TestSupport diff --git a/openwire-dotnet/tests/ActiveMQ/CommandTest.cs b/openwire-dotnet/tests/ActiveMQ/CommandTest.cs index e5db197e60..bf73d1c3ea 100644 --- a/openwire-dotnet/tests/ActiveMQ/CommandTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/CommandTest.cs @@ -1,61 +1,63 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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 OpenWire.Client.Commands; -using System.Collections; - -namespace OpenWire.Client -{ - [TestFixture] - public class CommandTest - { - - [Test] - public void TestCommand() - { - ConsumerId value1 = new ConsumerId(); - value1.ConnectionId = "abc"; - value1.SessionId = 123; - value1.Value = 456; - - ConsumerId value2 = new ConsumerId(); - value2.ConnectionId = "abc"; - value2.SessionId = 123; - value2.Value = 456; - - ConsumerId value3 = new ConsumerId(); - value3.ConnectionId = "abc"; - value3.SessionId = 123; - value3.Value = 457; - - Assert.AreEqual(value1, value2, "value1 and value2 should be equal"); - Assert.AreEqual(value1.GetHashCode(), value2.GetHashCode(), "value1 and value2 hash codes should be equal"); - - Assert.IsTrue(!value1.Equals(value3), "value1 and value3 should not be equal"); - Assert.IsTrue(!value3.Equals(value2), "value3 and value2 should not be equal"); - - // now lets test an IDictionary - IDictionary dictionary = new Hashtable(); - dictionary[value1] = value3; - - // now lets lookup with a copy - object actual = dictionary[value2]; - - Assert.AreEqual(value3, actual, "Should have found item in Map using value2 as a key"); - } - } -} +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 System.Collections; + +using ActiveMQ.OpenWire; +using ActiveMQ.OpenWire.Commands; + +namespace ActiveMQ +{ + [TestFixture] + public class CommandTest + { + + [Test] + public void TestCommand() + { + ConsumerId value1 = new ConsumerId(); + value1.ConnectionId = "abc"; + value1.SessionId = 123; + value1.Value = 456; + + ConsumerId value2 = new ConsumerId(); + value2.ConnectionId = "abc"; + value2.SessionId = 123; + value2.Value = 456; + + ConsumerId value3 = new ConsumerId(); + value3.ConnectionId = "abc"; + value3.SessionId = 123; + value3.Value = 457; + + Assert.AreEqual(value1, value2, "value1 and value2 should be equal"); + Assert.AreEqual(value1.GetHashCode(), value2.GetHashCode(), "value1 and value2 hash codes should be equal"); + + Assert.IsTrue(!value1.Equals(value3), "value1 and value3 should not be equal"); + Assert.IsTrue(!value3.Equals(value2), "value3 and value2 should not be equal"); + + // now lets test an IDictionary + IDictionary dictionary = new Hashtable(); + dictionary[value1] = value3; + + // now lets lookup with a copy + object actual = dictionary[value2]; + + Assert.AreEqual(value3, actual, "Should have found item in Map using value2 as a key"); + } + } +} diff --git a/openwire-dotnet/tests/ActiveMQ/ConsumerTest.cs b/openwire-dotnet/tests/ActiveMQ/ConsumerTest.cs index 239485da49..cb13fa9380 100755 --- a/openwire-dotnet/tests/ActiveMQ/ConsumerTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/ConsumerTest.cs @@ -1,92 +1,89 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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.IO; - -using NUnit.Framework; - -using OpenWire.Client; -using OpenWire.Client.Core; - -namespace OpenWire.Client -{ - [TestFixture] - public class ConsumerTest : TestSupport - { - IConnectionFactory factory; - IConnection connection; - IDestination destination; - - [SetUp] - protected void SetUp() - { - factory = new ConnectionFactory("localhost", 61616); - connection = factory.CreateConnection(); - } - - [TearDown] - protected void TearDown() - { - connection.Dispose(); - } - - [Test] - [Ignore("Not fully implemented yet.")] - public void testDurableConsumerSelectorChange() - { - - // Receive a message with the JMS API - connection.ClientId="test"; - connection.Start(); - - ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); - destination = session.GetTopic("foo"); - IMessageProducer producer = session.CreateProducer(destination); - producer.Persistent = true; - IMessageConsumer consumer = session.CreateDurableConsumer((ITopic)destination, "test", "color='red'", false); - - // Send the messages - ITextMessage message = session.CreateTextMessage("1st"); - //message.SetStringProperty("color", "red"); - producer.Send(message); - - IMessage m = consumer.Receive(1000); - Assert.IsNotNull(m); - Assert.AreEqual("1st", ((ITextMessage)m).Text ); - - // Change the subscription. - consumer.Dispose(); - consumer = session.CreateDurableConsumer((ITopic)destination, "test", "color='blue'", false); - - message = session.CreateTextMessage("2nd"); - // message.setStringProperty("color", "red"); - producer.Send(message); - message = session.CreateTextMessage("3rd"); - // message.setStringProperty("color", "blue"); - producer.Send(message); - - // Selector should skip the 2nd message. - m = consumer.Receive(1000); - Assert.IsNotNull(m); - Assert.AreEqual("3rd", ((ITextMessage)m).Text); - - Assert.IsNull(consumer.ReceiveNoWait()); - } - - } -} - +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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.IO; + +using NUnit.Framework; + +namespace ActiveMQ +{ + [TestFixture] + public class ConsumerTest : TestSupport + { + IConnectionFactory factory; + IConnection connection; + IDestination destination; + + [SetUp] + protected void SetUp() + { + factory = new ConnectionFactory("localhost", 61616); + connection = factory.CreateConnection(); + } + + [TearDown] + protected void TearDown() + { + connection.Dispose(); + } + + [Test] + [Ignore("Not fully implemented yet.")] + public void testDurableConsumerSelectorChange() + { + + // Receive a message with the JMS API + connection.ClientId="test"; + connection.Start(); + + ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); + destination = session.GetTopic("foo"); + IMessageProducer producer = session.CreateProducer(destination); + producer.Persistent = true; + IMessageConsumer consumer = session.CreateDurableConsumer((ITopic)destination, "test", "color='red'", false); + + // Send the messages + ITextMessage message = session.CreateTextMessage("1st"); + //message.SetStringProperty("color", "red"); + producer.Send(message); + + IMessage m = consumer.Receive(1000); + Assert.IsNotNull(m); + Assert.AreEqual("1st", ((ITextMessage)m).Text ); + + // Change the subscription. + consumer.Dispose(); + consumer = session.CreateDurableConsumer((ITopic)destination, "test", "color='blue'", false); + + message = session.CreateTextMessage("2nd"); + // message.setStringProperty("color", "red"); + producer.Send(message); + message = session.CreateTextMessage("3rd"); + // message.setStringProperty("color", "blue"); + producer.Send(message); + + // Selector should skip the 2nd message. + m = consumer.Receive(1000); + Assert.IsNotNull(m); + Assert.AreEqual("3rd", ((ITextMessage)m).Text); + + Assert.IsNull(consumer.ReceiveNoWait()); + } + + } +} + diff --git a/openwire-dotnet/tests/ActiveMQ/EndianTest.cs b/openwire-dotnet/tests/ActiveMQ/EndianTest.cs index a5108d46da..85fb6b29ea 100644 --- a/openwire-dotnet/tests/ActiveMQ/EndianTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/EndianTest.cs @@ -1,76 +1,78 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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 OpenWire.Client.Core; -using System; - -namespace openwire_dotnet -{ - [TestFixture] - public class EndianTest - { - - [Test] - public void TestLongEndian() - { - long value = 0x0102030405060708L; - - long newValue = BaseDataStreamMarshaller.SwitchEndian(value); - - Console.WriteLine("New value: " + newValue); - - Assert.AreEqual(0x0807060504030201L, newValue); - - long actual = BaseDataStreamMarshaller.SwitchEndian(newValue); - - Assert.AreEqual(value, actual); - } - - [Test] - public void TestIntEndian() - { - int value = 0x12345678; - - int newValue = BaseDataStreamMarshaller.SwitchEndian(value); - - Console.WriteLine("New value: " + newValue); - - Assert.AreEqual(0x78563412, newValue); - - int actual = BaseDataStreamMarshaller.SwitchEndian(newValue); - - Assert.AreEqual(value, actual); - } - [Test] - public void TestShortEndian() - { - short value = 0x1234; - - short newValue = BaseDataStreamMarshaller.SwitchEndian(value); - - Console.WriteLine("New value: " + newValue); - - Assert.AreEqual(0x3412, newValue); - - short actual = BaseDataStreamMarshaller.SwitchEndian(newValue); - - Assert.AreEqual(value, actual); - } - } -} - - +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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 System; + +using ActiveMQ.OpenWire; +using ActiveMQ.OpenWire.Commands; + +namespace ActiveMQ +{ + [TestFixture] + public class EndianTest + { + + [Test] + public void TestLongEndian() + { + long value = 0x0102030405060708L; + + long newValue = BaseDataStreamMarshaller.SwitchEndian(value); + + Console.WriteLine("New value: " + newValue); + + Assert.AreEqual(0x0807060504030201L, newValue); + + long actual = BaseDataStreamMarshaller.SwitchEndian(newValue); + + Assert.AreEqual(value, actual); + } + + [Test] + public void TestIntEndian() + { + int value = 0x12345678; + + int newValue = BaseDataStreamMarshaller.SwitchEndian(value); + + Console.WriteLine("New value: " + newValue); + + Assert.AreEqual(0x78563412, newValue); + + int actual = BaseDataStreamMarshaller.SwitchEndian(newValue); + + Assert.AreEqual(value, actual); + } + [Test] + public void TestShortEndian() + { + short value = 0x1234; + + short newValue = BaseDataStreamMarshaller.SwitchEndian(value); + + Console.WriteLine("New value: " + newValue); + + Assert.AreEqual(0x3412, newValue); + + short actual = BaseDataStreamMarshaller.SwitchEndian(newValue); + + Assert.AreEqual(value, actual); + } + } +} + + diff --git a/openwire-dotnet/tests/ActiveMQ/JMSPropertyTest.cs b/openwire-dotnet/tests/ActiveMQ/JMSPropertyTest.cs index ad3003200c..03dad0d9e3 100644 --- a/openwire-dotnet/tests/ActiveMQ/JMSPropertyTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/JMSPropertyTest.cs @@ -1,127 +1,124 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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.IO; - -using NUnit.Framework; - -using OpenWire.Client; -using OpenWire.Client.Core; - -namespace OpenWire.Client -{ - [ TestFixture ] - public class JMSPropertyTest : TestSupport - { - // standard JMS properties - string expectedText = "Hey this works!"; - string correlationID = "abc"; - ITemporaryQueue replyTo; - bool persistent = true; - byte priority = 5; - String type = "FooType"; - String groupID = "MyGroup"; - int groupSeq = 1; - - // custom properties - string customText = "Cheese"; - bool custom1 = true; - byte custom2 = 12; - short custom3 = 0x1234; - int custom4 = 0x12345678; - long custom5 = 0x1234567812345678; - char custom6 = 'J'; - - [ Test ] - public override void SendAndSyncReceive() - { - base.SendAndSyncReceive(); - } - - protected override IMessage CreateMessage(ISession session) - { - ITextMessage message = session.CreateTextMessage(expectedText); - replyTo = session.CreateTemporaryQueue(); - - // lets set the headers - message.JMSCorrelationID = correlationID; - message.JMSReplyTo = replyTo; - message.JMSPersistent = persistent; - message.JMSPriority = priority; - message.JMSType = type; - message.JMSXGroupID = groupID; - message.JMSXGroupSeq = groupSeq; - - // lets set the custom headers - message.Properties["customText"] = customText; - message.Properties["custom1"] = custom1; - message.Properties["custom2"] = custom2; - message.Properties["custom3"] = custom3; - message.Properties["custom4"] = custom4; - message.Properties["custom5"] = custom5; - message.Properties["custom6"] = custom6; - - return message; - } - - protected override void AssertValidMessage(IMessage message) - { - Assert.IsTrue(message is ITextMessage, "Did not receive a ITextMessage!"); - - Console.WriteLine("Received Message: " + message); - - ITextMessage textMessage = (ITextMessage) message; - String text = textMessage.Text; - Assert.AreEqual(expectedText, text, "the message text"); - - // compare standard JMS headers - Assert.AreEqual(correlationID, message.JMSCorrelationID, "JMSCorrelationID"); - Assert.AreEqual(replyTo, message.JMSReplyTo, "JMSReplyTo"); - Assert.AreEqual(persistent, message.JMSPersistent, "JMSPersistent"); - Assert.AreEqual(priority, message.JMSPriority, "JMSPriority"); - Assert.AreEqual(type, message.JMSType, "JMSType"); - Assert.AreEqual(groupID, message.JMSXGroupID, "JMSXGroupID"); - Assert.AreEqual(groupSeq, message.JMSXGroupSeq, "JMSXGroupSeq"); - - // compare custom headers - Assert.AreEqual(customText, message.Properties["customText"], "customText"); - Assert.AreEqual(custom1, message.Properties["custom1"], "custom1"); - Assert.AreEqual(custom2, message.Properties["custom2"], "custom2"); - Assert.AreEqual(custom3, message.Properties["custom3"], "custom3"); - Assert.AreEqual(custom4, message.Properties["custom4"], "custom4"); - // TODO - Assert.AreEqual(custom5, message.Properties["custom5"], "custom5"); - Assert.AreEqual(custom6, message.Properties["custom6"], "custom6"); - - Assert.AreEqual(custom1, message.Properties.GetBool("custom1"), "custom1"); - Assert.AreEqual(custom2, message.Properties.GetByte("custom2"), "custom2"); - Assert.AreEqual(custom3, message.Properties.GetShort("custom3"), "custom3"); - Assert.AreEqual(custom4, message.Properties.GetInt("custom4"), "custom4"); - Assert.AreEqual(custom5, message.Properties.GetLong("custom5"), "custom5"); - Assert.AreEqual(custom6, message.Properties.GetChar("custom6"), "custom6"); - - // lets now look at some standard JMS headers - Console.WriteLine("JMSExpiration: " + message.JMSExpiration); - Console.WriteLine("JMSMessageId: " + message.JMSMessageId); - Console.WriteLine("JMSRedelivered: " + message.JMSRedelivered); - Console.WriteLine("JMSTimestamp: " + message.JMSTimestamp); - Console.WriteLine("JMSXDeliveryCount: " + message.JMSXDeliveryCount); - Console.WriteLine("JMSXProducerTXID: " + message.JMSXProducerTXID); - } - } -} - +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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.IO; + +using NUnit.Framework; + +namespace ActiveMQ +{ + [ TestFixture ] + public class JMSPropertyTest : TestSupport + { + // standard JMS properties + string expectedText = "Hey this works!"; + string correlationID = "abc"; + ITemporaryQueue replyTo; + bool persistent = true; + byte priority = 5; + String type = "FooType"; + String groupID = "MyGroup"; + int groupSeq = 1; + + // custom properties + string customText = "Cheese"; + bool custom1 = true; + byte custom2 = 12; + short custom3 = 0x1234; + int custom4 = 0x12345678; + long custom5 = 0x1234567812345678; + char custom6 = 'J'; + + [ Test ] + public override void SendAndSyncReceive() + { + base.SendAndSyncReceive(); + } + + protected override IMessage CreateMessage(ISession session) + { + ITextMessage message = session.CreateTextMessage(expectedText); + replyTo = session.CreateTemporaryQueue(); + + // lets set the headers + message.JMSCorrelationID = correlationID; + message.JMSReplyTo = replyTo; + message.JMSPersistent = persistent; + message.JMSPriority = priority; + message.JMSType = type; + message.JMSXGroupID = groupID; + message.JMSXGroupSeq = groupSeq; + + // lets set the custom headers + message.Properties["customText"] = customText; + message.Properties["custom1"] = custom1; + message.Properties["custom2"] = custom2; + message.Properties["custom3"] = custom3; + message.Properties["custom4"] = custom4; + message.Properties["custom5"] = custom5; + message.Properties["custom6"] = custom6; + + return message; + } + + protected override void AssertValidMessage(IMessage message) + { + Assert.IsTrue(message is ITextMessage, "Did not receive a ITextMessage!"); + + Console.WriteLine("Received Message: " + message); + + ITextMessage textMessage = (ITextMessage) message; + String text = textMessage.Text; + Assert.AreEqual(expectedText, text, "the message text"); + + // compare standard JMS headers + Assert.AreEqual(correlationID, message.JMSCorrelationID, "JMSCorrelationID"); + Assert.AreEqual(replyTo, message.JMSReplyTo, "JMSReplyTo"); + Assert.AreEqual(persistent, message.JMSPersistent, "JMSPersistent"); + Assert.AreEqual(priority, message.JMSPriority, "JMSPriority"); + Assert.AreEqual(type, message.JMSType, "JMSType"); + Assert.AreEqual(groupID, message.JMSXGroupID, "JMSXGroupID"); + Assert.AreEqual(groupSeq, message.JMSXGroupSeq, "JMSXGroupSeq"); + + // compare custom headers + Assert.AreEqual(customText, message.Properties["customText"], "customText"); + Assert.AreEqual(custom1, message.Properties["custom1"], "custom1"); + Assert.AreEqual(custom2, message.Properties["custom2"], "custom2"); + Assert.AreEqual(custom3, message.Properties["custom3"], "custom3"); + Assert.AreEqual(custom4, message.Properties["custom4"], "custom4"); + // TODO + Assert.AreEqual(custom5, message.Properties["custom5"], "custom5"); + Assert.AreEqual(custom6, message.Properties["custom6"], "custom6"); + + Assert.AreEqual(custom1, message.Properties.GetBool("custom1"), "custom1"); + Assert.AreEqual(custom2, message.Properties.GetByte("custom2"), "custom2"); + Assert.AreEqual(custom3, message.Properties.GetShort("custom3"), "custom3"); + Assert.AreEqual(custom4, message.Properties.GetInt("custom4"), "custom4"); + Assert.AreEqual(custom5, message.Properties.GetLong("custom5"), "custom5"); + Assert.AreEqual(custom6, message.Properties.GetChar("custom6"), "custom6"); + + // lets now look at some standard JMS headers + Console.WriteLine("JMSExpiration: " + message.JMSExpiration); + Console.WriteLine("JMSMessageId: " + message.JMSMessageId); + Console.WriteLine("JMSRedelivered: " + message.JMSRedelivered); + Console.WriteLine("JMSTimestamp: " + message.JMSTimestamp); + Console.WriteLine("JMSXDeliveryCount: " + message.JMSXDeliveryCount); + Console.WriteLine("JMSXProducerTXID: " + message.JMSXProducerTXID); + } + } +} + diff --git a/openwire-dotnet/tests/ActiveMQ/MapMessageTest.cs b/openwire-dotnet/tests/ActiveMQ/MapMessageTest.cs index 51de428ec1..6092105975 100644 --- a/openwire-dotnet/tests/ActiveMQ/MapMessageTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/MapMessageTest.cs @@ -1,95 +1,92 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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.IO; - -using NUnit.Framework; - -using OpenWire.Client; -using OpenWire.Client.Core; - -namespace OpenWire.Client -{ - [ TestFixture ] - public class MapMessageTest : TestSupport - { - bool a = true; - byte b = 123; - char c = 'c'; - short d = 0x1234; - int e = 0x12345678; - long f = 0x1234567812345678; - string g = "Hello World!"; - - [ Test ] - public override void SendAndSyncReceive() - { - base.SendAndSyncReceive(); - } - - protected override IMessage CreateMessage(ISession session) - { - IMapMessage message = session.CreateMapMessage(); - - message.Body["a"] = a; - message.Body["b"] = b; - message.Body["c"] = c; - message.Body["d"] = d; - message.Body["e"] = e; - message.Body["f"] = f; - message.Body["g"] = g; - - return message; - } - - protected override void AssertValidMessage(IMessage message) - { - Assert.IsTrue(message is IMapMessage, "Did not receive a MapMessage!"); - IMapMessage mapMessage = (IMapMessage) message; - - Console.WriteLine("Received MapMessage: " + message); - Console.WriteLine("Received Count: " + mapMessage.Body.Count); - - Assert.AreEqual(ToHex(f), ToHex(mapMessage.Body.GetLong("f")), "map entry: f as hex"); - - // use generic API to access entries - Assert.AreEqual(a, mapMessage.Body["a"], "generic map entry: a"); - Assert.AreEqual(b, mapMessage.Body["b"], "generic map entry: b"); - Assert.AreEqual(c, mapMessage.Body["c"], "generic map entry: c"); - Assert.AreEqual(d, mapMessage.Body["d"], "generic map entry: d"); - Assert.AreEqual(e, mapMessage.Body["e"], "generic map entry: e"); - Assert.AreEqual(f, mapMessage.Body["f"], "generic map entry: f"); - Assert.AreEqual(g, mapMessage.Body["g"], "generic map entry: g"); - - // use type safe APIs - Assert.AreEqual(a, mapMessage.Body.GetBool("a"), "map entry: a"); - Assert.AreEqual(b, mapMessage.Body.GetByte("b"), "map entry: b"); - Assert.AreEqual(c, mapMessage.Body.GetChar("c"), "map entry: c"); - Assert.AreEqual(d, mapMessage.Body.GetShort("d"), "map entry: d"); - Assert.AreEqual(e, mapMessage.Body.GetInt("e"), "map entry: e"); - Assert.AreEqual(f, mapMessage.Body.GetLong("f"), "map entry: f"); - Assert.AreEqual(g, mapMessage.Body.GetString("g"), "map entry: g"); - - - } - - protected string ToHex(long value) - { - return String.Format("{0:x}", value); - } - } -} +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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.IO; + +using NUnit.Framework; + +namespace ActiveMQ +{ + [ TestFixture ] + public class MapMessageTest : TestSupport + { + bool a = true; + byte b = 123; + char c = 'c'; + short d = 0x1234; + int e = 0x12345678; + long f = 0x1234567812345678; + string g = "Hello World!"; + + [ Test ] + public override void SendAndSyncReceive() + { + base.SendAndSyncReceive(); + } + + protected override IMessage CreateMessage(ISession session) + { + IMapMessage message = session.CreateMapMessage(); + + message.Body["a"] = a; + message.Body["b"] = b; + message.Body["c"] = c; + message.Body["d"] = d; + message.Body["e"] = e; + message.Body["f"] = f; + message.Body["g"] = g; + + return message; + } + + protected override void AssertValidMessage(IMessage message) + { + Assert.IsTrue(message is IMapMessage, "Did not receive a MapMessage!"); + IMapMessage mapMessage = (IMapMessage) message; + + Console.WriteLine("Received MapMessage: " + message); + Console.WriteLine("Received Count: " + mapMessage.Body.Count); + + Assert.AreEqual(ToHex(f), ToHex(mapMessage.Body.GetLong("f")), "map entry: f as hex"); + + // use generic API to access entries + Assert.AreEqual(a, mapMessage.Body["a"], "generic map entry: a"); + Assert.AreEqual(b, mapMessage.Body["b"], "generic map entry: b"); + Assert.AreEqual(c, mapMessage.Body["c"], "generic map entry: c"); + Assert.AreEqual(d, mapMessage.Body["d"], "generic map entry: d"); + Assert.AreEqual(e, mapMessage.Body["e"], "generic map entry: e"); + Assert.AreEqual(f, mapMessage.Body["f"], "generic map entry: f"); + Assert.AreEqual(g, mapMessage.Body["g"], "generic map entry: g"); + + // use type safe APIs + Assert.AreEqual(a, mapMessage.Body.GetBool("a"), "map entry: a"); + Assert.AreEqual(b, mapMessage.Body.GetByte("b"), "map entry: b"); + Assert.AreEqual(c, mapMessage.Body.GetChar("c"), "map entry: c"); + Assert.AreEqual(d, mapMessage.Body.GetShort("d"), "map entry: d"); + Assert.AreEqual(e, mapMessage.Body.GetInt("e"), "map entry: e"); + Assert.AreEqual(f, mapMessage.Body.GetLong("f"), "map entry: f"); + Assert.AreEqual(g, mapMessage.Body.GetString("g"), "map entry: g"); + + + } + + protected string ToHex(long value) + { + return String.Format("{0:x}", value); + } + } +} diff --git a/openwire-dotnet/tests/ActiveMQ/OpenWire/BooleanStreamTest.cs b/openwire-dotnet/tests/ActiveMQ/OpenWire/BooleanStreamTest.cs index 145c9df22a..8c7814fd17 100644 --- a/openwire-dotnet/tests/ActiveMQ/OpenWire/BooleanStreamTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/OpenWire/BooleanStreamTest.cs @@ -19,10 +19,7 @@ using System.IO; using NUnit.Framework; -using OpenWire.Client; -using OpenWire.Client.Core; - -namespace OpenWire.Client.Core +namespace ActiveMQ.OpenWire { [TestFixture] public class BooleanStreamTest : TestSupport diff --git a/openwire-dotnet/tests/ActiveMQ/TestMain.cs b/openwire-dotnet/tests/ActiveMQ/TestMain.cs index 02b1e0c540..47ba1c9a64 100644 --- a/openwire-dotnet/tests/ActiveMQ/TestMain.cs +++ b/openwire-dotnet/tests/ActiveMQ/TestMain.cs @@ -1,80 +1,79 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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.IO; - -using OpenWire.Client; -using OpenWire.Client.Core; -using OpenWire.Client.Commands; - -namespace openwire_dotnet -{ - public class TestMain - { - public static void Main(string[] args) - { - try - { - Console.WriteLine("About to connect to ActiveMQ"); - - // START SNIPPET: demo - IConnectionFactory factory = new ConnectionFactory("localhost", 61616); - using (IConnection connection = factory.CreateConnection()) - { - Console.WriteLine("Created a connection!"); - - ISession session = connection.CreateSession(); - - IDestination destination = session.GetQueue("FOO.BAR"); - Console.WriteLine("Using destination: " + destination); - - // lets create a consumer and producer - IMessageConsumer consumer = session.CreateConsumer(destination); - - IMessageProducer producer = session.CreateProducer(destination); - producer.Persistent = true; - - // lets send a message - ITextMessage request = session.CreateTextMessage("Hello World!"); - request.JMSCorrelationID = "abc"; - request.JMSXGroupID = "cheese"; - request.Properties["myHeader"] = "James"; - - producer.Send(request); - - // lets consume a message - ActiveMQTextMessage message = (ActiveMQTextMessage) consumer.Receive(); - if (message == null) - { - Console.WriteLine("No message received!"); - } - else - { - Console.WriteLine("Received message with ID: " + message.JMSMessageId); - Console.WriteLine("Received message with text: " + message.Text); - } - } - // END SNIPPET: demo - } - catch (Exception e) - { - Console.WriteLine("Caught: " + e); - Console.WriteLine("Stack: " + e.StackTrace); - } - } - } -} +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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.IO; + +using ActiveMQ.OpenWire; +using ActiveMQ.OpenWire.Commands; + +namespace ActiveMQ +{ + public class TestMain + { + public static void Main(string[] args) + { + try + { + Console.WriteLine("About to connect to ActiveMQ"); + + // START SNIPPET: demo + IConnectionFactory factory = new ConnectionFactory("localhost", 61616); + using (IConnection connection = factory.CreateConnection()) + { + Console.WriteLine("Created a connection!"); + + ISession session = connection.CreateSession(); + + IDestination destination = session.GetQueue("FOO.BAR"); + Console.WriteLine("Using destination: " + destination); + + // lets create a consumer and producer + IMessageConsumer consumer = session.CreateConsumer(destination); + + IMessageProducer producer = session.CreateProducer(destination); + producer.Persistent = true; + + // lets send a message + ITextMessage request = session.CreateTextMessage("Hello World!"); + request.JMSCorrelationID = "abc"; + request.JMSXGroupID = "cheese"; + request.Properties["myHeader"] = "James"; + + producer.Send(request); + + // lets consume a message + ActiveMQTextMessage message = (ActiveMQTextMessage) consumer.Receive(); + if (message == null) + { + Console.WriteLine("No message received!"); + } + else + { + Console.WriteLine("Received message with ID: " + message.JMSMessageId); + Console.WriteLine("Received message with text: " + message.Text); + } + } + // END SNIPPET: demo + } + catch (Exception e) + { + Console.WriteLine("Caught: " + e); + Console.WriteLine("Stack: " + e.StackTrace); + } + } + } +} diff --git a/openwire-dotnet/tests/ActiveMQ/TestSupport.cs b/openwire-dotnet/tests/ActiveMQ/TestSupport.cs index 1e82ffa7c2..85c6616c9e 100644 --- a/openwire-dotnet/tests/ActiveMQ/TestSupport.cs +++ b/openwire-dotnet/tests/ActiveMQ/TestSupport.cs @@ -19,11 +19,7 @@ using System.IO; using NUnit.Framework; -using OpenWire.Client; -using OpenWire.Client.Core; - - -namespace OpenWire.Client +namespace ActiveMQ { /// diff --git a/openwire-dotnet/tests/ActiveMQ/TransactionTest.cs b/openwire-dotnet/tests/ActiveMQ/TransactionTest.cs index 2b26bbb3d6..1f784fc2ec 100644 --- a/openwire-dotnet/tests/ActiveMQ/TransactionTest.cs +++ b/openwire-dotnet/tests/ActiveMQ/TransactionTest.cs @@ -1,290 +1,287 @@ -/* - * Copyright 2006 The Apache Software Foundation or its licensors, as - * applicable. - * - * Licensed 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.IO; - -using NUnit.Framework; - -using OpenWire.Client; -using OpenWire.Client.Core; -using System.Collections; - -namespace OpenWire.Client -{ - [TestFixture] - public class TransactionTest : TestSupport - { - private static int destinationCounter; - - IDestination destination; - IConnection connection; - ISession session; - IMessageProducer producer; - IMessageConsumer consumer; - - [SetUp] - public void SetUp() - { - Connect(); - - // lets consume any outstanding messages from previous test runs - while (consumer.Receive(1000) != null) - { - } - session.Commit(); - } - - - - [TearDown] - public void TearDown() - { - Disconnect(); - } - - [Test] - public void TestSendRollback() - { - IMessage[] outbound = new IMessage[]{ - session.CreateTextMessage("First Message"), - session.CreateTextMessage("Second Message") - }; - - //sends a message - producer.Send(outbound[0]); - session.Commit(); - - //sends a message that gets rollbacked - producer.Send(session.CreateTextMessage("I'm going to get rolled back.")); - session.Rollback(); - - //sends a message - producer.Send(outbound[1]); - session.Commit(); - - //receives the first message - ArrayList messages = new ArrayList(); - Console.WriteLine("About to consume message 1"); - IMessage message = consumer.Receive(1000); - messages.Add(message); - Console.WriteLine("Received: " + message); - - //receives the second message - Console.WriteLine("About to consume message 2"); - message = consumer.Receive(4000); - messages.Add(message); - Console.WriteLine("Received: " + message); - - //validates that the rollbacked was not consumed - session.Commit(); - IMessage[] inbound = new IMessage[messages.Count]; - messages.CopyTo(inbound); - AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); - } - - [Test] - public void TestSendSessionClose() - { - IMessage[] outbound = new IMessage[]{ - session.CreateTextMessage("First Message"), - session.CreateTextMessage("Second Message") - }; - - //sends a message - producer.Send(outbound[0]); - session.Commit(); - - //sends a message that gets rollbacked - producer.Send(session.CreateTextMessage("I'm going to get rolled back.")); - consumer.Dispose(); - session.Dispose(); - - Reconnect(); - - //sends a message - producer.Send(outbound[1]); - session.Commit(); - - //receives the first message - ArrayList messages = new ArrayList(); - Console.WriteLine("About to consume message 1"); - IMessage message = consumer.Receive(1000); - messages.Add(message); - Console.WriteLine("Received: " + message); - - //receives the second message - Console.WriteLine("About to consume message 2"); - message = consumer.Receive(4000); - messages.Add(message); - Console.WriteLine("Received: " + message); - - //validates that the rollbacked was not consumed - session.Commit(); - IMessage[] inbound = new IMessage[messages.Count]; - messages.CopyTo(inbound); - AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); - } - - [Test] - public void TestReceiveRollback() - { - IMessage[] outbound = new IMessage[]{ - session.CreateTextMessage("First Message"), - session.CreateTextMessage("Second Message") - }; - - //sent both messages - producer.Send(outbound[0]); - producer.Send(outbound[1]); - session.Commit(); - - Console.WriteLine("Sent 0: " + outbound[0]); - Console.WriteLine("Sent 1: " + outbound[1]); - - ArrayList messages = new ArrayList(); - IMessage message = consumer.Receive(1000); - messages.Add(message); - Assert.AreEqual(outbound[0], message); - session.Commit(); - - // rollback so we can get that last message again. - message = consumer.Receive(1000); - Assert.IsNotNull(message); - Assert.AreEqual(outbound[1], message); - session.Rollback(); - - // Consume again.. the previous message should - // get redelivered. - message = consumer.Receive(5000); - Assert.IsNotNull(message, "Should have re-received the message again!"); - messages.Add(message); - session.Commit(); - - IMessage[] inbound = new IMessage[messages.Count]; - messages.CopyTo(inbound); - AssertTextMessagesEqual("Rollback did not work", outbound, inbound); - } - - - [Test] - public void TestReceiveTwoThenRollback() - { - IMessage[] outbound = new IMessage[]{ - session.CreateTextMessage("First Message"), - session.CreateTextMessage("Second Message") - }; - - producer.Send(outbound[0]); - producer.Send(outbound[1]); - session.Commit(); - - Console.WriteLine("Sent 0: " + outbound[0]); - Console.WriteLine("Sent 1: " + outbound[1]); - - ArrayList messages = new ArrayList(); - IMessage message = consumer.Receive(1000); - AssertTextMessageEqual("first mesage received before rollback", outbound[0], message); - - message = consumer.Receive(1000); - Assert.IsNotNull(message); - AssertTextMessageEqual("second message received before rollback", outbound[1], message); - session.Rollback(); - - // Consume again.. the previous message should - // get redelivered. - message = consumer.Receive(5000); - Assert.IsNotNull(message, "Should have re-received the first message again!"); - messages.Add(message); - AssertTextMessageEqual("first message received after rollback", outbound[0], message); - - message = consumer.Receive(5000); - Assert.IsNotNull(message, "Should have re-received the second message again!"); - messages.Add(message); - AssertTextMessageEqual("second message received after rollback", outbound[1], message); - - Assert.IsNull(consumer.ReceiveNoWait()); - session.Commit(); - - IMessage[] inbound = new IMessage[messages.Count]; - messages.CopyTo(inbound); - AssertTextMessagesEqual("Rollback did not work", outbound, inbound); - } - - protected override string CreateDestinationName() - { - // TODO - how can we get the test name? - return base.CreateDestinationName() + (++destinationCounter); - } - - protected void AssertTextMessagesEqual(String message, IMessage[] expected, IMessage[] actual) - { - Assert.AreEqual(expected.Length, actual.Length, "Incorrect number of messages received"); - - for (int i = 0; i < expected.Length; i++) - { - AssertTextMessageEqual(message + ". Index: " + i, expected[i], actual[i]); - } - } - - protected void AssertTextMessageEqual(String message, IMessage expected, IMessage actual) - { - Assert.IsTrue(expected is ITextMessage, "expected object not a text message"); - Assert.IsTrue(actual is ITextMessage, "actual object not a text message"); - - String expectedText = ((ITextMessage) expected).Text; - String actualText = ((ITextMessage) actual).Text; - - Assert.AreEqual(expectedText, actualText, message); - } - - protected void Connect() - { - IConnectionFactory factory = new ConnectionFactory("localhost", 61616); - - connection = factory.CreateConnection(); - - session = connection.CreateSession(AcknowledgementMode.Transactional); - - // reuse the same destination if we reconnect - if (destination == null) - { - destination = CreateDestination(session); - } - - consumer = session.CreateConsumer(destination); - - producer = session.CreateProducer(destination); - } - - - protected void Disconnect() - { - if (connection != null) - { - connection.Dispose(); - connection = null; - } - } - - protected void Reconnect() - { - Disconnect(); - Connect(); - } - - } -} +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed 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.IO; + +using NUnit.Framework; +using System.Collections; + +namespace ActiveMQ +{ + [TestFixture] + public class TransactionTest : TestSupport + { + private static int destinationCounter; + + IDestination destination; + IConnection connection; + ISession session; + IMessageProducer producer; + IMessageConsumer consumer; + + [SetUp] + public void SetUp() + { + Connect(); + + // lets consume any outstanding messages from previous test runs + while (consumer.Receive(1000) != null) + { + } + session.Commit(); + } + + + + [TearDown] + public void TearDown() + { + Disconnect(); + } + + [Test] + public void TestSendRollback() + { + IMessage[] outbound = new IMessage[]{ + session.CreateTextMessage("First Message"), + session.CreateTextMessage("Second Message") + }; + + //sends a message + producer.Send(outbound[0]); + session.Commit(); + + //sends a message that gets rollbacked + producer.Send(session.CreateTextMessage("I'm going to get rolled back.")); + session.Rollback(); + + //sends a message + producer.Send(outbound[1]); + session.Commit(); + + //receives the first message + ArrayList messages = new ArrayList(); + Console.WriteLine("About to consume message 1"); + IMessage message = consumer.Receive(1000); + messages.Add(message); + Console.WriteLine("Received: " + message); + + //receives the second message + Console.WriteLine("About to consume message 2"); + message = consumer.Receive(4000); + messages.Add(message); + Console.WriteLine("Received: " + message); + + //validates that the rollbacked was not consumed + session.Commit(); + IMessage[] inbound = new IMessage[messages.Count]; + messages.CopyTo(inbound); + AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); + } + + [Test] + public void TestSendSessionClose() + { + IMessage[] outbound = new IMessage[]{ + session.CreateTextMessage("First Message"), + session.CreateTextMessage("Second Message") + }; + + //sends a message + producer.Send(outbound[0]); + session.Commit(); + + //sends a message that gets rollbacked + producer.Send(session.CreateTextMessage("I'm going to get rolled back.")); + consumer.Dispose(); + session.Dispose(); + + Reconnect(); + + //sends a message + producer.Send(outbound[1]); + session.Commit(); + + //receives the first message + ArrayList messages = new ArrayList(); + Console.WriteLine("About to consume message 1"); + IMessage message = consumer.Receive(1000); + messages.Add(message); + Console.WriteLine("Received: " + message); + + //receives the second message + Console.WriteLine("About to consume message 2"); + message = consumer.Receive(4000); + messages.Add(message); + Console.WriteLine("Received: " + message); + + //validates that the rollbacked was not consumed + session.Commit(); + IMessage[] inbound = new IMessage[messages.Count]; + messages.CopyTo(inbound); + AssertTextMessagesEqual("Rollback did not work.", outbound, inbound); + } + + [Test] + public void TestReceiveRollback() + { + IMessage[] outbound = new IMessage[]{ + session.CreateTextMessage("First Message"), + session.CreateTextMessage("Second Message") + }; + + //sent both messages + producer.Send(outbound[0]); + producer.Send(outbound[1]); + session.Commit(); + + Console.WriteLine("Sent 0: " + outbound[0]); + Console.WriteLine("Sent 1: " + outbound[1]); + + ArrayList messages = new ArrayList(); + IMessage message = consumer.Receive(1000); + messages.Add(message); + Assert.AreEqual(outbound[0], message); + session.Commit(); + + // rollback so we can get that last message again. + message = consumer.Receive(1000); + Assert.IsNotNull(message); + Assert.AreEqual(outbound[1], message); + session.Rollback(); + + // Consume again.. the previous message should + // get redelivered. + message = consumer.Receive(5000); + Assert.IsNotNull(message, "Should have re-received the message again!"); + messages.Add(message); + session.Commit(); + + IMessage[] inbound = new IMessage[messages.Count]; + messages.CopyTo(inbound); + AssertTextMessagesEqual("Rollback did not work", outbound, inbound); + } + + + [Test] + public void TestReceiveTwoThenRollback() + { + IMessage[] outbound = new IMessage[]{ + session.CreateTextMessage("First Message"), + session.CreateTextMessage("Second Message") + }; + + producer.Send(outbound[0]); + producer.Send(outbound[1]); + session.Commit(); + + Console.WriteLine("Sent 0: " + outbound[0]); + Console.WriteLine("Sent 1: " + outbound[1]); + + ArrayList messages = new ArrayList(); + IMessage message = consumer.Receive(1000); + AssertTextMessageEqual("first mesage received before rollback", outbound[0], message); + + message = consumer.Receive(1000); + Assert.IsNotNull(message); + AssertTextMessageEqual("second message received before rollback", outbound[1], message); + session.Rollback(); + + // Consume again.. the previous message should + // get redelivered. + message = consumer.Receive(5000); + Assert.IsNotNull(message, "Should have re-received the first message again!"); + messages.Add(message); + AssertTextMessageEqual("first message received after rollback", outbound[0], message); + + message = consumer.Receive(5000); + Assert.IsNotNull(message, "Should have re-received the second message again!"); + messages.Add(message); + AssertTextMessageEqual("second message received after rollback", outbound[1], message); + + Assert.IsNull(consumer.ReceiveNoWait()); + session.Commit(); + + IMessage[] inbound = new IMessage[messages.Count]; + messages.CopyTo(inbound); + AssertTextMessagesEqual("Rollback did not work", outbound, inbound); + } + + protected override string CreateDestinationName() + { + // TODO - how can we get the test name? + return base.CreateDestinationName() + (++destinationCounter); + } + + protected void AssertTextMessagesEqual(String message, IMessage[] expected, IMessage[] actual) + { + Assert.AreEqual(expected.Length, actual.Length, "Incorrect number of messages received"); + + for (int i = 0; i < expected.Length; i++) + { + AssertTextMessageEqual(message + ". Index: " + i, expected[i], actual[i]); + } + } + + protected void AssertTextMessageEqual(String message, IMessage expected, IMessage actual) + { + Assert.IsTrue(expected is ITextMessage, "expected object not a text message"); + Assert.IsTrue(actual is ITextMessage, "actual object not a text message"); + + String expectedText = ((ITextMessage) expected).Text; + String actualText = ((ITextMessage) actual).Text; + + Assert.AreEqual(expectedText, actualText, message); + } + + protected void Connect() + { + IConnectionFactory factory = new ConnectionFactory("localhost", 61616); + + connection = factory.CreateConnection(); + + session = connection.CreateSession(AcknowledgementMode.Transactional); + + // reuse the same destination if we reconnect + if (destination == null) + { + destination = CreateDestination(session); + } + + consumer = session.CreateConsumer(destination); + + producer = session.CreateProducer(destination); + } + + + protected void Disconnect() + { + if (connection != null) + { + connection.Dispose(); + connection = null; + } + } + + protected void Reconnect() + { + Disconnect(); + Connect(); + } + + } +} diff --git a/openwire-dotnet/tests/tests.csproj b/openwire-dotnet/tests/tests.csproj index abdf55927c..429ef3d4d2 100644 --- a/openwire-dotnet/tests/tests.csproj +++ b/openwire-dotnet/tests/tests.csproj @@ -34,25 +34,25 @@ - - - - - - - - - - - - - - - src {F7BA9EF7-ADF7-40EF-9A9E-206649DBB10C} + + + + + + + + + + + + + + +