예제 #1
0
        public async Task GeneratedService_GeneratedProxy_FailingLayerProvider_ServerReceiveReq()
        {
            // Fail after 1 successful GetLayerStack calls on server side
            var serverLayerStackProvider = new TestLayerStackProvider_Fails(1);
            TestClientServer <DummyTestService> testClientServer =
                await SetupTestClientServer <DummyTestService>(serverLayerStackProvider, null);

            var proxy   = new DummyTestProxy <EpoxyConnection>(testClientServer.ClientConnection);
            var request = new Dummy {
                int_value = 100
            };

            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);

            request.int_value = 101;
            response          = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            Error error = response.Error.Deserialize();

            Assert.AreEqual((int)ErrorCode.InternalServerError, error.error_code);
            Assert.AreEqual(Errors.InternalErrorMessage, error.message);

            await testClientServer.ServiceTransport.StopAsync();

            await testClientServer.ClientTransport.StopAsync();
        }
        public async Task MethodCall_ReqRsp_FailingLayerStackProvider_ServerReceiveReq()
        {
            // Fail after 3 successful GetLayerStack calls (2 on client, 1 on server)
            transportBuilder.SetLayerStackProvider(new TestLayerStackProvider_Fails(3));
            var testService = new DummyTestService();

            await DefaultSetup(testService, 1);

            var proxy   = new DummyTestProxy <SimpleInMemConnection>(connections[0]);
            var request = new Dummy {
                int_value = 100
            };
            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);

            request.int_value = 101;
            response          = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            Error error = response.Error.Deserialize();

            Assert.AreEqual((int)ErrorCode.INTERNAL_SERVER_ERROR, error.error_code);
            Assert.AreEqual(Errors.InternalErrorMessage, error.message);
        }
예제 #3
0
        public async Task GeneratedService_GeneratedProxy_PayloadResponse_ServerLayerErrors()
        {
            var errorLayer = new TestLayer_ReturnErrors();
            LayerStack <Dummy> serverLayerStack = new LayerStack <Dummy>(errorLayer);
            TestClientServer <DummyTestService> testClientServer = await SetupTestClientServer <DummyTestService>(serverLayerStack, null);

            var proxy   = new DummyTestProxy <EpoxyConnection>(testClientServer.ClientConnection);
            var request = new Dummy {
                int_value = 100
            };

            errorLayer.SetState(MessageType.Request, errorOnSend: false, errorOnReceive: true);

            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            Assert.AreEqual(TestLayer_ReturnErrors.ReceiveError, response.Error.Deserialize().error_code);

            Assert.AreEqual(0, testClientServer.Service.RequestCount);
            Assert.AreEqual(Dummy.Empty.int_value, testClientServer.Service.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.Response, errorOnSend: true, errorOnReceive: false);
            response = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            Assert.AreEqual(TestLayer_ReturnErrors.SendError, response.Error.Deserialize().error_code);

            Assert.AreEqual(1, testClientServer.Service.RequestCount);
            Assert.AreEqual(request.int_value, testClientServer.Service.LastRequestReceived.int_value);

            await testClientServer.ServiceTransport.StopAsync();

            await testClientServer.ClientTransport.StopAsync();
        }
예제 #4
0
        async Task AssertRequestResponseWorksAsync(DummyTestProxy <EpoxyConnection> proxy)
        {
            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(new Dummy { int_value = 100 });

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);
        }
예제 #5
0
        public async Task GeneratedService_GeneratedProxy_FailingLayerProvider_ClientSendReq()
        {
            // Fail after 1 successful GetLayerStack calls on client side
            var clientLayerStackProvider = new TestLayerStackProvider_Fails(1);
            TestClientServer <DummyTestService> testClientServer =
                await SetupTestClientServer <DummyTestService>(null, clientLayerStackProvider);

            var proxy = new DummyTestProxy <EpoxyConnection>(testClientServer.ClientConnection);

            await AssertRequestResponseWorksAsync(proxy);

            var request = new Dummy {
                int_value = 101
            };
            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            Error error = response.Error.Deserialize();

            Assert.AreEqual((int)ErrorCode.INTERNAL_SERVER_ERROR, error.error_code);
            Assert.AreEqual(TestLayerStackProvider_Fails.InternalDetails, error.message);

            await testClientServer.ServiceTransport.StopAsync();

            await testClientServer.ClientTransport.StopAsync();
        }
