public void ReceiveAfterNoDataAvailableMetricsTest()
        {
            // Tests where the loop in the Receive() method iterates through once with no data being available before the message is received

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Expects for Receive() where no data is available
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(0));
                // Expects for Receive() where data is available
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockNetworkStream).Method("Read").Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte");
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveAvailableDataExceptionMetricsTest()
        {
            // Tests where a socket exception occurs whilst checking the underlying client for available data, afterwhich the class reconnects and receives a message
            //   Ensures the correct order of metric logging in this case, especially that a corresponding End() is called for each Begin()

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Set expectations for socket exception when checking available data
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Throw.Exception(new System.Net.Sockets.SocketException(1)));
                SetReconnectExpectations();
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new TcpRemoteReceiverReconnected()));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[testMessageByteArray.Length], 0, testMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveDuplicateSequenceNumberMetricsTest()
        {
            // Tests that a message received with the same sequence number as the previous message is ignored
            //   Ensures the correct order of metric logging in this case, especially that a corresponding End() is called for each Begin()

            byte[] secondMessageByteArray = new byte[testMessageByteArray.Length];
            Array.Copy(testMessageByteArray, secondMessageByteArray, testMessageByteArray.Length);
            // Update the sequence number in the second message
            byte[] updatedSequenceNumber = BitConverter.GetBytes(124);
            if (BitConverter.IsLittleEndian == false)
            {
                Array.Reverse(updatedSequenceNumber);
            }
            Array.Copy(updatedSequenceNumber, 0, secondMessageByteArray, 1, updatedSequenceNumber.Length);
            // Update the body of the second message to be <Data>XYZ</Data>
            secondMessageByteArray[19] = 0x58;
            secondMessageByteArray[20] = 0x59;
            secondMessageByteArray[21] = 0x5A;

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Set expectations for receiving first message
                SetBeginMessageReceiveExpectations(testMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[testMessageByteArray.Length], 0, testMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
                // Set expectations for receiving duplicate message
                SetBeginMessageReceiveExpectations(testMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[testMessageByteArray.Length], 0, testMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new TcpRemoteReceiverDuplicateSequenceNumber()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                // Set expectations for receiving next message
                SetBeginMessageReceiveExpectations(secondMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[secondMessageByteArray.Length], 0, secondMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", secondMessageByteArray), Return.Value(secondMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #4
0
        public void SerializeReturnValueMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new ReturnValueSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new ReturnValueSerialized()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new SerializedReturnValueSize(117)));
            }

            testMethodInvocationSerializer.SerializeReturnValue("ReturnString");

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #5
0
        public void SerializeMetricsTest()
        {
            MethodInvocation testMethodInvocation = new MethodInvocation("TestMethod", new object[] { "abc", ((int)123), null, ((double)456.789) });

            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MethodInvocationSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MethodInvocationSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MethodInvocationSerialized()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new SerializedMethodInvocationSize(381)));
            }
            testMethodInvocationSerializer.Serialize(testMethodInvocation);

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveMetricsTest()
        {
            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Expects for Receive()
                SetBeginMessageReceiveExpectations(testMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte");
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #7
0
        public void ReceiveMetricsTest()
        {
            string receivedMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>TestMethod</MethodName><Parameters><Parameter><DataType>string</DataType><Data>abc</Data></Parameter><Parameter><DataType>integer</DataType><Data>123</Data></Parameter><Parameter /><Parameter><DataType>double</DataType><Data>4.5678899999999999e+002</Data></Parameter></Parameters><ReturnType /></MethodInvocation>";

            using (mocks.Ordered)
            {
                Expect.Once.On(mockFileSystem).Method("CheckFileExists").With(messageFilePath).Will(Return.Value(true));
                Expect.Once.On(mockFileSystem).Method("CheckFileExists").With(lockFilePath).Will(Return.Value(false));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMessageFile).Method("ReadAll").WithNoArguments().Will(Return.Value(receivedMessage));
                Expect.AtLeastOnce.On(mockFileSystem);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(381)));
            }

            testFileRemoteReceiver.Receive();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #8
