public async Task MethodCall_Event_FailingLayerStackProvider_ServerReceiveEvent()
        {
            // 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 theEvent = new Dummy {
                int_value = 100
            };

            ManualResetEventSlim waitForEvent = testService.CreateResetEvent();

            proxy.EventMethodAsync(theEvent);
            bool wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));

            Assert.IsTrue(wasSignaled, "Timed out waiting for event to fire");

            Assert.AreEqual(1, testService.EventCount);
            Assert.AreEqual(theEvent.int_value, testService.LastEventReceived.int_value);

            waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsFalse(wasSignaled, "Event should not fire 2");

            Assert.AreEqual(1, testService.EventCount);
        }
        public async Task MethodCall_Event_With_StatefulLayers()
        {
            var layerProvider      = new TestLayerProvider_StatefulAppend("Layer");
            var layerStackProvider = new LayerStackProvider <Dummy>(layerProvider);

            transportBuilder.SetLayerStackProvider(layerStackProvider);
            var testService = new DummyTestService();

            await DefaultSetup(testService, 1);

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

            layerProvider.Layers.Clear();

            ManualResetEventSlim waitForEvent = testService.CreateResetEvent();

            proxy.EventMethodAsync(theEvent);
            bool wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));

            Assert.IsTrue(wasSignaled, "Timed out waiting for event to fire");
            testService.ClearResetEvent();

            Assert.AreEqual(1, testService.EventCount);
            Assert.AreEqual(theEvent.int_value, testService.LastEventReceived.int_value);

            Assert.AreEqual(2, layerProvider.Layers.Count);
            Assert.AreEqual("Layer0Send", layerProvider.Layers[0].State);
            Assert.AreEqual("Layer1Receive", layerProvider.Layers[1].State);
        }
        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);
        }
        public async Task MethodCall_Event_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 theEvent = new Dummy {
                int_value = 100
            };

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

            ManualResetEventSlim waitForEvent = testService.CreateResetEvent();

            proxy.EventMethodAsync(theEvent);
            bool wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));

            Assert.IsFalse(wasSignaled, "Event should not fire 1");
            testService.ClearResetEvent();

            Assert.AreEqual(0, testService.EventCount);
            Assert.AreEqual(Dummy.Empty.int_value, testService.LastEventReceived.int_value);

            errorLayer.SetState(MessageType.EVENT, errorOnSend: true, errorOnReceive: false);
            theEvent.int_value = 101;

            waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsFalse(wasSignaled, "Event should not fire 2");
            testService.ClearResetEvent();

            Assert.AreEqual(0, testService.EventCount);
            Assert.AreEqual(Dummy.Empty.int_value, testService.LastEventReceived.int_value);

            errorLayer.SetState(MessageType.EVENT, errorOnSend: false, errorOnReceive: false);
            theEvent.int_value = 102;

            waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsTrue(wasSignaled, "Timed out waiting for event to fire");

            Assert.AreEqual(1, testService.EventCount);
            Assert.AreEqual(theEvent.int_value, testService.LastEventReceived.int_value);
        }
Ejemplo n.º 5
0
        private static async Task <EpoxyTransport> Server(
            ILogSink logSink, IMetricsSink metricsSink,
            IPEndPoint endPoint)
        {
            var transport = new EpoxyTransportBuilder()
                            .SetLogSink(logSink)
                            .SetMetricsSink(metricsSink)
                            .Construct();

            var service  = new DummyTestService();
            var listener = transport.MakeListener(endPoint);

            listener.AddService(service);
            await listener.StartAsync();

            return(transport);
        }
Ejemplo n.º 6
0
        private async Task<EpoxyTransport> Server(
            ILogSink logSink, IMetricsSink metricsSink,
            IPEndPoint endPoint)
        {
            var transport = new EpoxyTransportBuilder()
                .SetLogSink(logSink)
                .SetMetricsSink(metricsSink)
                .Construct();

            var service = new DummyTestService();
            var listener = transport.MakeListener(endPoint);
            listeners.Add(listener);
            listener.AddService(service);
            await listener.StartAsync();

            return transport;
        }
        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);
        }
Ejemplo n.º 8
0
        public async Task MethodCall_Event_FailingLayerStackProvider_ServerReceiveEvent()
        {
            // 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 theEvent = new Dummy { int_value = 100 };

            ManualResetEventSlim waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            bool wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsTrue(wasSignaled, "Timed out waiting for event to fire");

            Assert.AreEqual(1, testService.EventCount);
            Assert.AreEqual(theEvent.int_value, testService.LastEventReceived.int_value);

            waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsFalse(wasSignaled, "Event should not fire 2");

            Assert.AreEqual(1, testService.EventCount);
        }
Ejemplo n.º 9
0
        public async Task MethodCall_Event_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 theEvent = new Dummy { int_value = 100 };

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

            ManualResetEventSlim waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            bool wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsFalse(wasSignaled, "Event should not fire 1");
            testService.ClearResetEvent();

            Assert.AreEqual(0, testService.EventCount);
            Assert.AreEqual(Dummy.Empty.int_value, testService.LastEventReceived.int_value);

            errorLayer.SetState(MessageType.Event, errorOnSend: true, errorOnReceive: false);
            theEvent.int_value = 101;

            waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsFalse(wasSignaled, "Event should not fire 2");
            testService.ClearResetEvent();

            Assert.AreEqual(0, testService.EventCount);
            Assert.AreEqual(Dummy.Empty.int_value, testService.LastEventReceived.int_value);

            errorLayer.SetState(MessageType.Event, errorOnSend: false, errorOnReceive: false);
            theEvent.int_value = 102;

            waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsTrue(wasSignaled, "Timed out waiting for event to fire");

            Assert.AreEqual(1, testService.EventCount);
            Assert.AreEqual(theEvent.int_value, testService.LastEventReceived.int_value);
        }
Ejemplo n.º 10
0
        public async Task MethodCall_Event_With_StatefulLayers()
        {
            var layerProvider = new TestLayerProvider_StatefulAppend("Layer");
            var layerStackProvider = new LayerStackProvider<Dummy>(LoggerTests.BlackHole, layerProvider);
            transportBuilder.SetLayerStackProvider(layerStackProvider);
            var testService = new DummyTestService();
            await DefaultSetup(testService, 1);

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

            layerProvider.Layers.Clear();

            ManualResetEventSlim waitForEvent = testService.CreateResetEvent();
            proxy.EventMethodAsync(theEvent);
            bool wasSignaled = waitForEvent.Wait(TimeSpan.FromSeconds(1));
            Assert.IsTrue(wasSignaled, "Timed out waiting for event to fire");
            testService.ClearResetEvent();

            Assert.AreEqual(1, testService.EventCount);
            Assert.AreEqual(theEvent.int_value, testService.LastEventReceived.int_value);

            Assert.AreEqual(2, layerProvider.Layers.Count);
            Assert.AreEqual("Layer0Send", layerProvider.Layers[0].State);
            Assert.AreEqual("Layer1Receive", layerProvider.Layers[1].State);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 12
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);
        }