Beispiel #1
0
        public void TestTransport_must_associate_successfully_with_another_TestTransport()
        {
            //arrange
            var registry   = new AssociationRegistry();
            var transportA = new TestTransport(addressA, registry);
            var transportB = new TestTransport(addressB, registry);

            //act

            //must complete returned promises to receive events
            var localConnectionFuture = transportA.Listen();

            localConnectionFuture.Wait(DefaultTimeout);
            localConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var remoteConnectionFuture = transportB.Listen();

            remoteConnectionFuture.Wait(DefaultTimeout);
            remoteConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var ready = registry.TransportsReady(addressA, addressB);

            Assert.True(ready);

            transportA.Associate(addressB);
            ExpectMsgPf <AssociationHandle>(DefaultTimeout, "Expect InboundAssociation from A",
                                            m => m.AsInstanceOf <InboundAssociation>().Association);

            //assert
            var associateAttempt = (registry.LogSnapshot().Single(x => x is AssociateAttempt)).AsInstanceOf <AssociateAttempt>();

            Assert.Equal(addressA, associateAttempt.LocalAddress);
            Assert.Equal(addressB, associateAttempt.RemoteAddress);
        }
Beispiel #2
0
        public void TestTransport_must_associate_successfully_with_another_TestTransport()
        {
            //arrange
            var registry = new AssociationRegistry();
            var transportA = new TestTransport(addressA, registry);
            var transportB = new TestTransport(addressB, registry);

            //act

            //must complete returned promises to receive events
            var localConnectionFuture = transportA.Listen();
            localConnectionFuture.Wait(DefaultTimeout);
            localConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var remoteConnectionFuture = transportB.Listen();
            remoteConnectionFuture.Wait(DefaultTimeout);
            remoteConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var ready = registry.TransportsReady(addressA, addressB);
            Assert.True(ready);

            transportA.Associate(addressB);
            expectMsgPF<AssociationHandle>(DefaultTimeout, "Expect InboundAssociation from A",
                m => m.AsInstanceOf<InboundAssociation>().Association);

            //assert
            var associateAttempt = (registry.LogSnapshot().Single(x => x is AssociateAttempt)).AsInstanceOf<AssociateAttempt>();
            Assert.Equal(addressA, associateAttempt.LocalAddress);
            Assert.Equal(addressB, associateAttempt.RemoteAddress);
        }
Beispiel #3
0
        public void Transport_must_associate_successfully_with_another_transport_of_its_kind()
        {
            var registry   = new AssociationRegistry();
            var transportA = NewTransportA(registry);
            var transportB = NewTransportB(registry);

            // Must complete the returned promise to receive events
            AwaitResult(transportA.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor));
            AwaitResult(transportB.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor));

            AwaitCondition(() => registry.TransportsReady(addressATest, addressBTest));

            transportA.Associate(addressB);
            ExpectMsgPf(DefaultTimeout, "Expect InboundAssociation from A", o =>
            {
                var inbound = o as InboundAssociation;

                if (inbound != null && inbound.Association.RemoteAddress == addressA)
                {
                    return(inbound.Association);
                }

                return(null);
            });

            Assert.Contains(registry.LogSnapshot().OfType <AssociateAttempt>(), x => x.LocalAddress == addressATest && x.RemoteAddress == addressBTest);
            AwaitCondition(() => registry.ExistsAssociation(addressATest, addressBTest));
        }
Beispiel #4
0
        public void Transport_must_return_an_Address_and_promise_when_listen_is_called()
        {
            var registry   = new AssociationRegistry();
            var transportA = NewTransportA(registry);

            var result = AwaitResult(transportA.Listen());

            Assert.Equal(addressA, result.Item1);
            Assert.NotNull(result.Item2);

            Assert.Contains(registry.LogSnapshot().OfType <ListenAttempt>(), x => x.BoundAddress == addressATest);
        }