예제 #6
0
        public async Task GeneratedService_GeneratedProxy_PayloadResponse_StatefulLayers()
        {
            var clientLayerProvider      = new TestLayerProvider_StatefulAppend("Client");
            var clientLayerStackProvider = new LayerStackProvider <Dummy>(LoggerTests.BlackHole, clientLayerProvider);
            var serverLayerProvider      = new TestLayerProvider_StatefulAppend("Server");
            var serverLayerStackProvider = new LayerStackProvider <Dummy>(LoggerTests.BlackHole, serverLayerProvider);
            TestClientServer <DummyTestService> testClientServer =
                await SetupTestClientServer <DummyTestService>(serverLayerStackProvider, clientLayerStackProvider);

            var proxy   = new DummyTestProxy <EpoxyConnection>(testClientServer.ClientConnection);
            var request = new Dummy {
                int_value = 100
            };

            clientLayerProvider.Layers.Clear();
            serverLayerProvider.Layers.Clear();

            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);

            Assert.AreEqual(1, clientLayerProvider.Layers.Count);
            Assert.AreEqual(1, serverLayerProvider.Layers.Count);
            Assert.AreEqual("Client0SendClient0Receive", clientLayerProvider.Layers[0].State);
            Assert.AreEqual("Server0ReceiveServer0Send", serverLayerProvider.Layers[0].State);

            request.int_value = 101;
            response          = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(102, response.Payload.Deserialize().int_value);

            Assert.AreEqual(2, clientLayerProvider.Layers.Count);
            Assert.AreEqual(2, serverLayerProvider.Layers.Count);
            Assert.AreEqual("Client1SendClient1Receive", clientLayerProvider.Layers[1].State);
            Assert.AreEqual("Server1ReceiveServer1Send", serverLayerProvider.Layers[1].State);

            await testClientServer.ServiceTransport.StopAsync();

            await testClientServer.ClientTransport.StopAsync();
        }
예제 #7
0
        public async Task GeneratedService_GeneratedProxy_PayloadResponse()
        {
            TestClientServer <DummyTestService> testClientServer = await SetupTestClientServer <DummyTestService>();

            var proxy   = new DummyTestProxy <EpoxyConnection>(testClientServer.ClientConnection);
            var request = new Dummy {
                int_value = 100
            };
            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);

            Assert.AreEqual(1, testClientServer.Service.RequestCount);
            Assert.AreEqual(0, testClientServer.Service.EventCount);
            Assert.AreEqual(request.int_value, testClientServer.Service.LastRequestReceived.int_value);
        }
예제 #8
0
        public async Task GeneratedService_GeneratedProxy_PayloadResponse_LayerData()
        {
            LayerStack <Dummy> layerStack = new LayerStack <Dummy>(new TestLayer_CheckPassedValue(1234));
            TestClientServer <DummyTestService> testClientServer = await SetupTestClientServer <DummyTestService>(layerStack, layerStack);

            var proxy   = new DummyTestProxy <EpoxyConnection>(testClientServer.ClientConnection);
            var request = new Dummy {
                int_value = 100
            };
            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);

            Assert.AreEqual(1, testClientServer.Service.RequestCount);

            await testClientServer.ServiceTransport.StopAsync();

            await testClientServer.ClientTransport.StopAsync();
        }
예제 #9
0
        public async Task IPv6Listener_RequestReply_PayloadResponse()
        {
            var transport = new EpoxyTransportBuilder().Construct();

            transports.Add(transport);
            var listener = transport.MakeListener(new IPEndPoint(IPAddress.IPv6Loopback, EpoxyTransport.DefaultInsecurePort));

            listener.AddService(new DummyTestService());
            await listener.StartAsync();

            EpoxyConnection conn = await transport.ConnectToAsync("epoxy://[::1]");

            var proxy   = new DummyTestProxy <EpoxyConnection>(conn);
            var request = new Dummy {
                int_value = 100
            };

            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);
        }
예제 #10
0
        public async Task IsolatedLoggingAndMetrics()
        {
            // Create two services on their own transports with separate ILogSinks and IMetricsSinks.
            // Create one client for each service on separate transports so they don't log or emit metrics.
            // Make one request for each client-server pair.
            //
            // Each logging sink should see exactly one message from a particular point in the code that processes
            // requests, and the messages seen by each sink should be different (because the Connections are
            // different). Each metrics sink should see exactly one ConnectionMetrics and one RequestMetrics, and their
            // identifying GUIDs should be different.

            // This can be any method that isn't in a transport implementation, will be called once per request, and
            // will be called zero times outside the request path.
            const string chosenMethodName = nameof(ServiceHost.DispatchRequest);

            var firstLogSink      = new InMemLogSink();
            var firstMetricsSink  = new InMemMetricsSink();
            var secondLogSink     = new InMemLogSink();
            var secondMetricsSink = new InMemMetricsSink();

            var firstEndPoint  = new IPEndPoint(IPAddress.Loopback, 10001);
            var firstAddress   = "epoxy://127.0.0.1:10001";
            var secondEndPoint = new IPEndPoint(IPAddress.Loopback, 10002);
            var secondAddress  = "epoxy://127.0.0.1:10002";

            var firstServer = await Server(firstLogSink, firstMetricsSink, firstEndPoint);

            var firstClientConn = await ClientConn(firstAddress);

            var firstProxy   = new DummyTestProxy <EpoxyConnection>(firstClientConn);
            var secondServer = await Server(secondLogSink, secondMetricsSink, secondEndPoint);

            var secondClientConn = await ClientConn(secondAddress);

            var secondProxy = new DummyTestProxy <EpoxyConnection>(secondClientConn);

            await firstProxy.ReqRspMethodAsync(new Dummy());

            await secondProxy.ReqRspMethodAsync(new Dummy());

            await firstClientConn.StopAsync();

            await secondClientConn.StopAsync();

            await firstServer.StopAsync();

            await secondServer.StopAsync();

            WaitForLogsAndMetrics();

            // We're targeting a log line that looks something like this:
            // C:\...\bond\cs\src\comm\service\ServiceHost.cs:119 - DispatchRequest - Got request [unittest.comm.DummyTest.ReqRspMethod] from EpoxyConnection(local: 127.0.0.1:20000, remote: 127.0.0.1:26056).
            var firstSinkTargetMessages  = firstLogSink.Messages.Where(l => l.Contains(chosenMethodName)).ToList();
            var secondSinkTargetMessages = secondLogSink.Messages.Where(l => l.Contains(chosenMethodName)).ToList();

            Assert.AreEqual(1, firstSinkTargetMessages.Count);
            Assert.AreEqual(1, secondSinkTargetMessages.Count);

            Assert.AreNotEqual(firstSinkTargetMessages.First(), secondSinkTargetMessages.First());

            // Each metrics sink should have seen one set of connection metrics and one set of request metrics.
            Assert.AreEqual(1, firstMetricsSink.ConnectionMetricses.Count);
            Assert.AreEqual(1, firstMetricsSink.RequestMetricses.Count);
            Assert.AreEqual(1, secondMetricsSink.ConnectionMetricses.Count);
            Assert.AreEqual(1, secondMetricsSink.RequestMetricses.Count);

            Assert.AreNotEqual(firstMetricsSink.ConnectionMetricses.First().connection_id,
                               secondMetricsSink.ConnectionMetricses.First().connection_id);
            Assert.AreNotEqual(firstMetricsSink.RequestMetricses.First().request_id,
                               secondMetricsSink.RequestMetricses.First().request_id);
        }
예제 #11
0
        public async Task MethodCall_ReqRsp_FailingLayerStackProvider_ServerReceiveReq()
        {
            // Fail after 3 successful GetLayerStack calls (2 on client, 1 on server)
            transportBuilder.SetLayerStackProvider(new TestLayerStackProvider_Fails(3));
            var testService = new DummyTestService();
            await DefaultSetup(testService, 1);

            var proxy = new DummyTestProxy<SimpleInMemConnection>(connections[0]);
            var request = new Dummy { int_value = 100 };
            IMessage<Dummy> response = await proxy.ReqRspMethodAsync(request);
            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);

            request.int_value = 101;
            response = await proxy.ReqRspMethodAsync(request);
            Assert.IsTrue(response.IsError);
            Error error = response.Error.Deserialize();
            Assert.AreEqual((int)ErrorCode.InternalServerError, error.error_code);
            Assert.AreEqual(Errors.InternalErrorMessage, error.message);
        }
