public void TestURIForPrefetchHandling(int queuePreFetch, int queueBrowserPrefetch, int topicPrefetch, int durableTopicPrefetch, int maximumPendingMessageLimit)
        {
            string testuri = string.Format("activemq:tcp://${{activemqhost}}:61616" +
                                           "?nms.PrefetchPolicy.queuePrefetch={0}" +
                                           "&nms.PrefetchPolicy.queueBrowserPrefetch={1}" +
                                           "&nms.PrefetchPolicy.topicPrefetch={2}" +
                                           "&nms.PrefetchPolicy.durableTopicPrefetch={3}" +
                                           "&nms.PrefetchPolicy.maximumPendingMessageLimit={4}",
                                           queuePreFetch, queueBrowserPrefetch, topicPrefetch, durableTopicPrefetch, maximumPendingMessageLimit);

            NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(testuri));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);

                Connection amqConnection = connection as Connection;
                Assert.AreEqual(queuePreFetch, amqConnection.PrefetchPolicy.QueuePrefetch);
                Assert.AreEqual(queueBrowserPrefetch, amqConnection.PrefetchPolicy.QueueBrowserPrefetch);
                Assert.AreEqual(topicPrefetch, amqConnection.PrefetchPolicy.TopicPrefetch);
                Assert.AreEqual(durableTopicPrefetch, amqConnection.PrefetchPolicy.DurableTopicPrefetch);
                Assert.AreEqual(maximumPendingMessageLimit, amqConnection.PrefetchPolicy.MaximumPendingMessageLimit);

                connection.Close();
            }
        }
        public void FailoverTransportFailOnProcessingReceivedMessageTest()
        {
            string             uri     = "failover:(tcp://${activemqhost}:61616)";
            IConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri));

            using (connection = factory.CreateConnection() as Connection)
            {
                connection.ConnectionInterruptedListener +=
                    new ConnectionInterruptedListener(TransportInterrupted);
                connection.ConnectionResumedListener +=
                    new ConnectionResumedListener(TransportResumed);

                connection.Start();
                using (ISession session = connection.CreateSession())
                {
                    IDestination destination = session.GetQueue("Test?consumer.prefetchSize=1");
                    PurgeQueue(connection, destination);
                    PutMsgIntoQueue(session, destination);

                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        consumer.Listener += OnMessage;
                        BreakConnection();
                        WaitForMessagesToArrive();
                    }
                }
            }

            Assert.IsTrue(this.interrupted);
            Assert.IsTrue(this.resumed);
        }
Beispiel #3
0
        public void TestConfigureRecoveryPolicyLoggerUsingDefaultLogger(string location, bool autoCreate)
        {
            string testuri = string.Format("activemq:tcp://${{activemqhost}}:61616" +
                                           "?nms.RecoveryPolicy.RecoveryLogger.Location={0}" +
                                           "&nms.RecoveryPolicy.RecoveryLogger.AutoCreateLocation={1}",
                                           location, autoCreate);

            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(testuri));

            using (INetTxConnection connection = factory.CreateNetTxConnection())
            {
                NetTxConnection netTxConnection = connection as NetTxConnection;

                Assert.IsNotNull(netTxConnection);
                NetTxRecoveryPolicy policy = netTxConnection.RecoveryPolicy;

                Assert.AreEqual("file", policy.RecoveryLoggerType);

                RecoveryFileLogger logger = policy.RecoveryLogger as RecoveryFileLogger;

                Assert.IsNotNull(logger);
                Assert.AreEqual(location, logger.Location);
                Assert.AreEqual(autoCreate, logger.AutoCreateLocation);
            }
        }
        public void TestMaxInactivityDuration()
        {
            string testuri = "activemq:tcp://${activemqhost}:61616" +
                             "?wireFormat.maxInactivityDurationInitialDelay=5000" +
                             "&wireFormat.maxInactivityDuration=10000" +
                             "&connection.asyncClose=false";

            NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(testuri));

            using (IConnection connection = factory.CreateConnection("", ""))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            SendMessage(producer);

                            IMessage receivedMsg = consumer.Receive(TimeSpan.FromSeconds(5));
                            Assert.AreEqual(CORRELATION_ID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");

                            // Go inactive...
                            Thread.Sleep(TimeSpan.FromSeconds(30));

                            // Send another message.
                            SendMessage(producer);
                            receivedMsg = consumer.Receive(TimeSpan.FromSeconds(5));
                            Assert.AreEqual(CORRELATION_ID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
                        }
                }
            }
        }
Beispiel #5
0
        public async Task TestProducerSendWithExpiry()
        {
            // Uri uri = new Uri(string.Format("tcp://localhost"));
            // Uris uri = new Uri(string.Format("mock://localhost:61616?transport.respondToMessages=false"));
            string             uri     = "tcp://${activemqhost}:61616?transport.useLogging=true";
            IConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri));

            // ConnectionFactory factory = new ConnectionFactory(uri);
            using (IConnection connection = await factory.CreateConnectionAsync())
                using (ISession session = await connection.CreateSessionAsync())
                {
                    IDestination destination = await session.GetTopicAsync("Test");

                    using (IMessageProducer producer = await session.CreateProducerAsync(destination))
                    {
                        ITextMessage message = await session.CreateTextMessageAsync("Hello World");

                        message.NMSTimeToLive = TimeSpan.FromSeconds(175);
                        await producer.SendAsync(message);

                        // ITextMessage message2 = await session.CreateTextMessageAsync("Hello World");
                        // // message2.NMSTimeToLive = TimeSpan.FromSeconds(175);
                        // await producer.SendAsync(message2);
                    }
                }
        }
Beispiel #6
0
        private void Receive(int numberOfMessages)
        {
            IConnectionFactory connectionFactory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(BrokerUri));

            using (IConnection connection = connectionFactory.CreateConnection())
            {
                connection.Start();

                connection.ConnectionInterruptedListener += OnConnectionInterrupted;
                connection.ConnectionResumedListener     += OnConnectionResumed;

                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IQueue queue = session.GetQueue(Queue);

                    using (IMessageConsumer consumer = session.CreateConsumer(queue))
                    {
                        for (int i = 0; i < numberOfMessages; i++)
                        {
                            IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(5000));
                            Assert.IsNotNull(message);
                            Tracer.Debug("Received message.");
                            received++;
                        }
                    }
                }

                connection.ConnectionInterruptedListener -= OnConnectionInterrupted;
                connection.ConnectionResumedListener     -= OnConnectionResumed;
            }
        }
        public void FailStartupMaxReconnectAttempts()
        {
            // Connect to valid machine, but on invalid port that doesn't have a broker listening.
            string             uri            = "failover:(tcp://localhost:31313)?transport.StartupMaxReconnectAttempts=3";
            IConnectionFactory factory        = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri));
            IConnection        failConnection = factory.CreateConnection();

            try
            {
                failConnection.Start();
                Assert.Fail("Should not have connected to broker.");
            }
            catch (Apache.NMS.ActiveMQ.ConnectionClosedException)
            {
            }
            finally
            {
                try
                {
                    failConnection.Stop();
                }
                catch (Apache.NMS.ActiveMQ.ConnectionClosedException)
                {
                    Assert.Fail("Connection closed exception thrown while closing a connection.");
                }
                finally
                {
                    failConnection.Dispose();
                }
            }
        }
        public void TestConnection()
        {
            IConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionUri));

            using (connection = factory.CreateConnection())
                using (ISession session = connection.CreateSession())
                {
                    IDestination destination = SessionUtil.GetDestination(session, "queue://TEST.test.in");
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        Connection amqConnection = connection as Connection;
                        connection.ExceptionListener += ConnectionException;

                        consumer.Listener += OnMessage;

                        TcpFaultyTransport transport = amqConnection.ITransport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport;
                        Assert.IsNotNull(transport);
                        transport.OnewayCommandPreProcessor += FailOnKeepAlive;

                        Thread.Sleep(TimeSpan.FromSeconds(2));

                        connection.Start();

                        Assert.IsTrue(exceptionOccuredEvent.WaitOne(TimeSpan.FromSeconds(30 * 3)),
                                      "Exception didnt occured within waiting time");
                    }
                }
        }
Beispiel #9
0
        private void Send(int numberOfMessages)
        {
            IConnectionFactory connectionFactory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(BrokerUri));

            using (IConnection connection = connectionFactory.CreateConnection())
            {
                connection.Start();

                using (ISession session = connection.CreateSession())
                {
                    IQueue queue = session.GetQueue(Queue);

                    using (IMessageProducer producer = session.CreateProducer(queue))
                    {
                        producer.DeliveryMode = MsgDeliveryMode.Persistent;

                        ITextMessage message = producer.CreateTextMessage(TextMessage);

                        for (int i = 0; i < numberOfMessages; i++)
                        {
                            producer.Send(message);
                            Tracer.Debug("Sent message.");
                            sent++;
                        }
                    }
                }
            }
        }
