Ejemplo n.º 1
0
        public void TestRespondFailsWithServerClosed()
        {
            IConnection       c = null;
            ISyncSubscription s = null;

            try
            {
                Msg m;
                using (NATSServer ns = new NATSServer())
                {
                    Options options = utils.DefaultTestOptions;
                    options.AllowReconnect = false;

                    c = new ConnectionFactory().CreateConnection(options);
                    s = c.SubscribeSync("foo");

                    string replyTo = c.NewInbox();

                    c.Publish("foo", replyTo, Encoding.UTF8.GetBytes("message"));

                    m = s.NextMessage(1000);
                    Assert.NotNull(m);
                    Assert.Equal(replyTo, m.Reply);

                    ns.Shutdown();
                }

                // Give the server time to close
                Thread.Sleep(2000);

                byte[] reply = Encoding.UTF8.GetBytes("reply");
                Assert.ThrowsAny <NATSConnectionClosedException>(() => m.Respond(reply));
            }
            finally
            {
                c?.Dispose();
                s?.Dispose();
            }
        }
Ejemplo n.º 2
0
        public void TestRespondFailsWithClosedConnection()
        {
            using (new NATSServer())
            {
                using (IConnection c = utils.DefaultTestConnection)
                {
                    ISyncSubscription s = c.SubscribeSync("foo");

                    string replyTo = c.NewInbox();
                    c.Publish("foo", replyTo, Encoding.UTF8.GetBytes("message"));

                    Msg m = s.NextMessage(1000);
                    Assert.NotNull(m);
                    Assert.Equal(replyTo, m.Reply);

                    c.Close();

                    byte[] reply = Encoding.UTF8.GetBytes("reply");
                    Assert.ThrowsAny <NATSConnectionClosedException>(() => m.Respond(reply));

                    s.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        public void TestRespondFailsWithClosedConnection()
        {
            using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
            {
                using (IConnection c = Context.OpenConnection(Context.Server1.Port))
                {
                    ISyncSubscription s = c.SubscribeSync("foo");

                    string replyTo = c.NewInbox();
                    c.Publish("foo", replyTo, Encoding.UTF8.GetBytes("message"));

                    Msg m = s.NextMessage(1000);
                    Assert.NotNull(m);
                    Assert.Equal(replyTo, m.Reply);

                    c.Close();

                    byte[] reply = Encoding.UTF8.GetBytes("reply");
                    Assert.ThrowsAny <NATSConnectionClosedException>(() => m.Respond(reply));

                    s.Dispose();
                }
            }
        }