예제 #12
0
        public async Task GeneratedService_GeneratedProxy_PayloadResponse()
        {
            TestClientServer<DummyTestService> testClientServer = await SetupTestClientServer<DummyTestService>();
            var proxy = new DummyTestProxy<EpoxyConnection>(testClientServer.ClientConnection);
            var request = new Dummy { int_value = 100 };
            IMessage<Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);

            Assert.AreEqual(1, testClientServer.Service.RequestCount);
            Assert.AreEqual(0, testClientServer.Service.EventCount);
            Assert.AreEqual(request.int_value, testClientServer.Service.LastRequestReceived.int_value);

            await testClientServer.ServiceTransport.StopAsync();
            await testClientServer.ClientTransport.StopAsync();
        }
        public async Task MethodCall_ReqRsp_WithLayerStackErrors()
        {
            var errorLayer = new TestLayer_ReturnErrors();

            transportBuilder.SetLayerStackProvider(new LayerStackProvider <Dummy>(errorLayer));
            var testService = new DummyTestService();

            await DefaultSetup(testService, 1);

            var proxy   = new DummyTestProxy <SimpleInMemConnection>(connections[0]);
            var request = new Dummy {
                int_value = 100
            };

            errorLayer.SetState(MessageType.REQUEST, errorOnSend: false, errorOnReceive: true);
            IMessage <Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            Error error = response.Error.Deserialize();

            Assert.AreEqual(TestLayer_ReturnErrors.ReceiveError, error.error_code, "Error 1 does not match");

            Assert.AreEqual(0, testService.RequestCount);
            Assert.AreEqual(Dummy.Empty.int_value, testService.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.REQUEST, errorOnSend: true, errorOnReceive: false);
            request.int_value = 101;
            response          = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.SendError, error.error_code, "Error 2 does not match");

            Assert.AreEqual(0, testService.RequestCount);
            Assert.AreEqual(Dummy.Empty.int_value, testService.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.RESPONSE, errorOnSend: true, errorOnReceive: false);
            request.int_value = 102;
            response          = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.SendError, error.error_code, "Error 3 does not match");

            Assert.AreEqual(1, testService.RequestCount);
            Assert.AreEqual(request.int_value, testService.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.RESPONSE, errorOnSend: false, errorOnReceive: true);
            request.int_value = 103;
            response          = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.ReceiveError, error.error_code, "Error 4 does not match");

            Assert.AreEqual(2, testService.RequestCount);
            Assert.AreEqual(request.int_value, testService.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.EVENT, errorOnSend: true, errorOnReceive: true);
            request.int_value = 104;
            response          = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(105, response.Payload.Deserialize().int_value);

            Assert.AreEqual(3, testService.RequestCount);
            Assert.AreEqual(request.int_value, testService.LastRequestReceived.int_value);
        }
예제 #14
0
 async Task AssertRequestResponseWorksAsync(DummyTestProxy<EpoxyConnection> proxy)
 {
     IMessage<Dummy> response = await proxy.ReqRspMethodAsync(new Dummy { int_value = 100 });
     Assert.IsFalse(response.IsError);
     Assert.AreEqual(101, response.Payload.Deserialize().int_value);
 }
예제 #15
0
        public async Task IPv6Listener_RequestReply_PayloadResponse()
        {
            var transport = new EpoxyTransportBuilder().Construct();
            listener = transport.MakeListener(new IPEndPoint(IPAddress.IPv6Loopback, EpoxyTransport.DefaultInsecurePort));
            listener.AddService(new DummyTestService());
            await listener.StartAsync();

            EpoxyConnection conn = await transport.ConnectToAsync("epoxy://[::1]");
            var proxy = new DummyTestProxy<EpoxyConnection>(conn);
            var request = new Dummy { int_value = 100 };

            IMessage<Dummy> response = await proxy.ReqRspMethodAsync(request);
            Assert.IsFalse(response.IsError);
            Assert.AreEqual(101, response.Payload.Deserialize().int_value);

            await transport.StopAsync();
        }