Beispiel #10
0
        public void TestURI(string connectionURI)
        {
            {
                Uri uri = URISupport.CreateCompatibleUri(NMSTestSupport.ReplaceEnvVar(connectionURI));
                NetTxConnectionFactory factory = new NetTxConnectionFactory(uri);
                Assert.IsNotNull(factory);
                using (IConnection connection = factory.CreateConnection("", ""))
                {
                    Assert.IsNotNull(connection);

                    using (ISession session = connection.CreateSession())
                    {
                        IDestination destination = session.CreateTemporaryTopic();
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.Close();
                        }

                        using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        {
                            consumer.Close();
                        }

                        session.Close();
                    }

                    connection.Close();
                }
            }

            {
                NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
                Assert.IsNotNull(factory);
                using (IConnection connection = factory.CreateConnection("", ""))
                {
                    Assert.IsNotNull(connection);

                    using (ISession session = connection.CreateSession())
                    {
                        Assert.IsNotNull(session as INetTxSession);

                        IDestination destination = session.CreateTemporaryTopic();
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.Close();
                        }

                        using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        {
                            consumer.Close();
                        }

                        session.Close();
                    }

                    connection.Close();
                }
            }
        }
        public async Task TestURI(string connectionURI)
        {
            {
                Uri uri = URISupport.CreateCompatibleUri(NMSTestSupport.ReplaceEnvVar(connectionURI));
                ConnectionFactory factory = new ConnectionFactory(uri);
                Assert.IsNotNull(factory);
                using (IConnection connection = await factory.CreateConnectionAsync("", ""))
                {
                    Assert.IsNotNull(connection);

                    using (ISession session = await connection.CreateSessionAsync())
                    {
                        IDestination destination = await session.CreateTemporaryTopicAsync();

                        using (IMessageProducer producer = await session.CreateProducerAsync(destination))
                        {
                            await producer.CloseAsync();
                        }

                        using (IMessageConsumer consumer = await session.CreateConsumerAsync(destination))
                        {
                            await consumer.CloseAsync();
                        }

                        await session.CloseAsync();
                    }

                    await connection.CloseAsync();
                }
            }

            {
                ConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
                Assert.IsNotNull(factory);
                using (IConnection connection = await factory.CreateConnectionAsync("", ""))
                {
                    Assert.IsNotNull(connection);

                    using (ISession session = await connection.CreateSessionAsync())
                    {
                        IDestination destination = await session.CreateTemporaryTopicAsync();

                        using (IMessageProducer producer = await session.CreateProducerAsync(destination))
                        {
                            await producer.CloseAsync();
                        }

                        using (IMessageConsumer consumer = await session.CreateConsumerAsync(destination))
                        {
                            await consumer.CloseAsync();
                        }

                        await session.CloseAsync();
                    }

                    await connection.CloseAsync();
                }
            }
        }
Beispiel #12
0
        public void TestConfigureRecoveryPolicyLoggerTypeWithInvalidType(
            [Values("tcp://${activemqhost}:61616?nms.RecoveryPolicy.RecoveryLoggerType=invalid")]
            string baseConnectionURI)
        {
            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));

            using (IConnection connection = factory.CreateConnection()){}
        }
Beispiel #13
0
        public void FailoverWithShortLivedProducerTest()
        {
            string             uri     = "failover:(tcpfaulty://${activemqhost}:61616?transport.useLogging=true)";
            IConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri));

            using (connection = factory.CreateConnection() as Connection)
            {
                connection.ConnectionInterruptedListener +=
                    new ConnectionInterruptedListener(TransportInterrupted);
                connection.ConnectionResumedListener +=
                    new ConnectionResumedListener(TransportResumed);

                connection.Start();

                ITransport         transport = (connection as Connection).ITransport;
                TcpFaultyTransport tcpFaulty = transport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport;
                Assert.IsNotNull(tcpFaulty);

                using (ISession session = connection.CreateSession())
                {
                    IDestination destination = session.GetQueue(destinationName);
                    PurgeQueue(connection, destination);
                }

                Tracer.Debug("Test is putting " + MSG_COUNT + " messages on the queue: " + destinationName);

                using (ISession session = connection.CreateSession(AcknowledgementMode.Transactional))
                {
                    IDestination destination = session.GetQueue(destinationName);
                    PutMsgIntoQueue(session, destination, false);
                    tcpFaulty.Close();
                    PutMsgIntoQueue(session, destination, false);
                    session.Commit();
                }

                Assert.IsTrue(this.interrupted);
                Assert.IsTrue(this.resumed);

                Tracer.Debug("Test is attempting to read " + MSG_COUNT +
                             " messages from the queue: " + destinationName);

                using (ISession session = connection.CreateSession())
                {
                    IDestination     destination = session.GetQueue(destinationName);
                    IMessageConsumer consumer    = session.CreateConsumer(destination);
                    for (int i = 0; i < MSG_COUNT; ++i)
                    {
                        IMessage msg = consumer.Receive(TimeSpan.FromSeconds(5));
                        Assert.IsNotNull(msg, "Should receive message[" + (i + 1) + "] after commit failed once.");
                    }
                }
            }

            Assert.IsTrue(this.interrupted);
            Assert.IsTrue(this.resumed);
        }
