コード例 #1
0
        public async Task ProtocolStateActor_must_in_inbound_mode_accept_payload_after_Associate_PDU_received()
        {
            var collaborators = GetCollaborators();
            var reader        =
                sys.ActorOf(ProtocolStateActor.InboundProps(new HandshakeInfo(localAddress, 42), collaborators.Handle,
                                                            new ActorAssociationEventListener(testActor), new AkkaProtocolSettings(config), codec,
                                                            collaborators.FailureDetector));

            reader.Tell(testAssociate(33), Self);

            await AwaitCond(() => collaborators.FailureDetector.called, DefaultTimeout);

            var wrappedHandle = expectMsgPF <AkkaProtocolHandle>(DefaultTimeout, "expected InboundAssociation", o =>
            {
                var inbound = o.AsInstanceOf <InboundAssociation>();
                if (inbound == null)
                {
                    return(null);
                }
                Assert.AreEqual(33, inbound.Association.AsInstanceOf <AkkaProtocolHandle>().HandshakeInfo.Uid);
                return(inbound.Association.AsInstanceOf <AkkaProtocolHandle>());
            });

            Assert.IsNotNull(wrappedHandle);

            wrappedHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(testActor));

            Assert.IsTrue(collaborators.FailureDetector.called);

            // Heartbeat was sent in response to Associate
            await AwaitCond(() => LastActivityIsHeartbeat(collaborators.Registry), DefaultTimeout);

            reader.Tell(testPayload, Self);

            expectMsgPF <InboundPayload>("expected InboundPayload", o =>
            {
                var inbound = o.AsInstanceOf <InboundPayload>();
                Assert.AreEqual(testEnvelope, inbound.Payload);
                return(null);
            });
        }
コード例 #2
0
        public void ProtocolStateActor_must_handle_correctly_when_the_handler_is_registered_only_after_the_association_is_already_closed()
        {
            var collaborators = GetCollaborators();

            collaborators.Transport.AssociateBehavior.PushConstant(collaborators.Handle);

            var statusPromise = new TaskCompletionSource <AssociationHandle>();
            var stateActor    =
                Sys.ActorOf(ProtocolStateActor.OutboundProps(new HandshakeInfo(localAddress, 42), remoteAddress,
                                                             statusPromise, collaborators.Transport,
                                                             new AkkaProtocolSettings(config), codec, collaborators.FailureDetector));

            AwaitCondition(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout);

            stateActor.Tell(testAssociate(33), Self);

            statusPromise.Task.Wait(TimeSpan.FromSeconds(3));
            statusPromise.Task.Result.Match()
            .With <AkkaProtocolHandle>(h =>
            {
                Assert.Equal(remoteAkkaAddress, h.RemoteAddress);
                Assert.Equal(localAkkaAddress, h.LocalAddress);
            })
            .Default(msg => Assert.True(false, "Did not receive expected AkkaProtocolHandle from handshake"));
            var wrappedHandle = statusPromise.Task.Result.AsInstanceOf <AkkaProtocolHandle>();

            stateActor.Tell(new Disassociated(DisassociateInfo.Unknown), Self);

            //handler tries to register after the association has closed
            wrappedHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(TestActor));

            ExpectMsgPf <Disassociated>("expected Disassociated(DisassociateInfo.Unknown", o =>
            {
                var disassociated = o.AsInstanceOf <Disassociated>();

                Assert.NotNull(disassociated);
                Assert.Equal(DisassociateInfo.Unknown, disassociated.Info);

                return(disassociated);
            });
        }
コード例 #3
0
        public async Task ProtocolStateActor_must_in_inbound_mode_disassociate_when_an_unexpected_message_arrives_instead_of_Associate()
        {
            var collaborators = GetCollaborators();

            var reader =
                sys.ActorOf(ProtocolStateActor.InboundProps(new HandshakeInfo(localAddress, 42), collaborators.Handle,
                                                            new ActorAssociationEventListener(testActor), new AkkaProtocolSettings(config), codec,
                                                            collaborators.FailureDetector));

            //a stray message will force a disassociate
            reader.Tell(testHeartbeat, Self);

            //this associate will now be ignored
            reader.Tell(testAssociate(33), Self);

            await AwaitCond(() =>
            {
                var snapshots = collaborators.Registry.LogSnapshot();
                return(snapshots.Any(x => x is DisassociateAttempt));
            }, DefaultTimeout);
        }
コード例 #4
0
        public async Task ProtocolStateActor_must_handle_explicit_disassociate_messages()
        {
            var collaborators = GetCollaborators();

            collaborators.Transport.AssociateBehavior.PushConstant(collaborators.Handle);

            var statusPromise = new TaskCompletionSource <AssociationHandle>();
            var reader        =
                sys.ActorOf(ProtocolStateActor.OutboundProps(new HandshakeInfo(localAddress, 42), remoteAddress,
                                                             statusPromise, collaborators.Transport,
                                                             new AkkaProtocolSettings(config), codec, collaborators.FailureDetector));

            await AwaitCond(() => LastActivityIsAssociate(collaborators.Registry, 42), DefaultTimeout);

            reader.Tell(testAssociate(33), Self);

            statusPromise.Task.Wait(TimeSpan.FromSeconds(3));
            statusPromise.Task.Result.Match()
            .With <AkkaProtocolHandle>(h =>
            {
                Assert.Equal(remoteAkkaAddress, h.RemoteAddress);
                Assert.Equal(localAkkaAddress, h.LocalAddress);
            })
            .Default(msg => Assert.True(false, "Did not receive expected AkkaProtocolHandle from handshake"));
            var wrappedHandle = statusPromise.Task.Result.AsInstanceOf <AkkaProtocolHandle>();

            wrappedHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(testActor));

            reader.Tell(testDisassociate(DisassociateInfo.Unknown), Self);

            expectMsgPF <Disassociated>("expected Disassociated(DisassociateInfo.Unknown", o =>
            {
                var disassociated = o.AsInstanceOf <Disassociated>();

                Assert.NotNull(disassociated);
                Assert.Equal(DisassociateInfo.Unknown, disassociated.Info);

                return(disassociated);
            });
        }
コード例 #5
0
        public void ProtocolStateActor_must_give_up_outbound_after_connection_timeout()
        {
            var collaborators = GetCollaborators();

            collaborators.Handle.Writeable = false;
            collaborators.Transport.AssociateBehavior.PushConstant(collaborators.Handle);

            var statusPromise = new TaskCompletionSource <AssociationHandle>();

            var conf2 = ConfigurationFactory.ParseString("akka.remote.dot-netty.tcp.connection-timeout = 500 ms")
                        .WithFallback(config);

            var stateActor =
                Sys.ActorOf(ProtocolStateActor.OutboundProps(new HandshakeInfo(_localAddress, 42), _remoteAddress,
                                                             statusPromise, collaborators.Transport,
                                                             new AkkaProtocolSettings(conf2), codec, collaborators.FailureDetector));

            Watch(stateActor);

            Intercept <TimeoutException>(() => statusPromise.Task.Wait(TimeSpan.FromSeconds(5)).Should().BeTrue());
            ExpectTerminated(stateActor);
        }