예제 #16
0
        public async Task GeneratedService_GeneratedProxy_FailingLayerProvider_ServerReceiveReq()
        {
            // Fail after 1 successful GetLayerStack calls on server side
            var serverLayerStackProvider = new TestLayerStackProvider_Fails(1);
            TestClientServer<DummyTestService> testClientServer =
                await SetupTestClientServer<DummyTestService>(serverLayerStackProvider, null);
            var proxy = new DummyTestProxy<EpoxyConnection>(testClientServer.ClientConnection);

            await AssertRequestResponseWorksAsync(proxy);

            var request = new Dummy { int_value = 101 };
            IMessage<Dummy> response = await proxy.ReqRspMethodAsync(request);
            Assert.IsTrue(response.IsError);
            Error error = response.Error.Deserialize();
            Assert.AreEqual((int)ErrorCode.INTERNAL_SERVER_ERROR, error.error_code);
            Assert.AreEqual(Errors.InternalErrorMessage, error.message);

            await testClientServer.ServiceTransport.StopAsync();
            await testClientServer.ClientTransport.StopAsync();
        }
예제 #17
0
        public async Task GeneratedService_GeneratedProxy_PayloadResponse_ServerLayerErrors()
        {
            var errorLayer = new TestLayer_ReturnErrors();
            var serverLayerStackProvider = new LayerStackProvider<Dummy>(LoggerTests.BlackHole, errorLayer);
            TestClientServer<DummyTestService> testClientServer = await SetupTestClientServer<DummyTestService>(serverLayerStackProvider, null);
            var proxy = new DummyTestProxy<EpoxyConnection>(testClientServer.ClientConnection);
            var request = new Dummy { int_value = 100 };

            errorLayer.SetState(MessageType.REQUEST, errorOnSend: false, errorOnReceive: true);

            IMessage<Dummy> response = await proxy.ReqRspMethodAsync(request);
            Assert.IsTrue(response.IsError);
            Error error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.ReceiveError, error.error_code);

            Assert.AreEqual(0, testClientServer.Service.RequestCount);
            Assert.AreEqual(Dummy.Empty.int_value, testClientServer.Service.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.RESPONSE, errorOnSend: true, errorOnReceive: false);
            response = await proxy.ReqRspMethodAsync(request);
            Assert.IsTrue(response.IsError);
            error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.SendError, error.error_code);

            Assert.AreEqual(1, testClientServer.Service.RequestCount);
            Assert.AreEqual(request.int_value, testClientServer.Service.LastRequestReceived.int_value);

            await testClientServer.ServiceTransport.StopAsync();
            await testClientServer.ClientTransport.StopAsync();
        }
예제 #18
0
        public async Task MethodCall_ReqRsp_WithLayerStackErrors()
        {
            var errorLayer = new TestLayer_ReturnErrors();
            transportBuilder.SetLayerStackProvider(new LayerStackProvider<Dummy>(LoggerTests.BlackHole, errorLayer));
            var testService = new DummyTestService();
            await DefaultSetup(testService, 1);

            var proxy = new DummyTestProxy<SimpleInMemConnection>(connections[0]);
            var request = new Dummy { int_value = 100 };

            errorLayer.SetState(MessageType.Request, errorOnSend: false, errorOnReceive: true);
            IMessage<Dummy> response = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            Error error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.ReceiveError, error.error_code, "Error 1 does not match");

            Assert.AreEqual(0, testService.RequestCount);
            Assert.AreEqual(Dummy.Empty.int_value, testService.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.Request, errorOnSend: true, errorOnReceive: false);
            request.int_value = 101;
            response = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.SendError, error.error_code, "Error 2 does not match");

            Assert.AreEqual(0, testService.RequestCount);
            Assert.AreEqual(Dummy.Empty.int_value, testService.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.Response, errorOnSend: true, errorOnReceive: false);
            request.int_value = 102;
            response = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.SendError, error.error_code, "Error 3 does not match");

            Assert.AreEqual(1, testService.RequestCount);
            Assert.AreEqual(request.int_value, testService.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.Response, errorOnSend: false, errorOnReceive: true);
            request.int_value = 103;
            response = await proxy.ReqRspMethodAsync(request);

            Assert.IsTrue(response.IsError);
            error = response.Error.Deserialize();
            Assert.AreEqual(TestLayer_ReturnErrors.ReceiveError, error.error_code, "Error 4 does not match");

            Assert.AreEqual(2, testService.RequestCount);
            Assert.AreEqual(request.int_value, testService.LastRequestReceived.int_value);

            errorLayer.SetState(MessageType.Event, errorOnSend: true, errorOnReceive: true);
            request.int_value = 104;
            response = await proxy.ReqRspMethodAsync(request);

            Assert.IsFalse(response.IsError);
            Assert.AreEqual(105, response.Payload.Deserialize().int_value);

            Assert.AreEqual(3, testService.RequestCount);
            Assert.AreEqual(request.int_value, testService.LastRequestReceived.int_value);
        }