Beispiel #14
0
        public void TestTransactedProduceAndConsume(
            [Values("tcp://${activemqhost}:61616")]
            string baseConnectionURI)
        {
            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));

            using (INetTxConnection connection = factory.CreateNetTxConnection())
            {
                connection.Start();

                using (INetTxSession session = connection.CreateNetTxSession())
                {
                    IDestination destination = session.CreateTemporaryQueue();
                    using (IMessageProducer producer = session.CreateProducer(destination))
                    {
                        using (TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionScopeAsyncFlowOption.Enabled))
                        {
                            Assert.IsNotNull(Transaction.Current);
                            for (int i = 0; i < MSG_COUNT; ++i)
                            {
                                producer.Send(session.CreateTextMessage("Hello World"));
                            }

                            scoped.Complete();
                        }
                    }

                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        Thread.Sleep(100);

                        using (TransactionScope scoped = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionScopeAsyncFlowOption.Enabled))
                        {
                            for (int i = 0; i < MSG_COUNT; ++i)
                            {
                                IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
                                Assert.IsNotNull(msg, "Message was null for index: " + i);
                            }
                            scoped.Complete();
                        }
                    }

                    // No more messages should be in the Q, non rolled back or otherwise.
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        Thread.Sleep(100);
                        IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000));
                        Assert.IsNull(msg, "Message was not null.");
                    }

                    session.Close();
                }

                connection.Close();
            }
        }
Beispiel #15
0
        public void TestURI(string connectionURI)
        {
            NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
            }
        }
 public void TestURIFailures_NMSConnectionException(string connectionURI)
 {
     Assert.Throws <NMSConnectionException>(() =>
     {
         NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
         Assert.IsNotNull(factory);
         Assert.IsNotNull(factory.ConnectionFactory);
         using (IConnection connection = factory.CreateConnection("", ""))
         {
             Assert.IsNotNull(connection);
             connection.Close();
         }
     });
 }
Beispiel #17
0
        public void TestConnectionStarts(string connectionURI)
        {
            NMS.Tracer.Trace = new NmsConsoleTracer();
            IConnectionFactory factory = new ConnectionFactory(
                NMSTestSupport.ReplaceEnvVar(connectionURI));

            Assert.IsNotNull(factory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);
                // This should trigger a CONNECT frame and CONNACK response.
                connection.Start();
            }
        }
Beispiel #18
0
        public void TestURIForRedeliverPolicyHandling()
        {
            string uri1 = "stomp:tcp://${activemqhost}:61613" +
                          "?nms.RedeliveryPolicy.BackOffMultiplier=10" +
                          "&nms.RedeliveryPolicy.InitialRedeliveryDelay=2000" +
                          "&nms.RedeliveryPolicy.UseExponentialBackOff=true" +
                          "&nms.RedeliveryPolicy.UseCollisionAvoidance=true" +
                          "&nms.RedeliveryPolicy.CollisionAvoidancePercent=20";

            string uri2 = "stomp:tcp://${activemqhost}:61613" +
                          "?nms.RedeliveryPolicy.backOffMultiplier=50" +
                          "&nms.RedeliveryPolicy.initialRedeliveryDelay=4000" +
                          "&nms.RedeliveryPolicy.useExponentialBackOff=false" +
                          "&nms.RedeliveryPolicy.useCollisionAvoidance=false" +
                          "&nms.RedeliveryPolicy.collisionAvoidancePercent=10";

            NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri1));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);

                Connection amqConnection = connection as Connection;

                Assert.AreEqual(10, amqConnection.RedeliveryPolicy.BackOffMultiplier);
                Assert.AreEqual(2000, amqConnection.RedeliveryPolicy.InitialRedeliveryDelay);
                Assert.AreEqual(true, amqConnection.RedeliveryPolicy.UseExponentialBackOff);
                Assert.AreEqual(true, amqConnection.RedeliveryPolicy.UseCollisionAvoidance);
                Assert.AreEqual(20, amqConnection.RedeliveryPolicy.CollisionAvoidancePercent);
            }

            factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri2));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);

                Connection amqConnection = connection as Connection;
                Assert.AreEqual(50, amqConnection.RedeliveryPolicy.BackOffMultiplier);
                Assert.AreEqual(4000, amqConnection.RedeliveryPolicy.InitialRedeliveryDelay);
                Assert.AreEqual(false, amqConnection.RedeliveryPolicy.UseExponentialBackOff);
                Assert.AreEqual(false, amqConnection.RedeliveryPolicy.UseCollisionAvoidance);
                Assert.AreEqual(10, amqConnection.RedeliveryPolicy.CollisionAvoidancePercent);
            }
        }
