Exemple #1
0
        private void We_can_create_linked_sockets(LinkedSocketCallback callback)
        {
            Assert.NotNull(callback);

            Given_fresh_slate("can create linked sockets", () =>
            {
                LatestPubSocket pub = null;
                LatestSubSocket sub = null;

                try
                {
                    var addr = TestAddr;

                    pub = CreateOne <LatestPubSocket>();
                    sub = CreateOne <LatestSubSocket>();

                    // Serves other paths of unit testing.
                    sub.Options.SetDuration(O.RecvTimeoutDuration, FromMilliseconds(90d));

                    // TODO: TBD: yes, in this case, Subscriber is the "server" listening for publishers.
                    // TODO: TBD: I would think this might be the other way round... or could be... does not necessarily HAVE to be...
                    sub.Listen(addr);
                    pub.Dial(addr);

                    callback(pub, sub);
                }
                finally
                {
                    DisposeAll(pub, sub);
                }
            });
        }
Exemple #2
0
        private void Given_Bus_sockets(LinkedSocketCallback callback)
        {
            var addr = TestAddr;

            Given($"three '{typeof(LatestBusSocket).FullName}' instances", () =>
            {
                LatestBusSocket bus1 = null;
                LatestBusSocket bus2 = null;
                LatestBusSocket bus3 = null;

                try
                {
                    bus1 = CreateOne <LatestBusSocket>();
                    bus2 = CreateOne <LatestBusSocket>();
                    bus3 = CreateOne <LatestBusSocket>();

                    bus1.Listen(addr);
                    bus2.Dial(addr);
                    bus3.Dial(addr);

                    var recvTimeout = FromMilliseconds(50d);

                    bus1.Options.SetDuration(O.RecvTimeoutDuration, recvTimeout);
                    bus2.Options.SetDuration(O.RecvTimeoutDuration, recvTimeout);
                    bus3.Options.SetDuration(O.RecvTimeoutDuration, recvTimeout);

                    Section("messages can be delivered", () =>
                    {
                        Section("receive times out", () =>
                        {
                            Message m = null;
                            try
                            {
                                m = CreateMessage();

                                var n = m;

                                Assert.Throws <NanoException>(() => bus1.TryReceive(n))
                                .Matching(ex => ex.ErrorNumber.ToErrorCode() == TimedOut);
                                Assert.Throws <NanoException>(() => bus2.TryReceive(n))
                                .Matching(ex => ex.ErrorNumber.ToErrorCode() == TimedOut);
                                Assert.Throws <NanoException>(() => bus3.TryReceive(n))
                                .Matching(ex => ex.ErrorNumber.ToErrorCode() == TimedOut);
                            }
                            finally
                            {
                                m?.Dispose();
                            }
                        });

                        callback(bus1, bus2, bus3);
                    });
                }
                finally
                {
                    DisposeAll(bus1, bus2, bus3);
                }
            });
        }
Exemple #3
0
        private void Subscriber_can_receive_from_Publisher(LinkedSocketCallback callback)
        {
            We_can_create_linked_sockets((pub, sub) =>
            {
                Section("Subscriber can receive from publisher", () =>
                {
                    sub.Options.SetString(O.SubSubscribe, Topics.Some);

                    callback(pub, sub);
                });
            });
        }
Exemple #4
0
        private void Subscriber_can_subscribe(LinkedSocketCallback callback)
        {
            Assert.NotNull(callback);

            We_can_create_linked_sockets((pub, sub) =>
            {
                Section("Subscriber can subscribe", () =>
                {
                    sub.Options.SetString(O.SubSubscribe, Abc);
                    sub.Options.SetString(O.SubSubscribe, Empty);

                    callback(pub, sub);
                });
            });
        }