Exemplo n.º 1
0
        public void TestServerAutoUnsub()
        {
            using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
            {
                using (IConnection c = Context.OpenConnection(Context.Server1.Port))
                {
                    long received = 0;
                    int  max      = 10;

                    using (IAsyncSubscription s = c.SubscribeAsync("foo"))
                    {
                        s.MessageHandler += (sender, arg) =>
                        {
                            received++;
                        };

                        s.AutoUnsubscribe(max);
                        s.Start();

                        for (int i = 0; i < (max * 2); i++)
                        {
                            c.Publish("foo", Encoding.UTF8.GetBytes("hello"));
                        }
                        c.Flush();

                        Thread.Sleep(500);

                        Assert.Equal(max, received);

                        Assert.False(s.IsValid);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TestServerAutoUnsub()
        {
            using (new NATSServer())
            {
                using (IConnection c = utils.DefaultTestConnection)
                {
                    long received = 0;
                    int  max      = 10;

                    using (IAsyncSubscription s = c.SubscribeAsync("foo"))
                    {
                        s.MessageHandler += (sender, arg) =>
                        {
                            received++;
                        };

                        s.AutoUnsubscribe(max);
                        s.Start();

                        for (int i = 0; i < (max * 2); i++)
                        {
                            c.Publish("foo", Encoding.UTF8.GetBytes("hello"));
                        }
                        c.Flush();

                        Thread.Sleep(500);

                        Assert.Equal(max, received);

                        Assert.False(s.IsValid);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void TestServerAutoUnsub()
        {
            using (IConnection c = new ConnectionFactory().CreateConnection())
            {
                long received = 0;
                int  max      = 10;

                using (IAsyncSubscription s = c.SubscribeAsync("foo"))
                {
                    s.MessageHandler += (sender, arg) =>
                    {
                        System.Console.WriteLine("Received msg.");
                        received++;
                    };

                    s.AutoUnsubscribe(max);
                    s.Start();

                    for (int i = 0; i < (max * 2); i++)
                    {
                        c.Publish("foo", Encoding.UTF8.GetBytes("hello"));
                    }
                    c.Flush();

                    Thread.Sleep(500);

                    if (received != max)
                    {
                        Assert.Fail("Recieved ({0}) != max ({1})",
                                    received, max);
                    }
                    Assert.IsFalse(s.IsValid);
                }
            }
        }