Beispiel #19
0
        public void TestURIForPrefetchHandling()
        {
            string uri1 = "activemq:tcp://${activemqhost}:61616" +
                          "?nms.PrefetchPolicy.queuePrefetch=1" +
                          "&nms.PrefetchPolicy.queueBrowserPrefetch=2" +
                          "&nms.PrefetchPolicy.topicPrefetch=3" +
                          "&nms.PrefetchPolicy.durableTopicPrefetch=4" +
                          "&nms.PrefetchPolicy.maximumPendingMessageLimit=5";

            string uri2 = "activemq:tcp://${activemqhost}:61616" +
                          "?nms.PrefetchPolicy.queuePrefetch=112" +
                          "&nms.PrefetchPolicy.queueBrowserPrefetch=212" +
                          "&nms.PrefetchPolicy.topicPrefetch=312" +
                          "&nms.PrefetchPolicy.durableTopicPrefetch=412" +
                          "&nms.PrefetchPolicy.maximumPendingMessageLimit=512";

            NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri1));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);

                Connection amqConnection = connection as Connection;
                Assert.AreEqual(1, amqConnection.PrefetchPolicy.QueuePrefetch);
                Assert.AreEqual(2, amqConnection.PrefetchPolicy.QueueBrowserPrefetch);
                Assert.AreEqual(3, amqConnection.PrefetchPolicy.TopicPrefetch);
                Assert.AreEqual(4, amqConnection.PrefetchPolicy.DurableTopicPrefetch);
                Assert.AreEqual(5, amqConnection.PrefetchPolicy.MaximumPendingMessageLimit);
            }

            factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri2));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);

                Connection amqConnection = connection as Connection;
                Assert.AreEqual(112, amqConnection.PrefetchPolicy.QueuePrefetch);
                Assert.AreEqual(212, amqConnection.PrefetchPolicy.QueueBrowserPrefetch);
                Assert.AreEqual(312, amqConnection.PrefetchPolicy.TopicPrefetch);
                Assert.AreEqual(412, amqConnection.PrefetchPolicy.DurableTopicPrefetch);
                Assert.AreEqual(512, amqConnection.PrefetchPolicy.MaximumPendingMessageLimit);
            }
        }
Beispiel #20
0
        public void TestConnectionFactoryParseParams(
            [Values("tcp://${activemqhost}:61616", "activemq:tcp://${activemqhost}:61616")]
            string baseConnectionURI,
            [Values(AcknowledgementMode.ClientAcknowledge, AcknowledgementMode.AutoAcknowledge)]
            AcknowledgementMode ackMode,
            [Values(true, false)]
            bool asyncSend,
            [Values(true, false)]
            bool alwaysSyncSend,
            [Values(true, false)]
            bool asyncClose,
            [Values(true, false)]
            bool copyMessageOnSend,
            [Values(3000, 1000)]
            int requestTimeout,
            [Values(true, false)]
            bool sendAcksAsync,
            [Values(true, false)]
            bool dispatchAsync)
        {
            string connectionURI = string.Format("{0}?" +
                                                 "connection.AckMode={1}&" +
                                                 "connection.AsyncSend={2}&" +
                                                 "connection.AlwaysSyncSend={3}&" +
                                                 "connection.AsyncClose={4}&" +
                                                 "connection.CopyMessageOnSend={5}&" +
                                                 "connection.RequestTimeout={6}&" +
                                                 "connection.SendAcksAsync={7}&" +
                                                 "connection.DispatchAsync={8}",
                                                 baseConnectionURI, ackMode, asyncSend, alwaysSyncSend, asyncClose, copyMessageOnSend, requestTimeout, sendAcksAsync, dispatchAsync);

            NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));

            using (Connection connection = factory.CreateConnection() as Connection)
            {
                Assert.AreEqual(ackMode, connection.AcknowledgementMode);
                Assert.AreEqual(asyncSend, connection.AsyncSend);
                Assert.AreEqual(alwaysSyncSend, connection.AlwaysSyncSend);
                Assert.AreEqual(asyncClose, connection.AsyncClose);
                Assert.AreEqual(copyMessageOnSend, connection.CopyMessageOnSend);
                Assert.AreEqual(requestTimeout, connection.RequestTimeout.TotalMilliseconds);
                Assert.AreEqual(sendAcksAsync, connection.SendAcksAsync);
                Assert.AreEqual(dispatchAsync, connection.DispatchAsync);
            }
        }
        public void TestInactivityMonitorThreadLeak(
            [Values(0, 1000)]
            int inactivityDuration)
        {
            Process currentProcess = Process.GetCurrentProcess();

            Tracer.InfoFormat("Beginning thread count: {0}, handle count: {1}", currentProcess.Threads.Count, currentProcess.HandleCount);

            string testuri = string.Format("activemq:tcp://${{activemqhost}}:61616?wireFormat.maxInactivityDuration={0}", inactivityDuration);

            NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(testuri));

            // We measure the initial resource counts, and then allow a certain fudge factor for the resources
            // to fluctuate at run-time.  We allow for a certain amount of fluctuation, but if the counts
            // grow outside the safe boundaries of delayed garbage collection, then we fail the test.
            currentProcess = Process.GetCurrentProcess();
            int beginThreadCount = currentProcess.Threads.Count;
            int beginHandleCount = currentProcess.HandleCount;
            int maxThreadGrowth  = 10;
            int maxHandleGrowth  = 500;

            for (int i = 0; i < 200; i++)
            {
                using (IConnection connection = factory.CreateConnection("ResourceLeakTest", "Password"))
                {
                    using (ISession session = connection.CreateSession())
                    {
                        IDestination destination = SessionUtil.GetDestination(session, "topic://TEST.NMSResourceLeak");
                        using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        {
                            connection.Start();
                        }
                    }
                }

                currentProcess = Process.GetCurrentProcess();
                int endThreadCount = currentProcess.Threads.Count;
                int endHandleCount = currentProcess.HandleCount;

                Assert.Less(endThreadCount, beginThreadCount + maxThreadGrowth, string.Format("Thread count grew beyond maximum of {0} on iteration #{1}.", maxThreadGrowth, i));
                Assert.Less(endHandleCount, beginHandleCount + maxHandleGrowth, string.Format("Handle count grew beyond maximum of {0} on iteration #{1}.", maxHandleGrowth, i));
            }
        }
