public void ReliableMultiSubjectProxy_AsObserver()
        {
            Run(client =>
            {
                var env = new TestReliableExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var inputUri      = new Uri("test://stream/input");
                var outputUri     = new Uri("test://stream/output");
                var inputSubject  = new ReliableSubject <int>();
                var outputSubject = new ReliableSubject <int>();
                env.AddArtifact(inputUri, inputSubject);
                env.AddArtifact(outputUri, outputSubject);

                var inputProxy  = new ReliableMultiSubjectProxy <int, int>(inputUri);
                var outputProxy = new ReliableMultiSubjectProxy <int, int>(outputUri);
                var observer    = new MockObserver <int>(client);
                var inputSub    = SubscribeRoot(inputProxy.ToSubscribable(), new ObserverToReliableObserver <int>(outputProxy.CreateObserver()));
                var outputSub   = SubscribeRoot(outputProxy.ToSubscribable(), observer);
                new SubscriptionInitializeVisitor(inputSub).Initialize(ctx);
                new SubscriptionInitializeVisitor(outputSub).Initialize(ctx);

                var subjObsvr = inputSubject.CreateObserver();
                Schedule(client, 10, () => subjObsvr.OnNext(1, 0L));
                Schedule(client, 20, () => subjObsvr.OnNext(2, 1L));
                Schedule(client, 30, () => subjObsvr.OnNext(3, 2L));
                client.Start();

                observer.Messages.AssertEqual(
                    OnNext(10, 1),
                    OnNext(20, 2),
                    OnNext(30, 3)
                    );
            });
        }
        public void ReliableMultiSubjectProxy_AsReliableObservable_Dispose()
        {
            Run(client =>
            {
                var env = new TestReliableExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var uri     = new Uri("test://stream");
                var subject = new ReliableSubject <int>();
                env.AddArtifact(uri, subject);

                var proxy    = new ReliableMultiSubjectProxy <int, int>(uri);
                var observer = new MockObserver <int>(client);
                var sub      = proxy.ToSubscribable().Subscribe(observer);
                new SubscriptionInitializeVisitor(sub).Initialize(ctx);
                sub.Dispose();

                // Reliable subscriptions must be ack'd before they can be disposed
                // Unfortunately, this acking must be done on the implicit interface.
                SubscriptionVisitor.Do <ReliableSubscriptionBase>(s => ((IReliableSubscription)s).AcknowledgeRange(0)).Apply(sub);
                sub.Dispose();

                var isDisposed = false;
                SubscriptionVisitor.Do <ReliableSubcription <int> >(s => isDisposed |= s.IsDisposed).Apply(sub);

                Assert.IsTrue(isDisposed);
            });
        }
        public void ReliableMultiSubjectProxy_AsReliableObservable_InvalidEnvironment()
        {
            Run(client =>
            {
                var env = new TestExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var uri     = new Uri("test://stream");
                var subject = new ReliableSubject <int>();
                env.AddArtifact(uri, subject);

                var proxy    = new ReliableMultiSubjectProxy <int, int>(uri);
                var observer = new MockObserver <int>(client);
                var sub      = proxy.ToSubscribable().Subscribe(observer);
                Assert.ThrowsException <InvalidOperationException>(() => new SubscriptionInitializeVisitor(sub).Initialize(ctx));
            });
        }
 public Observer(ReliableSubject <T> parent)
 {
     _parent = parent;
 }