public void DisconnnectNotAttemptedWhenNotConnected()
        {
            Expect.Never.On(mockProducer);

            testActiveMqRemoteSender.Disconnect();
            mocks.VerifyAllExpectationsHaveBeenMet();
            Assert.AreEqual(false, testActiveMqRemoteSender.Connected);
        }
Ejemplo n.º 2
0
        public void DisconnectAfterDispose()
        {
            SetDisposeExpectations();
            testActiveMqRemoteSender.Dispose();
            ObjectDisposedException e = Assert.Throws <ObjectDisposedException>(delegate
            {
                testActiveMqRemoteSender.Disconnect();
            });

            Assert.AreEqual(e.ObjectName, "ActiveMqRemoteSender");
        }
        //------------------------------------------------------------------------------
        //
        // Method: Disconnect
        //
        //------------------------------------------------------------------------------
        /// <summary>
        /// Disconnects and cleans up the underlying MethodInvocationRemoting and ActiveMQ components.
        /// </summary>
        public void Disconnect()
        {
            methodInvocationReceiver.CancelReceive();
            incomingReceiver.CancelReceive();
            incomingReceiver.Disconnect();
            incomingSender.Disconnect();
            outgoingReceiver.CancelReceive();
            outgoingReceiver.Disconnect();
            outgoingSender.Disconnect();

            // Call dispose on the sender and receiver objects, as they hold unmanaged connections to ActiveMQ
            incomingReceiver.Dispose();
            incomingSender.Dispose();
            outgoingReceiver.Dispose();
            outgoingSender.Dispose();
        }
Ejemplo n.º 4
0
        public void DisconnectLoggingTest()
        {
            Expect.AtLeastOnce.On(mockConnection);
            Expect.AtLeastOnce.On(mockProducer);
            Expect.AtLeastOnce.On(mockSession);
            using (mocks.Ordered)
            {
                Expect.Once.On(mockApplicationLogger);
                Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteSender, LogLevel.Information, "Disconnected.");
            }

            testActiveMqRemoteSender.Connect();
            testActiveMqRemoteSender.Disconnect();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // Setup connection parameters for ActiveMQ
            const string connectUri                 = "activemq:tcp://localhost:61616?wireFormat.maxInactivityDuration=0";
            const string queueName                  = "FromJava";
            const string requestQueueFilter         = "Request";
            const string responseQueueFilter        = "Response";
            const int    receiverConnectLoopTimeout = 200;

            // Setup method invocation receiver
            ActiveMqRemoteSender           activeMqSender           = new ActiveMqRemoteSender(connectUri, queueName, responseQueueFilter);
            ActiveMqRemoteReceiver         activeMqReceiver         = new ActiveMqRemoteReceiver(connectUri, queueName, requestQueueFilter, receiverConnectLoopTimeout);
            MethodInvocationSerializer     methodSerializer         = new MethodInvocationSerializer(new SerializerOperationMap());
            MethodInvocationRemoteReceiver methodInvocationReceiver = new MethodInvocationRemoteReceiver(methodSerializer, activeMqSender, activeMqReceiver);

            methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation);

            try
            {
                // Connect to ActiveMQ
                activeMqSender.Connect();
                activeMqReceiver.Connect();
                // Start receiving method invocations
                methodInvocationReceiver.Receive();
                Console.WriteLine("Waiting for incoming method calls...");
                Console.WriteLine("Press [ENTER] to cancel.");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception occurred");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                // Stop receiving, disconnect, and dispose
                methodInvocationReceiver.CancelReceive();
                activeMqReceiver.CancelReceive();
                activeMqReceiver.Disconnect();
                activeMqSender.Disconnect();
                activeMqReceiver.Dispose();
                activeMqSender.Dispose();
            }
        }