You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2008/02/12 23:52:31 UTC
svn commit: r627163 [2/2] - in /activemq/activemq-dotnet/Apache.NMS/trunk:
./ src/main/csharp/ src/test/csharp/
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs?rev=627163&r1=627162&r2=627163&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs Tue Feb 12 14:52:29 2008
@@ -1,150 +1,215 @@
-/*
- * 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;
-using System.Reflection;
-using System.IO;
-
-namespace Apache.NMS
-{
- public class NMSConnectionFactory : IConnectionFactory
- {
- IConnectionFactory factory;
-
- /// <summary>
- /// The ConnectionFactory object must define a constructor that takes as a minimum a Uri object.
- /// Any additional parameters are optional, but will typically include a Client ID string.
- /// </summary>
- public NMSConnectionFactory(string uri, params object[] constructorParams)
- {
- factory = CreateConnectionFactory(uri, constructorParams);
- }
-
- /// <summary>
- /// Finds the Type associated with the given scheme. This searches all loaded assembiles
- /// for a resouce called Apache.NMS.NMSFactory.${scheme} and expects it to conatain
- /// the name of the Type assoicated with the scheme.
- /// </summary>
- public static IConnectionFactory CreateConnectionFactory(string uri, params object[] constructorParams)
- {
- try
- {
- // TODO: perhaps we should not use Uri to parse the string.. some implemenations my use non- Uri parsable
- // URIs.
- string scheme = new Uri(uri).Scheme;
- Type type = GetTypeForScheme(scheme);
-
- // If an implementation was found.. try to instanciate it..
- if (type != null)
- {
- object[] parameters = GetParameters(uri, constructorParams);
- return (Apache.NMS.IConnectionFactory)Activator.CreateInstance(type, parameters);
- }
- else
- {
- throw new NMSException("No IConnectionFactory implementation found for connection URI: " + uri);
- }
- }
- catch (NMSException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new NMSException("Could not create the IConnectionFactory implementation: " + ex.Message, ex);
- }
- }
-
-
- /// <summary>
- /// Finds the Type associated with the given scheme. This searches all loaded assembiles
- /// for a resouce called Apache.NMS.NMSFactory.${scheme} and expects it to conatain
- /// the name of the Type assoicated with the scheme.
- /// </summary>
- private static Type GetTypeForScheme(String scheme) {
-
- // TODO: if this scanning is too slow, we should cache the results in a scheme->Type map
- Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
- foreach (Assembly assembly in assemblies)
- {
- string resourceFile = assembly.GetName().Name + "." + "Apache.NMS.NMSConnectionFactory." + scheme;
- Stream fs = assembly.GetManifestResourceStream(resourceFile);
- if (fs != null)
- {
- // Found it..
- using (StreamReader sr = new StreamReader(fs))
- {
- try
- {
- String className = sr.ReadLine();
- return assembly.GetType(className, true, true);
- }
- catch (Exception e)
- {
- Tracer.ErrorFormat("Error creating ConnectionFactory from resource file '{0}': {1}", resourceFile, e.Message);
- }
- }
- }
- }
- return null;
- }
-
- /// <summary>
- /// Create an object array containing the parameters to pass to the constructor.
- /// </summary>
- /// <param name="firstParam"></param>
- /// <param name="varParams"></param>
- /// <returns></returns>
- private static object[] GetParameters(object firstParam, params object[] varParams)
- {
- ArrayList paramList = new ArrayList();
- paramList.Add(firstParam);
- foreach(object param in varParams)
- {
- paramList.Add(param);
- }
- return paramList.ToArray();
- }
-
- /// <summary>
- /// Creates a new connection
- /// </summary>
- public IConnection CreateConnection()
- {
- return factory.CreateConnection();
- }
-
- /// <summary>
- /// Creates a new connection with the given user name and password
- /// </summary>
- public IConnection CreateConnection(string userName, string password)
- {
- return factory.CreateConnection(userName, password);
- }
- /// <summary>
- /// The actual IConnectionFactory implementation that is being used. This implemenation
- /// depends on the scheme of the URI used when constructed.
- /// </summary>
- public IConnectionFactory ConnectionFactory
- {
- get
- {
- return factory;
- }
- }
- }
-}
+/*
+ * 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;
+using System.IO;
+using System.Reflection;
+using System.Xml;
+
+namespace Apache.NMS
+{
+ public class NMSConnectionFactory : IConnectionFactory
+ {
+ protected readonly IConnectionFactory factory;
+
+ /// <summary>
+ /// The ConnectionFactory object must define a constructor that takes as a minimum a Uri object.
+ /// Any additional parameters are optional, but will typically include a Client ID string.
+ /// </summary>
+ /// <param name="providerURI"></param>
+ /// <param name="constructorParams"></param>
+ public NMSConnectionFactory(string providerURI, params object[] constructorParams)
+ : this(new Uri(providerURI), constructorParams)
+ {
+ }
+
+ /// <summary>
+ /// The ConnectionFactory object must define a constructor that takes as a minimum a Uri object.
+ /// Any additional parameters are optional, but will typically include a Client ID string.
+ /// </summary>
+ /// <param name="uriProvider"></param>
+ /// <param name="constructorParams"></param>
+ public NMSConnectionFactory(Uri uriProvider, params object[] constructorParams)
+ {
+ this.factory = CreateConnectionFactory(uriProvider, constructorParams);
+ }
+
+ /// <summary>
+ /// Create a connection factory that can create connections for the given scheme in the URI.
+ /// </summary>
+ /// <param name="uriProvider"></param>
+ /// <param name="constructorParams"></param>
+ /// <returns></returns>
+ public static IConnectionFactory CreateConnectionFactory(Uri uriProvider, params object[] constructorParams)
+ {
+ IConnectionFactory connectionFactory = null;
+
+ try
+ {
+ Type factoryType = GetTypeForScheme(uriProvider.Scheme);
+
+ // If an implementation was found, try to instantiate it.
+ if(factoryType != null)
+ {
+ object[] parameters = MakeParameterArray(uriProvider, constructorParams);
+ connectionFactory = (IConnectionFactory) Activator.CreateInstance(factoryType, parameters);
+ }
+
+ if(null == connectionFactory)
+ {
+ throw new NMSConnectionException("No IConnectionFactory implementation found for connection URI: " + uriProvider);
+ }
+ }
+ catch(NMSConnectionException)
+ {
+ throw;
+ }
+ catch(Exception ex)
+ {
+ throw new NMSConnectionException("Could not create the IConnectionFactory implementation: " + ex.Message, ex);
+ }
+
+ return connectionFactory;
+ }
+
+ /// <summary>
+ /// Finds the Type associated with the given scheme.
+ /// </summary>
+ /// <param name="scheme"></param>
+ /// <returns></returns>
+ private static Type GetTypeForScheme(string scheme)
+ {
+ string assemblyFileName;
+ string factoryClassName;
+ Type factoryType = null;
+
+ if(LookupConnectionFactoryInfo(scheme, out assemblyFileName, out factoryClassName))
+ {
+ Assembly assembly = Assembly.LoadFrom(assemblyFileName);
+
+ if(null != assembly)
+ {
+ factoryType = assembly.GetType(factoryClassName, true, true);
+ }
+ }
+
+ return factoryType;
+ }
+
+ /// <summary>
+ /// Lookup the connection factory assembly filename and class name.
+ /// Read an external configuration file that maps scheme to provider implementation.
+ /// Load XML config files named: nmsprovider-{scheme}.config
+ /// Following is a sample configuration file named nmsprovider-jms.config. Replace
+ /// the parenthesis with angle brackets for proper XML formatting.
+ ///
+ /// (?xml version="1.0" encoding="utf-8" ?)
+ /// (configuration)
+ /// (provider assembly="MyCompany.NMS.JMSProvider.dll" classFactory="MyCompany.NMS.JMSProvider.ConnectionFactory"/)
+ /// (/configuration)
+ ///
+ /// This configuration file would be loaded and parsed when a connection uri with a scheme of 'jms'
+ /// is used for the provider. In this example the connection string might look like:
+ /// jms://localhost:7222
+ ///
+ /// </summary>
+ /// <param name="scheme"></param>
+ /// <param name="assemblyFileName"></param>
+ /// <param name="factoryClassName"></param>
+ /// <returns></returns>
+ private static bool LookupConnectionFactoryInfo(string scheme, out string assemblyFileName, out string factoryClassName)
+ {
+ string configFileName = String.Format("nmsprovider-{0}.config", scheme.ToLower());
+ bool foundFactory = false;
+
+ assemblyFileName = String.Empty;
+ factoryClassName = String.Empty;
+
+ try
+ {
+ if(File.Exists(configFileName))
+ {
+ XmlDocument configDoc = new XmlDocument();
+
+ configDoc.Load(configFileName);
+ XmlElement providerNode = (XmlElement) configDoc.SelectSingleNode("/configuration/provider");
+
+ if(null != providerNode)
+ {
+ assemblyFileName = providerNode.GetAttribute("assembly");
+ factoryClassName = providerNode.GetAttribute("classFactory");
+ if(String.Empty != assemblyFileName && String.Empty != factoryClassName)
+ {
+ foundFactory = true;
+ }
+ }
+ }
+ }
+ catch
+ {
+ }
+
+ return foundFactory;
+ }
+
+ /// <summary>
+ /// Create an object array containing the parameters to pass to the constructor.
+ /// </summary>
+ /// <param name="firstParam"></param>
+ /// <param name="varParams"></param>
+ /// <returns></returns>
+ private static object[] MakeParameterArray(object firstParam, params object[] varParams)
+ {
+ ArrayList paramList = new ArrayList();
+ paramList.Add(firstParam);
+ foreach(object param in varParams)
+ {
+ paramList.Add(param);
+ }
+
+ return paramList.ToArray();
+ }
+
+ /// <summary>
+ /// Creates a new connection
+ /// </summary>
+ public IConnection CreateConnection()
+ {
+ return this.factory.CreateConnection();
+ }
+
+ /// <summary>
+ /// Creates a new connection with the given user name and password
+ /// </summary>
+ /// <param name="userName"></param>
+ /// <param name="password"></param>
+ /// <returns></returns>
+ public IConnection CreateConnection(string userName, string password)
+ {
+ return this.factory.CreateConnection(userName, password);
+ }
+
+ /// <summary>
+ /// The actual IConnectionFactory implementation that is being used. This implemenation
+ /// depends on the scheme of the URI used when constructed.
+ /// </summary>
+ public IConnectionFactory ConnectionFactory
+ {
+ get { return factory; }
+ }
+ }
+}
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/CommonAssemblyInfo.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/CommonAssemblyInfo.cs?rev=627163&r1=627162&r2=627163&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/CommonAssemblyInfo.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/CommonAssemblyInfo.cs Tue Feb 12 14:52:29 2008
@@ -20,7 +20,7 @@
[assembly: AssemblyConfigurationAttribute("SNAPSHOT")]
[assembly: AssemblyCompanyAttribute("http://activemq.apache.org/nms")]
[assembly: AssemblyProductAttribute("Apache NMS Class Library")]
-[assembly: AssemblyCopyrightAttribute("Copyright (C) 2005-2007 Apache Software Foundation")]
+[assembly: AssemblyCopyrightAttribute("Copyright (C) 2005-2008 Apache Software Foundation")]
[assembly: AssemblyTrademarkAttribute("")]
[assembly: AssemblyCultureAttribute("")]
[assembly: AssemblyVersionAttribute("1.0")]
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs?rev=627163&r1=627162&r2=627163&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ConsumerTest.cs Tue Feb 12 14:52:29 2008
@@ -15,6 +15,7 @@
* limitations under the License.
*/
using System;
+using System.Threading;
using NUnit.Framework;
namespace Apache.NMS.Test
@@ -28,7 +29,7 @@
[SetUp]
public override void SetUp()
{
- clientId = "test";
+ clientId = "Apache.NMS.Test.ConsumerTest";
base.SetUp();
}
@@ -51,7 +52,7 @@
public void TestDurableConsumerSelectorChangeNonPersistent()
{
destinationType = DestinationType.Topic;
- persistent = true;
+ persistent = false;
doTestDurableConsumerSelectorChange();
}
@@ -67,7 +68,7 @@
message.Properties["color"] = "red";
producer.Send(message);
- IMessage m = consumer.Receive(TimeSpan.FromMilliseconds(receiveTimeout));
+ IMessage m = consumer.Receive(receiveTimeout);
Assert.IsNotNull(m);
Assert.AreEqual("1st", ((ITextMessage) m).Text);
@@ -89,5 +90,52 @@
Assert.IsNull(consumer.ReceiveNoWait());
}
+
+ [Test]
+ public void TestNoTimeoutConsumer()
+ {
+ destinationType = DestinationType.Queue;
+ // Launch a thread to perform IMessageConsumer.Receive().
+ // If it doesn't fail in less than three seconds, no exception was thrown.
+ Thread receiveThread = new Thread(doTestNoTimeoutConsumer);
+
+ using(timeoutConsumer = Session.CreateConsumer(Destination))
+ {
+ receiveThread.Start();
+ if(receiveThread.Join(3000))
+ {
+ Assert.Fail("IMessageConsumer.Receive() returned without blocking. Test failed.");
+ }
+ else
+ {
+ // Kill the thread - otherwise it'll sit in Receive() until a message arrives.
+ receiveThread.Interrupt();
+ }
+ }
+ }
+
+ protected IMessageConsumer timeoutConsumer;
+
+ public void doTestNoTimeoutConsumer()
+ {
+ try
+ {
+ timeoutConsumer.Receive();
+ }
+ catch(ArgumentOutOfRangeException e)
+ {
+ // The test failed. We will know because the timeout will expire inside TestNoTimeoutConsumer().
+ Console.WriteLine("Test failed with exception: " + e.Message);
+ }
+ catch(ThreadInterruptedException)
+ {
+ // The test succeeded! We were still blocked when we were interrupted.
+ }
+ catch(Exception e)
+ {
+ // Some other exception occurred.
+ Console.WriteLine("Test failed with exception: " + e.Message);
+ }
+ }
}
}
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs?rev=627163&r1=627162&r2=627163&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/DurableTest.cs Tue Feb 12 14:52:29 2008
@@ -88,7 +88,7 @@
IMessageConsumer consumer = session.CreateDurableConsumer(
topic, CONSUMER_ID, "2 > 1", false);
consumer.Listener += new MessageListener(consumer_Listener);
- /// Don't know how else to give the system enough time. /// Thread.Sleep(5000); Assert.AreEqual(0, count); Console.WriteLine("Count = " + count); SendPersistentMessage(); Thread.Sleep(5000); Assert.AreEqual(2, count); Console.WriteLine("Count = " + count); consumer.Dispose(); }
+ // Don't know how else to give the system enough time. // Thread.Sleep(5000); Assert.AreEqual(0, count); Console.WriteLine("Count = " + count); SendPersistentMessage(); Thread.Sleep(5000); Assert.AreEqual(2, count); Console.WriteLine("Count = " + count); consumer.Dispose(); }
connection.Stop();
}
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs?rev=627163&r1=627162&r2=627163&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/NMSTestSupport.cs Tue Feb 12 14:52:29 2008
@@ -18,237 +18,266 @@
using NUnit.Framework;
using System;
-/// <summary>
-/// useful base class for test cases
-/// </summary>
-
namespace Apache.NMS.Test
{
- [ TestFixture ]
- public abstract class NMSTestSupport
- {
+ /// <summary>
+ /// useful base class for test cases
+ /// </summary>
+ [TestFixture]
+ public abstract class NMSTestSupport
+ {
protected static object destinationLock = new object();
protected static int destinationCounter;
- // enable/disable logging of message flows
- protected bool logging = true;
+ // enable/disable logging of message flows
+ protected bool logging = true;
+
+ private IConnectionFactory factory;
+ private IConnection connection;
+ private ISession session;
+ private IDestination destination;
+
+ protected TimeSpan receiveTimeout = TimeSpan.FromMilliseconds(1000);
+ protected string clientId;
+ protected bool persistent = true;
+ protected DestinationType destinationType = DestinationType.Queue;
+ protected AcknowledgementMode acknowledgementMode = AcknowledgementMode.ClientAcknowledge;
+
+ [SetUp]
+ public virtual void SetUp()
+ {
+ }
- private IConnectionFactory factory;
- private IConnection connection;
- private ISession session;
- private IDestination destination;
-
- protected int receiveTimeout = 1000;
- protected string clientId;
- protected bool persistent = true;
- protected DestinationType destinationType = DestinationType.Queue;
- protected AcknowledgementMode acknowledgementMode = AcknowledgementMode.ClientAcknowledge;
-
- [SetUp]
- virtual public void SetUp()
- {
- }
-
- [TearDown]
- virtual public void TearDown()
- {
+ [TearDown]
+ public virtual void TearDown()
+ {
destination = null;
- Disconnect();
- }
+ Disconnect();
+ }
+
+ // Properties
+ public bool Connected
+ {
+ get { return connection != null; }
+ set
+ {
+ if(value)
+ {
+ Connect();
+ }
+ else
+ {
+ Disconnect();
+ }
+ }
+ }
+
+ public IConnectionFactory Factory
+ {
+ get
+ {
+ if(factory == null)
+ {
+ factory = CreateConnectionFactory();
+ Assert.IsNotNull(factory, "no factory created");
+ }
+ return factory;
+ }
+ set { this.factory = value; }
+ }
+
+ public IConnection Connection
+ {
+ get
+ {
+ if(connection == null)
+ {
+ Connect();
+ }
+ return connection;
+ }
+ set { this.connection = value; }
+ }
+
+ public ISession Session
+ {
+ get
+ {
+ if(session == null)
+ {
+ session = Connection.CreateSession(acknowledgementMode);
+ Assert.IsNotNull(connection != null, "no session created");
+ }
+ return session;
+ }
+ set { this.session = value; }
+ }
+
+ protected virtual void Connect()
+ {
+ WriteLine("Connecting...");
+ connection = CreateConnection();
+ Assert.IsNotNull(connection, "no connection created");
+ connection.Start();
+ WriteLine("Connected.");
+ Assert.IsNotNull(connection, "no connection created");
+ }
- // Properties
- public bool Connected
- {
- get { return connection!=null; }
- set { if( value ) Connect(); else Disconnect(); }
- }
-
- public IConnectionFactory Factory
- {
- get {
- if( factory == null ) {
- factory = CreateConnectionFactory();
- Assert.IsNotNull(factory, "no factory created");
- }
- return factory;
- }
- set { this.factory = value; }
- }
-
- public IConnection Connection
- {
- get {
- if( connection == null ) {
- Connect();
- }
- return connection;
- }
- set { this.connection = value; }
- }
-
- public ISession Session
- {
- get {
- if( session == null ) {
- session = Connection.CreateSession(acknowledgementMode);
- Assert.IsNotNull(connection != null, "no session created");
- }
- return session;
- }
- set { this.session = value; }
- }
-
- virtual protected void Connect()
- {
- WriteLine("Connectting...");
- connection = CreateConnection();
- Assert.IsNotNull(connection, "no connection created");
- connection.Start();
- WriteLine("Connected.");
- Assert.IsNotNull(connection, "no connection created");
- }
-
- virtual protected void Disconnect()
- {
- if (session != null)
+ protected virtual void Disconnect()
+ {
+ if(session != null)
{
session.Dispose();
session = null;
}
- if (connection != null)
- {
- WriteLine("Disconnecting...");
- connection.Dispose();
- connection = null;
- WriteLine("Disconnected.");
- }
- }
-
- virtual protected void Reconnect()
- {
- Disconnect();
- Connect();
- }
-
- protected virtual void Drain()
- {
- using (ISession session = Connection.CreateSession())
- {
- // Tries to consume any messages on the Destination
- IMessageConsumer consumer = session.CreateConsumer(Destination);
-
- // Should only need to wait for first message to arrive due to the way
- // prefetching works.
- IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(receiveTimeout));
- while (msg != null)
- {
- msg = consumer.ReceiveNoWait();
- }
- }
- }
-
- public virtual void SendAndSyncReceive()
- {
- using (ISession session = Connection.CreateSession())
- {
- IMessageConsumer consumer = session.CreateConsumer(Destination);
- IMessageProducer producer = session.CreateProducer(Destination);
+ if(connection != null)
+ {
+ WriteLine("Disconnecting...");
+ connection.Dispose();
+ connection = null;
+ WriteLine("Disconnected.");
+ }
+ }
+
+ protected virtual void Reconnect()
+ {
+ Disconnect();
+ Connect();
+ }
+
+ protected virtual void Drain()
+ {
+ using(ISession drainSession = Connection.CreateSession())
+ {
+ // Tries to consume any messages on the Destination
+ IMessageConsumer consumer = drainSession.CreateConsumer(CreateDestination(drainSession));
+
+ // Should only need to wait for first message to arrive due to the way
+ // prefetching works.
+ while(consumer.Receive(receiveTimeout) != null)
+ {
+ }
+ }
+ }
+
+ public virtual void SendAndSyncReceive()
+ {
+ using(ISession sendSession = Connection.CreateSession())
+ {
+ IDestination sendDestination = CreateDestination(sendSession);
+ IMessageConsumer consumer = sendSession.CreateConsumer(sendDestination);
+ IMessageProducer producer = sendSession.CreateProducer(sendDestination);
producer.Persistent = persistent;
- IMessage request = CreateMessage();
- producer.Send(request);
+ IMessage request = sendSession.CreateMessage();
+ producer.Send(request);
+
+ IMessage message = consumer.Receive(receiveTimeout);
+ Assert.IsNotNull(message, "No message returned!");
+ AssertValidMessage(message);
+ }
+ }
+
+ protected abstract IConnectionFactory CreateConnectionFactory();
+
+ protected virtual IConnection CreateConnection()
+ {
+ IConnection newConnection = Factory.CreateConnection();
+ if(clientId != null)
+ {
+ newConnection.ClientId = clientId;
+ }
+ return newConnection;
+ }
+
+ protected virtual IMessageProducer CreateProducer()
+ {
+ return Session.CreateProducer(Destination);
+ }
+
+ protected virtual IMessageConsumer CreateConsumer()
+ {
+ return Session.CreateConsumer(Destination);
+ }
+
+ protected virtual IDestination CreateDestination()
+ {
+ return CreateDestination(Session);
+ }
+
+ protected virtual IDestination CreateDestination(ISession curSession)
+ {
+ if(destinationType == DestinationType.Queue)
+ {
+ return curSession.GetQueue(CreateDestinationName());
+ }
+ else if(destinationType == DestinationType.Topic)
+ {
+ return curSession.GetTopic(CreateDestinationName());
+ }
+ else if(destinationType == DestinationType.TemporaryQueue)
+ {
+ return curSession.CreateTemporaryQueue();
+ }
+ else if(destinationType == DestinationType.TemporaryTopic)
+ {
+ return curSession.CreateTemporaryTopic();
+ }
+ else
+ {
+ throw new Exception("Unknown destination type: " + destinationType);
+ }
+ }
+
+ protected virtual string CreateDestinationName()
+ {
+ return "Test.DotNet." + GetType().Name + "." + NextNumber.ToString();
+ }
- IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(receiveTimeout));
- Assert.IsNotNull(message, "No message returned!");
- AssertValidMessage(message);
- }
- }
-
- abstract protected IConnectionFactory CreateConnectionFactory();
-
- protected virtual IConnection CreateConnection()
- {
- IConnection connection = Factory.CreateConnection();
- if( clientId!=null ) {
- connection.ClientId = clientId;
- }
- return connection;
- }
-
- protected virtual IMessageProducer CreateProducer()
- {
- IMessageProducer producer = Session.CreateProducer(Destination);
- return producer;
- }
-
- protected virtual IMessageConsumer CreateConsumer()
- {
- IMessageConsumer consumer = Session.CreateConsumer(Destination);
- return consumer;
- }
-
- protected virtual IDestination CreateDestination()
- {
- if( destinationType == DestinationType.Queue ) {
- return Session.GetQueue(CreateDestinationName());
- } else if( destinationType == DestinationType.Topic ) {
- return Session.GetTopic(CreateDestinationName());
- } else if( destinationType == DestinationType.TemporaryQueue ) {
- return Session.CreateTemporaryQueue();
- } else if( destinationType == DestinationType.TemporaryTopic ) {
- return Session.CreateTemporaryTopic();
- } else {
- throw new Exception("Unknown destination type: "+destinationType);
- }
- }
-
- protected virtual string CreateDestinationName()
- {
- return "Test.DotNet." + GetType().Name + "." + NextNumber.ToString();
- }
-
public static int NextNumber
{
- get { lock(destinationLock) { return ++destinationCounter; } }
+ get
+ {
+ lock(destinationLock)
+ {
+ return ++destinationCounter;
+ }
+ }
+ }
+
+ protected virtual IMessage CreateMessage()
+ {
+ return Session.CreateMessage();
+ }
+
+ protected virtual void AssertValidMessage(IMessage message)
+ {
+ Assert.IsNotNull(message, "Null Message!");
+ }
+
+ public IDestination Destination
+ {
+ get
+ {
+ if(destination == null)
+ {
+ destination = CreateDestination();
+ Assert.IsNotNull(destination, "No destination available!");
+ WriteLine("Using destination: " + destination);
+ }
+ return destination;
+ }
+ set { destination = value; }
}
-
- protected virtual IMessage CreateMessage()
- {
- return Session.CreateMessage();
- }
-
- protected virtual void AssertValidMessage(IMessage message)
- {
- Assert.IsNotNull(message, "Null Message!");
- }
-
-
- public IDestination Destination
- {
- get {
- if (destination == null)
- {
- destination = CreateDestination();
- Assert.IsNotNull(destination, "No destination available!");
- WriteLine("Using destination: " + destination);
- }
- return destination;
- }
- set {
- destination = value;
- }
- }
protected virtual void WriteLine(string text)
{
- if (logging)
+ if(logging)
{
Console.WriteLine();
Console.WriteLine("#### : " + text);
}
}
- }
-}
-
-
+ }
+}
\ No newline at end of file
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj?rev=627163&r1=627162&r2=627163&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj Tue Feb 12 14:52:29 2008
@@ -66,5 +66,13 @@
<ItemGroup>
<None Include="activemq-dotnet.snk" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="LICENSE.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="NOTICE.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>