Beispiel #5
0
        private bool LastActivityIsDisassociate(AssociationRegistry associationRegistry)
        {
            if (associationRegistry.LogSnapshot().Count == 0)
            {
                return(false);
            }
            var rValue = false;

            associationRegistry.LogSnapshot().Last().Match()
            .With <WriteAttempt>(attempt =>
            {
                if (attempt.Sender.Equals(localAddress) && attempt.Recipient.Equals(remoteAddress))
                {
                    codec.DecodePdu(attempt.Payload)
                    .Match()
                    .With <Disassociate>(h => rValue = true)
                    .Default(msg => rValue           = false);
                }
            });

            return(rValue);
        }
Beispiel #6
0
        private bool LastActivityIsAssociate(AssociationRegistry associationRegistry, long uid)
        {
            if (associationRegistry.LogSnapshot().Count == 0)
            {
                return(false);
            }
            var rValue = false;

            if (associationRegistry.LogSnapshot().Last() is WriteAttempt)
            {
                var attempt = (WriteAttempt)associationRegistry.LogSnapshot().Last();
                if (attempt.Sender.Equals(_localAddress) && attempt.Recipient.Equals(_remoteAddress))
                {
                    codec.DecodePdu(attempt.Payload)
                    .Match()
                    .With <Associate>(h => rValue = h.Info.Origin.Equals(_localAddress) && h.Info.Uid == uid)
                    .Default(msg => rValue        = false);
                }
            }

            return(rValue);
        }
Beispiel #7
0
        private bool LastActivityIsHeartbeat(AssociationRegistry associationRegistry)
        {
            if (associationRegistry.LogSnapshot().Count == 0)
            {
                return(false);
            }
            var rValue = false;

            if (associationRegistry.LogSnapshot().Last() is WriteAttempt)
            {
                var attempt = (WriteAttempt)associationRegistry.LogSnapshot().Last();
                if (attempt.Sender.Equals(_localAddress) && attempt.Recipient.Equals(_remoteAddress))
                {
                    codec.DecodePdu(attempt.Payload)
                    .Match()
                    .With <Heartbeat>(h => rValue = true)
                    .Default(msg => rValue        = false);
                }
            }

            return(rValue);
        }
Beispiel #8
0
        public void Transport_must_successfully_send_PDUs()
        {
            var registry   = new AssociationRegistry();
            var transportA = NewTransportA(registry);
            var transportB = NewTransportB(registry);

            AwaitResult(transportA.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor));
            AwaitResult(transportB.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor));

            AwaitCondition(() => registry.TransportsReady(addressATest, addressBTest));

            var associate = transportA.Associate(addressB);
            var handleB   = ExpectMsgPf(DefaultTimeout, "Expect InboundAssociation from A", o =>
            {
                var handle = o as InboundAssociation;
                if (handle != null && handle.Association.RemoteAddress == addressA)
                {
                    return(handle.Association);
                }

                return(null);
            });

            var handleA = AwaitResult(associate);

            // Initialize handles
            handleA.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor));
            handleB.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor));

            var payload = ByteString.CopyFromUtf8("PDU");
            var pdu     = withAkkaProtocol ? new AkkaPduProtobuffCodec().ConstructPayload(payload) : payload;

            AwaitCondition(() => registry.ExistsAssociation(addressATest, addressBTest));

            handleA.Write(payload);
            ExpectMsgPf(DefaultTimeout, "Expect InboundPayload from A", o =>
            {
                var inboundPayload = o as InboundPayload;

                if (inboundPayload != null && inboundPayload.Payload.Equals(pdu))
                {
                    return(inboundPayload.Payload);
                }

                return(null);
            });

            Assert.True(
                registry.LogSnapshot().OfType <WriteAttempt>().Any(x => x.Sender == addressATest && x.Recipient == addressBTest && x.Payload.Equals(pdu))
                );
        }
Beispiel #9
0
        public void TestTransport_must_return_an_Address_and_TaskCompletionSource_on_Listen()
        {
            //arrange
            var registry = new AssociationRegistry();
            var transportA = new TestTransport(addressA, registry);

            //act
            var result = transportA.Listen();
            result.Wait(DefaultTimeout);

            //assert
            Assert.Equal(addressA, result.Result.Item1);
            Assert.NotNull(result.Result.Item2);

            var snapshot = registry.LogSnapshot();
            Assert.Equal(1, snapshot.Count);
            Assert.IsType<ListenAttempt>(snapshot[0]);
            Assert.Equal(addressA, ((ListenAttempt)snapshot[0]).BoundAddress);
        }
Beispiel #10
0
        public void Transport_must_successfully_disassociate()
        {
            var registry   = new AssociationRegistry();
            var transportA = NewTransportA(registry);
            var transportB = NewTransportB(registry);

            AwaitResult(transportA.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor));
            AwaitResult(transportB.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor));

            AwaitCondition(() => registry.TransportsReady(addressATest, addressBTest));

            var associate = transportA.Associate(addressB);
            var handleB   = ExpectMsgPf(DefaultTimeout, "Expect InboundAssociation from A", o =>
            {
                var handle = o as InboundAssociation;
                if (handle != null && handle.Association.RemoteAddress == addressA)
                {
                    return(handle.Association);
                }

                return(null);
            });

            var handleA = AwaitResult(associate);

            // Initialize handles
            handleA.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor));
            handleB.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor));

            AwaitCondition(() => registry.ExistsAssociation(addressATest, addressBTest));

            handleA.Disassociate();

            ExpectMsgPf(DefaultTimeout, "Should receive Disassociated", o => o as Disassociated);

            AwaitCondition(() => !registry.ExistsAssociation(addressATest, addressBTest));

            AwaitCondition(() =>
                           registry.LogSnapshot().OfType <DisassociateAttempt>().Any(x => x.Requestor == addressATest && x.Remote == addressBTest)
                           );
        }
Beispiel #11
0
        public void TestTransport_must_return_an_Address_and_TaskCompletionSource_on_Listen()
        {
            //arrange
            var registry   = new AssociationRegistry();
            var transportA = new TestTransport(addressA, registry);

            //act
            var result = transportA.Listen();

            result.Wait(DefaultTimeout);

            //assert
            Assert.Equal(addressA, result.Result.Item1);
            Assert.NotNull(result.Result.Item2);

            var snapshot = registry.LogSnapshot();

            Assert.Equal(1, snapshot.Count);
            Assert.IsType <ListenAttempt>(snapshot[0]);
            Assert.Equal(addressA, ((ListenAttempt)snapshot[0]).BoundAddress);
        }
Beispiel #12
0
        public void TestTransport_should_emulate_sending_PDUs()
        {
            //arrange
            var registry = new AssociationRegistry();
            var transportA = new TestTransport(addressA, registry);
            var transportB = new TestTransport(addressB, registry);

            //act

            //must complete returned promises to receive events
            var localConnectionFuture = transportA.Listen();
            localConnectionFuture.Wait(DefaultTimeout);
            localConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var remoteConnectionFuture = transportB.Listen();
            remoteConnectionFuture.Wait(DefaultTimeout);
            remoteConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var ready = registry.TransportsReady(addressA, addressB);
            Assert.True(ready);

            var associate = transportA.Associate(addressB);
            var handleB = expectMsgPF<AssociationHandle>(DefaultTimeout, "Expect InboundAssociation from A", o =>
            {
                var handle = o as InboundAssociation;
                if (handle != null && handle.Association.RemoteAddress.Equals(addressA)) return handle.Association;
                return null;
            });
            handleB.ReadHandlerSource.SetResult(new ActorHandleEventListener(Self));

            associate.Wait(DefaultTimeout);
            var handleA = associate.Result;

            //Initialize handles
            handleA.ReadHandlerSource.SetResult(new ActorHandleEventListener(Self));

            var akkaPDU = ByteString.CopyFromUtf8("AkkaPDU");

            var exists = registry.ExistsAssociation(addressA, addressB);
            Assert.True(exists);

            handleA.Write(akkaPDU);

            //assert
            expectMsgPF(DefaultTimeout, "Expect InboundPayload from A", o =>
            {
                var payload = o as InboundPayload;
                if (payload != null && payload.Payload.Equals(akkaPDU)) return akkaPDU;
                return null;
            });

            var writeAttempt = (registry.LogSnapshot().Single(x => x is WriteAttempt)).AsInstanceOf<WriteAttempt>();
            Assert.True(writeAttempt.Sender.Equals(addressA) && writeAttempt.Recipient.Equals(addressB)
                && writeAttempt.Payload.Equals(akkaPDU));
        }
        private bool LastActivityIsAssociate(AssociationRegistry associationRegistry, long uid)
        {
            if (associationRegistry.LogSnapshot().Count == 0) return false;
            var rValue = false;
            associationRegistry.LogSnapshot().Last().Match()
                .With<WriteAttempt>(attempt =>
                {
                    if (attempt.Sender.Equals(localAddress) && attempt.Recipient.Equals(remoteAddress))
                    {
                        codec.DecodePdu(attempt.Payload)
                            .Match()
                            .With<Associate>(h => rValue = h.Info.Origin.Equals(localAddress) && h.Info.Uid == uid)
                            .Default(msg => rValue = false);
                    }
                });

            return rValue;
        }
Beispiel #14
0
        public void TestTransport_should_emulate_disassociation()
        {
            //arrange
            var registry = new AssociationRegistry();
            var transportA = new TestTransport(addressA, registry);
            var transportB = new TestTransport(addressB, registry);

            //act

            //must complete returned promises to receive events
            var localConnectionFuture = transportA.Listen();
            localConnectionFuture.Wait(DefaultTimeout);
            localConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var remoteConnectionFuture = transportB.Listen();
            remoteConnectionFuture.Wait(DefaultTimeout);
            remoteConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var ready = registry.TransportsReady(addressA, addressB);
            Assert.True(ready);

            var associate = transportA.Associate(addressB);
            var handleB = expectMsgPF<AssociationHandle>(DefaultTimeout, "Expect InboundAssociation from A", o =>
            {
                var handle = o as InboundAssociation;
                if (handle != null && handle.Association.RemoteAddress.Equals(addressA)) return handle.Association;
                return null;
            });
            handleB.ReadHandlerSource.SetResult(new ActorHandleEventListener(Self));

            associate.Wait(DefaultTimeout);
            var handleA = associate.Result;

            //Initialize handles
            handleA.ReadHandlerSource.SetResult(new ActorHandleEventListener(Self));

            var exists = registry.ExistsAssociation(addressA, addressB);
            Assert.True(exists);

            handleA.Disassociate();

            var msg = expectMsgPF(DefaultTimeout, "Expected Disassociated", o => o.AsInstanceOf<Disassociated>());

            //assert
            Assert.NotNull(msg);

            exists = registry.ExistsAssociation(addressA, addressB);
            Assert.True(!exists, "Association should no longer exist");

            var disassociateAttempt = registry.LogSnapshot().Single(x => x is DisassociateAttempt).AsInstanceOf<DisassociateAttempt>();
            Assert.True(disassociateAttempt.Requestor.Equals(addressA) && disassociateAttempt.Remote.Equals(addressB));
        }
        private bool LastActivityIsDisassociate(AssociationRegistry associationRegistry)
        {
            if (associationRegistry.LogSnapshot().Count == 0) return false;
            var rValue = false;
            if (associationRegistry.LogSnapshot().Last() is WriteAttempt)
            {
                var attempt = (WriteAttempt) associationRegistry.LogSnapshot().Last();
                if (attempt.Sender.Equals(localAddress) && attempt.Recipient.Equals(remoteAddress))
                    codec.DecodePdu(attempt.Payload)
                        .Match()
                        .With<Disassociate>(h => rValue = true)
                        .Default(msg => rValue = false);
            }

            return rValue;
        }
        private bool LastActivityIsHeartbeat(AssociationRegistry associationRegistry)
        {
            if (associationRegistry.LogSnapshot().Count == 0) return false;
            var rValue = false;
            associationRegistry.LogSnapshot().Last().Match()
                .With<WriteAttempt>(attempt =>
                {
                    if (attempt.Sender.Equals(localAddress) && attempt.Recipient.Equals(remoteAddress))
                    {
                        codec.DecodePdu(attempt.Payload)
                            .Match()
                            .With<Heartbeat>(h => rValue = true)
                            .Default(msg => rValue = false);
                    }
                });

            return rValue;
        }
Beispiel #17
0
        public void TestTransport_should_emulate_sending_PDUs()
        {
            //arrange
            var registry   = new AssociationRegistry();
            var transportA = new TestTransport(addressA, registry);
            var transportB = new TestTransport(addressB, registry);

            //act

            //must complete returned promises to receive events
            var localConnectionFuture = transportA.Listen();

            localConnectionFuture.Wait(DefaultTimeout);
            localConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var remoteConnectionFuture = transportB.Listen();

            remoteConnectionFuture.Wait(DefaultTimeout);
            remoteConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var ready = registry.TransportsReady(addressA, addressB);

            Assert.True(ready);

            var associate = transportA.Associate(addressB);
            var handleB   = ExpectMsgPf <AssociationHandle>(DefaultTimeout, "Expect InboundAssociation from A", o =>
            {
                var handle = o as InboundAssociation;
                if (handle != null && handle.Association.RemoteAddress.Equals(addressA))
                {
                    return(handle.Association);
                }
                return(null);
            });

            handleB.ReadHandlerSource.SetResult(new ActorHandleEventListener(Self));

            associate.Wait(DefaultTimeout);
            var handleA = associate.Result;

            //Initialize handles
            handleA.ReadHandlerSource.SetResult(new ActorHandleEventListener(Self));

            var akkaPDU = ByteString.CopyFromUtf8("AkkaPDU");

            var exists = registry.ExistsAssociation(addressA, addressB);

            Assert.True(exists);

            handleA.Write(akkaPDU);

            //assert
            ExpectMsgPf(DefaultTimeout, "Expect InboundPayload from A", o =>
            {
                var payload = o as InboundPayload;
                if (payload != null && payload.Payload.Equals(akkaPDU))
                {
                    return(akkaPDU);
                }
                return(null);
            });

            var writeAttempt = (registry.LogSnapshot().Single(x => x is WriteAttempt)).AsInstanceOf <WriteAttempt>();

            Assert.True(writeAttempt.Sender.Equals(addressA) && writeAttempt.Recipient.Equals(addressB) &&
                        writeAttempt.Payload.Equals(akkaPDU));
        }
Beispiel #18
0
        public void TestTransport_should_emulate_disassociation()
        {
            //arrange
            var registry   = new AssociationRegistry();
            var transportA = new TestTransport(addressA, registry);
            var transportB = new TestTransport(addressB, registry);

            //act

            //must complete returned promises to receive events
            var localConnectionFuture = transportA.Listen();

            localConnectionFuture.Wait(DefaultTimeout);
            localConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var remoteConnectionFuture = transportB.Listen();

            remoteConnectionFuture.Wait(DefaultTimeout);
            remoteConnectionFuture.Result.Item2.SetResult(new ActorAssociationEventListener(Self));

            var ready = registry.TransportsReady(addressA, addressB);

            Assert.True(ready);

            var associate = transportA.Associate(addressB);
            var handleB   = ExpectMsgPf <AssociationHandle>(DefaultTimeout, "Expect InboundAssociation from A", o =>
            {
                var handle = o as InboundAssociation;
                if (handle != null && handle.Association.RemoteAddress.Equals(addressA))
                {
                    return(handle.Association);
                }
                return(null);
            });

            handleB.ReadHandlerSource.SetResult(new ActorHandleEventListener(Self));

            associate.Wait(DefaultTimeout);
            var handleA = associate.Result;

            //Initialize handles
            handleA.ReadHandlerSource.SetResult(new ActorHandleEventListener(Self));

            var exists = registry.ExistsAssociation(addressA, addressB);

            Assert.True(exists);

            handleA.Disassociate();

            var msg = ExpectMsgPf(DefaultTimeout, "Expected Disassociated", o => o.AsInstanceOf <Disassociated>());

            //assert
            Assert.NotNull(msg);

            exists = registry.ExistsAssociation(addressA, addressB);
            Assert.True(!exists, "Association should no longer exist");

            var disassociateAttempt = registry.LogSnapshot().Single(x => x is DisassociateAttempt).AsInstanceOf <DisassociateAttempt>();

            Assert.True(disassociateAttempt.Requestor.Equals(addressA) && disassociateAttempt.Remote.Equals(addressB));
        }