Ejemplo n.º 1
0
        public void WhenDisposingAnObserverItShouldNotReceiveMoreMessages()
        {
            sync = TestSync.TwoActors();

            var subject  = "415b09873e3348d3a953e93d35ff61bf";
            var payload1 = SamplePayload.Random();
            var payload2 = SamplePayload.Random();

            using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
            {
                var interceptingOb1 = new TestObserver(_ => sync.SignalComplete());
                var interceptingOb2 = new TestObserver(_ => sync.SignalComplete());

                using (var cn = Context.OpenConnection(Context.Server1.Port))
                {
                    using (var observable = cn.Observe(subject))
                    {
                        using (observable.Subscribe(interceptingOb1))
                        {
                            using (observable.Subscribe(interceptingOb2))
                            {
                                cn.Publish(subject, payload1);
                                sync.WaitForAll();
                            }

                            cn.Publish(subject, payload2);
                            sync.WaitForOne();
                        }

                        Assert.Equal(new[] { payload1.Data, payload2.Data }, interceptingOb1.OnNextResults.Select(i => i.Data).ToArray());
                        Assert.Equal(new[] { payload1.Data }, interceptingOb2.OnNextResults.Select(i => i.Data).ToArray());
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void WhenDisposingAnObserverItShouldNotReceiveMoreMessages()
        {
            sync = TestSync.TwoActors();

            var subject  = "f3d07d4e380048399df9363222ca482b";
            var payload1 = SamplePayload.Random();
            var payload2 = SamplePayload.Random();

            using (Context.StartStreamingServerWithEmbedded(Context.Server1))
            {
                var interceptingOb1 = new TestObserver(_ => sync.SignalComplete());
                var interceptingOb2 = new TestObserver(_ => sync.SignalComplete());

                using (var cn = Context.GetStanConnection(Context.Server1))
                {
                    using (var observable = cn.Observe(subject))
                    {
                        using (observable.Subscribe(interceptingOb1))
                        {
                            using (observable.Subscribe(interceptingOb2))
                            {
                                cn.Publish(subject, payload1);
                                sync.WaitForAll();
                            }

                            cn.Publish(subject, payload2);
                            sync.WaitForOne();
                        }

                        Assert.Equal(new[] { payload1.Data, payload2.Data }, interceptingOb1.OnNextResults.Select(i => i.Data).ToArray());
                        Assert.Equal(new[] { payload1.Data }, interceptingOb2.OnNextResults.Select(i => i.Data).ToArray());
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void WhenDisposingAnObservableNoMoreDispatchesShouldBeDone()
        {
            sync = TestSync.TwoActors();

            var subject  = "bea00c947f4c470cb4e884c58202d3ac";
            var payload1 = SamplePayload.Random();
            var payload2 = SamplePayload.Random();

            using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
            {
                var interceptingOb1 = new TestObserver(_ => sync.SignalComplete());
                var interceptingOb2 = new TestObserver(_ => sync.SignalComplete());

                using (var cn = Context.OpenConnection(Context.Server1.Port))
                {
                    var observable1 = cn.Observe(subject);
                    var observable2 = cn.Observe(subject);

                    observable1.Subscribe(interceptingOb1);
                    observable2.Subscribe(interceptingOb2);

                    cn.Publish(subject, payload1);
                    sync.WaitForAll();

                    observable1.Dispose();

                    cn.Publish(subject, payload2);
                    sync.WaitForOne();

                    observable2.Dispose();

                    Assert.Equal(new[] { payload1.Data }, interceptingOb1.OnNextResults.Select(i => i.Data).ToArray());
                    Assert.Equal(new[] { payload1.Data, payload2.Data }, interceptingOb2.OnNextResults.Select(i => i.Data).ToArray());
                }
            }
        }
Ejemplo n.º 4
0
        public void WhenDisposingAnObservableNoMoreDispatchesShouldBeDone()
        {
            sync = TestSync.TwoActors();

            var subject  = "61d374c816034f8b9428b04e273f4c85";
            var payload1 = SamplePayload.Random();
            var payload2 = SamplePayload.Random();

            using (Context.StartStreamingServerWithEmbedded(Context.Server1))
            {
                var interceptingOb1 = new TestObserver(_ => sync.SignalComplete());
                var interceptingOb2 = new TestObserver(_ => sync.SignalComplete());

                using (var cn = Context.GetStanConnection(Context.Server1))
                {
                    var observable1 = cn.Observe(subject);
                    var observable2 = cn.Observe(subject);

                    observable1.Subscribe(interceptingOb1);
                    observable2.Subscribe(interceptingOb2);

                    cn.Publish(subject, payload1);
                    sync.WaitForAll();

                    observable1.Dispose();

                    cn.Publish(subject, payload2);
                    sync.WaitForOne();

                    observable2.Dispose();

                    Assert.Equal(new[] { payload1.Data }, interceptingOb1.OnNextResults.Select(i => i.Data).ToArray());
                    Assert.Equal(new[] { payload1.Data, payload2.Data }, interceptingOb2.OnNextResults.Select(i => i.Data).ToArray());
                }
            }
        }