Exemple #1
0
        public void TestNatSubscriptionShouldLogPublishingError()
        {
            var mockLogger = new Mock <Microsoft.Extensions.Logging.ILogger>();
            JsonRpcSubscription subscription = new JsonRpcSubscription("test:largepayload", "test::group", new LargePayloadService(), mockLogger.Object);

            subscription.Subscribe("nats://127.0.0.1");
            subscription.Start().GetAwaiter().GetResult();

            JsonRpcServer server = new JsonRpcServer("nats://127.0.0.1", 5000);

            using (server)
            {
                Assert.Throws <JsonRpcException>(() =>
                {
                    var resp = server.ServeAsync(new JsonRpcRequest
                    {
                        Method     = "test:largepayload",
                        Id         = Guid.NewGuid().ToString(),
                        Parameters = new Dictionary <string, string>
                        {
                            { "size", "10000000" }
                        }
                    }).GetAwaiter().GetResult();
                });
            }

            mockLogger.Verify(m => m.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <Object>(), It.IsAny <Exception>(), It.IsAny <Func <Object, Exception, string> >()));
        }
Exemple #2
0
        public void TestDisposedSubscritionThrowsException()
        {
            JsonRpcSubscription subscription =
                new JsonRpcSubscription("test:channel", "test::group", new EchoService(), null);

            subscription.Subscribe("nats://127.0.0.1");
            subscription.Dispose();
            Assert.Throws <ObjectDisposedException>(() => subscription.Start().GetAwaiter().GetResult());
        }
Exemple #3
0
        public void TestNatSubscriptionShouldRecoverFromPublishingError()
        {
            JsonRpcSubscription subscription = new JsonRpcSubscription("test:largepayload", "test::group", new LargePayloadService(), null);

            subscription.Subscribe("nats://127.0.0.1");
            subscription.Start().GetAwaiter().GetResult();

            JsonRpcServer server = new JsonRpcServer("nats://127.0.0.1", 5000);

            using (server)
            {
                Assert.Throws <JsonRpcException>(() =>
                {
                    var resp = server.ServeAsync(new JsonRpcRequest
                    {
                        Method     = "test:largepayload",
                        Id         = Guid.NewGuid().ToString(),
                        Parameters = new Dictionary <string, string>
                        {
                            { "size", "10000000" }
                        }
                    }).GetAwaiter().GetResult();
                });

                var resp2 = server.ServeAsync(new JsonRpcRequest
                {
                    Method     = "test:largepayload",
                    Id         = Guid.NewGuid().ToString(),
                    Parameters = new Dictionary <string, string>
                    {
                        { "size", "100" }
                    }
                }).GetAwaiter().GetResult();

                Assert.IsNotNull(resp2);
                Assert.IsNull(resp2.Error);
                Assert.AreEqual(resp2.Id.ToString(), resp2.Id);
                Assert.AreEqual(new string('A', 100), resp2.Result);
            }
        }