예제 #19
0
        public async Task IsolatedLoggingAndMetrics()
        {
            // Create two services on their own transports with separate ILogSinks and IMetricsSinks.
            // Create one client for each service on separate transports so they don't log or emit metrics.
            // Make one request for each client-server pair.
            //
            // Each logging sink should see exactly one message from a particular point in the code that processes
            // requests, and the messages seen by each sink should be different (because the Connections are
            // different). Each metrics sink should see exactly one ConnectionMetrics and one RequestMetrics, and their
            // identifying GUIDs should be different.

            // This can be any method that isn't in a transport implementation, will be called once per request, and
            // will be called zero times outside the request path.
            const string chosenMethodName = nameof(ServiceHost.DispatchRequest);

            var firstLogSink = new InMemLogSink();
            var firstMetricsSink = new InMemMetricsSink();
            var secondLogSink = new InMemLogSink();
            var secondMetricsSink = new InMemMetricsSink();

            var firstEndPoint = new IPEndPoint(IPAddress.Loopback, 10001);
            var firstAddress = "epoxy://127.0.0.1:10001";
            var secondEndPoint = new IPEndPoint(IPAddress.Loopback, 10002);
            var secondAddress = "epoxy://127.0.0.1:10002";

            var firstServer = await Server(firstLogSink, firstMetricsSink, firstEndPoint);
            var firstClientConn = await ClientConn(firstAddress);
            var firstProxy = new DummyTestProxy<EpoxyConnection>(firstClientConn);
            var secondServer = await Server(secondLogSink, secondMetricsSink, secondEndPoint);
            var secondClientConn = await ClientConn(secondAddress);
            var secondProxy = new DummyTestProxy<EpoxyConnection>(secondClientConn);

            await firstProxy.ReqRspMethodAsync(new Dummy());
            await secondProxy.ReqRspMethodAsync(new Dummy());

            await firstClientConn.StopAsync();
            await secondClientConn.StopAsync();
            await firstServer.StopAsync();
            await secondServer.StopAsync();

            // We're targeting a log line that looks something like this:
            // C:\...\bond\cs\src\comm\service\ServiceHost.cs:119 - DispatchRequest - Got request [unittest.comm.DummyTest.ReqRspMethod] from EpoxyConnection(local: 127.0.0.1:20000, remote: 127.0.0.1:26056).
            var firstSinkTargetMessages = firstLogSink.Messages.Where(l => l.Contains(chosenMethodName)).ToList();
            var secondSinkTargetMessages = secondLogSink.Messages.Where(l => l.Contains(chosenMethodName)).ToList();

            Assert.AreEqual(1, firstSinkTargetMessages.Count);
            Assert.AreEqual(1, secondSinkTargetMessages.Count);

            Assert.AreNotEqual(firstSinkTargetMessages.First(), secondSinkTargetMessages.First());

            // Each metrics sink should have seen one set of connection metrics and one set of request metrics.
            Assert.AreEqual(1, firstMetricsSink.ConnectionMetricses.Count);
            Assert.AreEqual(1, firstMetricsSink.RequestMetricses.Count);
            Assert.AreEqual(1, secondMetricsSink.ConnectionMetricses.Count);
            Assert.AreEqual(1, secondMetricsSink.RequestMetricses.Count);

            Assert.AreNotEqual(firstMetricsSink.ConnectionMetricses.First().connection_id,
                               secondMetricsSink.ConnectionMetricses.First().connection_id);
            Assert.AreNotEqual(firstMetricsSink.RequestMetricses.First().request_id,
                               secondMetricsSink.RequestMetricses.First().request_id);
        }