Beispiel #22
0
        public void TestConnectionFactorySetParams(
            [Values("tcp://${activemqhost}:61616", "activemq:tcp://${activemqhost}:61616")]
            string connectionURI,
            [Values(AcknowledgementMode.ClientAcknowledge, AcknowledgementMode.AutoAcknowledge)]
            AcknowledgementMode ackMode,
            [Values(true, false)]
            bool asyncSend,
            [Values(true, false)]
            bool alwaysSyncSend,
            [Values(true, false)]
            bool asyncClose,
            [Values(true, false)]
            bool copyMessageOnSend,
            [Values(3000, 1000)]
            int requestTimeout,
            [Values(true, false)]
            bool sendAcksAsync,
            [Values(true, false)]
            bool dispatchAsync)
        {
            NetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));

            factory.AcknowledgementMode = ackMode;
            factory.AsyncSend           = asyncSend;
            factory.AlwaysSyncSend      = alwaysSyncSend;
            factory.AsyncClose          = asyncClose;
            factory.CopyMessageOnSend   = copyMessageOnSend;
            factory.RequestTimeout      = requestTimeout;
            factory.SendAcksAsync       = sendAcksAsync;
            factory.DispatchAsync       = dispatchAsync;

            using (Connection connection = factory.CreateConnection() as Connection)
            {
                Assert.AreEqual(ackMode, connection.AcknowledgementMode);
                Assert.AreEqual(asyncSend, connection.AsyncSend);
                Assert.AreEqual(alwaysSyncSend, connection.AlwaysSyncSend);
                Assert.AreEqual(asyncClose, connection.AsyncClose);
                Assert.AreEqual(copyMessageOnSend, connection.CopyMessageOnSend);
                Assert.AreEqual(requestTimeout, connection.RequestTimeout.TotalMilliseconds);
                Assert.AreEqual(sendAcksAsync, connection.SendAcksAsync);
                Assert.AreEqual(dispatchAsync, connection.DispatchAsync);
            }
        }
Beispiel #23
0
        public void TestMessageDeliveredAfterCommitFailsAndRollback()
        {
            string             uri     = "failover:(tcpfaulty://${activemqhost}:61616?transport.useLogging=true)";
            IConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri));

            using (connection = factory.CreateConnection() as Connection)
            {
                using (ISession session = connection.CreateSession())
                {
                    IDestination destination = session.GetQueue(destinationName);
                    DeleteQueue(connection, destination);
                    PutOneMsgIntoQueue(session, destination);
                }

                using (ISession session = connection.CreateSession(AcknowledgementMode.Transactional))
                {
                    connection.Start();

                    ITransport         transport = (connection as Connection).ITransport;
                    TcpFaultyTransport tcpFaulty = transport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport;
                    Assert.IsNotNull(tcpFaulty);
                    tcpFaulty.OnewayCommandPreProcessor += this.FailOnCommitTransportHook;

                    IMessageConsumer consumer = session.CreateConsumer(session.GetQueue(destinationName));
                    IMessage         message  = consumer.Receive(TimeSpan.FromSeconds(30));
                    Assert.IsNotNull(message, "Message was not delivered");
                    Tracer.Debug("Commiting transaction");

                    try
                    {
                        Tracer.Info("Now attempting to commit the transaction");
                        session.Commit();
                    }
                    catch (Exception ex)
                    {
                        Tracer.InfoFormat("Commit failed as expected. {0}", ex.Message);
                    }

                    message = consumer.Receive(TimeSpan.FromSeconds(30));
                    Assert.IsNotNull(message, "message was not redilivered");
                }
            }
        }
Beispiel #24
0
        public void TestIndividualAcksWithClosedConsumerAndAuditSync()
        {
            const int    MSG_COUNT  = 20;
            const string QUEUE_NAME = "TEST.TestIndividualAcksWithClosedConsumerAndAuditSync";

            ProduceSomeMessages(MSG_COUNT, QUEUE_NAME);

            string             uri     = "failover:(tcp://${activemqhost}:61616)";
            IConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri));

            using (IConnection connection = factory.CreateConnection() as Connection)
                using (ISession session = connection.CreateSession(AcknowledgementMode.IndividualAcknowledge))
                    using (IQueue queue = session.GetQueue(QUEUE_NAME))
                    {
                        connection.Start();

                        // Consume all messages with no ACK
                        using (IMessageConsumer consumer = session.CreateConsumer(queue))
                        {
                            for (int i = 0; i < MSG_COUNT; ++i)
                            {
                                IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(3000));
                                Assert.NotNull(message);
                                Tracer.DebugFormat("Received message: {0}", message.NMSMessageId);
                            }
                        }

                        // Consumer the same batch again.
                        using (IMessageConsumer consumer = session.CreateConsumer(queue))
                        {
                            for (int i = 0; i < MSG_COUNT; ++i)
                            {
                                IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(3000));
                                Assert.NotNull(message);
                                Tracer.DebugFormat("Received message: {0}", message.NMSMessageId);
                            }
                        }

                        session.DeleteDestination(queue);
                    }
        }
Beispiel #25
0
        public void TestConfigureRecoveryPolicyLoggerType(
            [Values("tcp://${activemqhost}:61616?nms.RecoveryPolicy.RecoveryLoggerType=file")]
            string baseConnectionURI)
        {
            INetTxConnectionFactory factory = new NetTxConnectionFactory(NMSTestSupport.ReplaceEnvVar(baseConnectionURI));

            using (INetTxConnection connection = factory.CreateNetTxConnection())
            {
                NetTxConnection netTxConnection = connection as NetTxConnection;

                Assert.IsNotNull(netTxConnection);
                NetTxRecoveryPolicy policy = netTxConnection.RecoveryPolicy;

                Assert.AreEqual("file", policy.RecoveryLoggerType);

                RecoveryFileLogger logger = policy.RecoveryLogger as RecoveryFileLogger;

                Assert.IsNotNull(logger);
                Assert.AreEqual(Directory.GetCurrentDirectory(), logger.Location);
            }
        }
        public void TestURIForPrefetchHandlingOfAll(int allPreFetch)
        {
            string testuri = string.Format("activemq:tcp://${{activemqhost}}:61616" +
                                           "?nms.PrefetchPolicy.all={0}", allPreFetch);

            NMSConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(testuri));

            Assert.IsNotNull(factory);
            Assert.IsNotNull(factory.ConnectionFactory);
            using (IConnection connection = factory.CreateConnection("", ""))
            {
                Assert.IsNotNull(connection);

                Connection amqConnection = connection as Connection;
                Assert.AreEqual(allPreFetch, amqConnection.PrefetchPolicy.QueuePrefetch);
                Assert.AreEqual(allPreFetch, amqConnection.PrefetchPolicy.QueueBrowserPrefetch);
                Assert.AreEqual(allPreFetch, amqConnection.PrefetchPolicy.TopicPrefetch);
                Assert.AreEqual(allPreFetch, amqConnection.PrefetchPolicy.DurableTopicPrefetch);

                connection.Close();
            }
        }
        public void InvalidClientIdExceptionTest()
        {
            Uri uri = URISupport.CreateCompatibleUri(NMSTestSupport.ReplaceEnvVar(connectionURI));
            ConnectionFactory factory = new ConnectionFactory(uri);

            Assert.IsNotNull(factory);
            using (IConnection connection = factory.CreateConnection())
            {
                connection.ClientId = "FOO";
                connection.Start();

                try
                {
                    IConnection connection2 = factory.CreateConnection();
                    connection2.ClientId = "FOO";
                    connection2.Start();
                    Assert.Fail("Should throw an InvalidSelectorException");
                }
                catch (InvalidClientIDException)
                {
                }
            }
        }