0
        public void SendMetricsTest()
        {
            Expect.AtLeastOnce.On(mockRemoteSender);
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new StringCompressTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new StringCompressTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new StringCompressed()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new CompressedStringSize(1492)));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new StringCompressTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new StringCompressTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new StringCompressed()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new CompressedStringSize(0)));
            }

            testRemoteSenderCompressor.Send("<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>MethodWithAllDataTypeAsParameters</MethodName><Parameters><Parameter><DataType>integer</DataType><Data>123</Data></Parameter><Parameter><DataType>dateTimeArray</DataType><Data><ElementDataType>dateTime</ElementDataType><Element><DataType>dateTime</DataType><Data>0001-01-01T00:00:00.000</Data></Element><Element><DataType>dateTime</DataType><Data>9999-12-31T23:59:59.999</Data></Element></Data></Parameter><Parameter><DataType>string</DataType><Data>&lt;TestString&gt;This is a test string &lt;&gt;?/:\";''[]{}+=_-)(*&amp;^%$#@!|\\&lt;/TestString&gt;</Data></Parameter><Parameter><DataType>decimalArray</DataType><Data><ElementDataType>decimal</ElementDataType><Element><DataType>decimal</DataType><Data>-79228162514264337593543950335</Data></Element><Element><DataType>decimal</DataType><Data>79228162514264337593543950335</Data></Element></Data></Parameter><Parameter><DataType>signedByte</DataType><Data>8</Data></Parameter><Parameter><DataType>boolArray</DataType><Data><ElementDataType>bool</ElementDataType><Element><DataType>bool</DataType><Data>false</Data></Element><Element><DataType>bool</DataType><Data>true</Data></Element></Data></Parameter><Parameter><DataType>shortInteger</DataType><Data>-16343</Data></Parameter><Parameter><DataType>charArray</DataType><Data><ElementDataType>char</ElementDataType><Element><DataType>char</DataType><Data>M</Data></Element><Element><DataType>char</DataType><Data>&lt;</Data></Element></Data></Parameter><Parameter><DataType>longInteger</DataType><Data>76543</Data></Parameter><Parameter><DataType>doubleArray</DataType><Data><ElementDataType>double</ElementDataType><Element><DataType>double</DataType><Data>-1.6976931348623213E-308</Data></Element><Element><DataType>double</DataType><Data>1.6976931348623213E308</Data></Element></Data></Parameter><Parameter><DataType>float</DataType><Data>-Infinity</Data></Parameter><Parameter><DataType>floatArray</DataType><Data><ElementDataType>float</ElementDataType><Element><DataType>float</DataType><Data>-3.14159261E-38</Data></Element><Element><DataType>float</DataType><Data>3.14159272E38</Data></Element></Data></Parameter><Parameter><DataType>double</DataType><Data>Infinity</Data></Parameter><Parameter><DataType>longIntegerArray</DataType><Data><ElementDataType>longInteger</ElementDataType><Element><DataType>longInteger</DataType><Data>-9223372036854775808</Data></Element><Element><DataType>longInteger</DataType><Data>9223372036854775807</Data></Element></Data></Parameter><Parameter><DataType>char</DataType><Data>!</Data></Parameter><Parameter><DataType>shortIntegerArray</DataType><Data><ElementDataType>shortInteger</ElementDataType><Element><DataType>shortInteger</DataType><Data>-32768</Data></Element><Element><DataType>shortInteger</DataType><Data>32767</Data></Element></Data></Parameter><Parameter><DataType>bool</DataType><Data>true</Data></Parameter><Parameter><DataType>signedByteArray</DataType><Data><ElementDataType>signedByte</ElementDataType><Element><DataType>signedByte</DataType><Data>-128</Data></Element><Element><DataType>signedByte</DataType><Data>127</Data></Element></Data></Parameter><Parameter><DataType>decimal</DataType><Data>40958609456.39898479845</Data></Parameter><Parameter><DataType>stringArray</DataType><Data><ElementDataType>string</ElementDataType><Element><DataType>string</DataType><Data>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus in nulla magna, non cursus elit. Vivamus velit dolor, aliquet a.</Data></Element><Element><DataType>string</DataType><Data><Empty></Empty></Data></Element></Data></Parameter><Parameter><DataType>dateTime</DataType><Data>2013-05-01T12:43:56.654</Data></Parameter><Parameter><DataType>integerArray</DataType><Data><ElementDataType>integer</ElementDataType><Element><DataType>integer</DataType><Data>-2147483648</Data></Element><Element><DataType>integer</DataType><Data>2147483647</Data></Element></Data></Parameter><Parameter><DataType>decimalArray</DataType><Data><ElementDataType>decimal</ElementDataType></Data></Parameter><Parameter><DataType>stringArray</DataType><Data><ElementDataType>string</ElementDataType><Element><DataType>string</DataType><Data>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut aliquet quam sit amet massa tincidunt a interdum purus interdum. Cras.</Data></Element><Element><DataType>string</DataType><Data>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vitae velit tellus, non interdum urna. Quisque vehicula augue eu mauris.</Data></Element><Element></Element></Data></Parameter><Parameter></Parameter></Parameters><ReturnType><DataType>dateTime</DataType></ReturnType></MethodInvocation>");
            testRemoteSenderCompressor.Send("");

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveReconnectMetricsTest()
        {
            // Tests receiving a message, where a new pending connection is detected and accepted after reading just the start delimiter byte from the initial connection
            //   Ensures the correct order of metric logging in this case, especially that a corresponding End() is called for each Begin()

            byte[] shortMessageByteArray = new byte[1];
            Array.Copy(testMessageByteArray, 0, shortMessageByteArray, 0, 1);

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Set expectations for reading partial message
                SetBeginMessageReceiveExpectations(shortMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[shortMessageByteArray.Length], 0, shortMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", shortMessageByteArray), Return.Value(shortMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(true));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                // Set expectations for reconnect
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(true));
                SetReconnectExpectations();
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new TcpRemoteReceiverReconnected()));
                // Set expectations for reading whole message
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[testMessageByteArray.Length], 0, testMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            string receivedMessage = testTcpRemoteReceiver.Receive();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveMetricsTest()
        {
            ITextMessage  mockTextMessage           = mocks.NewMock <ITextMessage>();
            IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>();
            string        receivedMessage           = "<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>TestMethod</MethodName><Parameters><Parameter><DataType>string</DataType><Data>abc</Data></Parameter><Parameter><DataType>integer</DataType><Data>123</Data></Parameter><Parameter /><Parameter><DataType>double</DataType><Data>4.5678899999999999e+002</Data></Parameter></Parameters><ReturnType /></MethodInvocation>";

            using (mocks.Ordered)
            {
                // Expects for Connect()
                Expect.AtLeastOnce.On(mockConnection);
                // Expects for first Receive()
                Expect.Once.On(mockConsumer).Method("Receive").WithAnyArguments().Will(Return.Value(mockTextMessage));
                Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties));
                Expect.Once.On(mockTextMessageProperties).Method("GetString").With("Text").Will(Return.Value(receivedMessage));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(381)));
            }

            testActiveMqRemoteReceiver.Connect();
            testActiveMqRemoteReceiver.Receive();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }