示例#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);
        }
示例#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);
        }
示例#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));
        }
示例#4
0
        public void Transport_must_fail_to_associate_with_nonexisting_address()
        {
            var registry   = new AssociationRegistry();
            var transportA = NewTransportA(registry);

            AwaitResult(transportA.Listen()).Item2.SetResult(new ActorAssociationEventListener(TestActor));
            AwaitCondition(() => registry.TransportsReady(addressATest));

            // Transport throws InvalidAssociationException when trying to associate with non-existing system
            XAssert.Throws <InvalidAssociationException>(() =>
                                                         AwaitResult(transportA.Associate(nonExistingAddress))
                                                         );
        }
示例#5
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))
                );
        }
示例#6
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)
                           );
        }
示例#7
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));
        }
示例#8
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));
        }
示例#9
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));
        }
示例#10
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));
        }