Beispiel #28
0
        public void TestConnection()
        {
            IConnectionFactory factory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionUri));

            using (connection = factory.CreateConnection())
                using (ISession session = connection.CreateSession())
                {
                    IDestination destination = SessionUtil.GetDestination(session, "queue://TEST.test.in");
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        Connection amqConnection = connection as Connection;
                        connection.ExceptionListener += ConnectionException;

                        consumer.Listener += OnMessage;

                        TcpFaultyTransport transport = amqConnection.ITransport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport;
                        Assert.IsNotNull(transport);
                        transport.OnewayCommandPreProcessor += FailOnKeepAlive;

                        Thread.Sleep(TimeSpan.FromSeconds(2));

                        connection.Start();

                        int count = 30;
                        while (count-- > 0)
                        {
                            if (!connectionClosed)
                            {
                                Thread.Sleep(TimeSpan.FromSeconds(3));
                            }
                        }

                        Assert.IsTrue(connectionClosed);
                    }
                }
        }
Beispiel #29
0
        public void TestConnectUsingBasicTransport(
            [Values("tcpfaulty://${activemqhost}:61616", "activemq:tcpfaulty://${activemqhost}:61616")]
            string connectionURI)
        {
            ConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));

            using (Connection connection = factory.CreateConnection() as Connection)
            {
                ITransport transport = connection.ITransport.Narrow(typeof(TcpFaultyTransport)) as ITransport;
                Assert.IsNotNull(transport);

                TcpFaultyTransport testee = transport as TcpFaultyTransport;
                testee.OnewayCommandPreProcessor  += new CommandHandler(this.OnPreProcessCommand);
                testee.OnewayCommandPostProcessor += new CommandHandler(this.OnPostProcessCommand);

                using (ISession session = connection.CreateSession())
                {
                    Assert.IsTrue(session.Transacted == false);
                }

                Assert.IsTrue(this.preProcessorFired);
                Assert.IsTrue(this.postProcessorFired);
            }
        }
Beispiel #30
0
        public void FailoverBeforeCommitSentTest()
        {
            string             uri     = "failover:(tcpfaulty://${activemqhost}:61616?transport.useLogging=true)";
            IConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(uri));

            using (connection = factory.CreateConnection() as Connection)
            {
                connection.ConnectionInterruptedListener +=
                    new ConnectionInterruptedListener(TransportInterrupted);
                connection.ConnectionResumedListener +=
                    new ConnectionResumedListener(TransportResumed);

                connection.Start();

                ITransport         transport = (connection as Connection).ITransport;
                TcpFaultyTransport tcpFaulty = transport.Narrow(typeof(TcpFaultyTransport)) as TcpFaultyTransport;
                Assert.IsNotNull(tcpFaulty);
                tcpFaulty.OnewayCommandPreProcessor += this.FailOnCommitTransportHook;

                using (ISession session = connection.CreateSession())
                {
                    IDestination destination = session.GetQueue(destinationName);
                    PurgeQueue(connection, destination);
                }

                Tracer.Debug("Test is putting " + MSG_COUNT + " messages on the queue: " + destinationName);

                using (ISession session = connection.CreateSession(AcknowledgementMode.Transactional))
                {
                    IDestination destination = session.GetQueue(destinationName);
                    PutMsgIntoQueue(session, destination, false);

                    try
                    {
                        session.Commit();
                        Assert.Fail("Should have thrown a TransactionRolledBackException");
                    }
                    catch (TransactionRolledBackException)
                    {
                    }
                    catch
                    {
                        Assert.Fail("Should have thrown a TransactionRolledBackException");
                    }
                }

                Assert.IsTrue(this.interrupted);
                Assert.IsTrue(this.resumed);

                Tracer.Debug("Test is attempting to read a message from" +
                             destinationName + " but no messages are expected");

                using (ISession session = connection.CreateSession())
                {
                    IDestination     destination = session.GetQueue(destinationName);
                    IMessageConsumer consumer    = session.CreateConsumer(destination);
                    IMessage         msg         = consumer.Receive(TimeSpan.FromSeconds(5));
                    Assert.IsNull(msg, "Should not receive a message after commit failed.");
                }
            }

            Assert.IsTrue(this.interrupted);
            Assert.IsTrue(this.resumed);
        }