public Collaborators(AssociationRegistry registry, TestTransport transport, TestAssociationHandle handle, TestFailureDetector failureDetector) { FailureDetector = failureDetector; Handle = handle; Transport = transport; Registry = registry; }
public override void Cleanup() { base.Cleanup(); // force all content logged by the TestTransport to be released AssociationRegistry.Get(_registryKey).Reset(); }
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)); }
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); }
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); }
public Collaborators GetCollaborators() { var registry = new AssociationRegistry(); var transport = new TestTransport(localAddress, registry); var handle = new TestAssociationHandle(localAddress, remoteAddress, transport, true); transport.WriteBehavior.PushConstant(true); return new Collaborators(registry, transport, handle, new TestFailureDetector()); }
public Collaborators GetCollaborators() { var registry = new AssociationRegistry(); var transport = new TestTransport(localAddress, registry); var handle = new TestAssociationHandle(localAddress, remoteAddress, transport, true); transport.WriteBehavior.PushConstant(true); return(new Collaborators(registry, transport, handle, new TestFailureDetector())); }
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); }
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)) ); }
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)) ); }
/// <summary> /// Converts a model from Edm term into Taupo term /// </summary> /// <param name="edmModel">The input model in Edm term</param> /// <returns>The output model in Taupo term</returns> public EntityModelSchema ConvertToTaupoModel(IEdmModel edmModel) { this.edmModel = edmModel; this.associationRegistry = new AssociationRegistry(); var taupoModel = new EntityModelSchema(); foreach (var edmComplexType in edmModel.SchemaElements.OfType <IEdmComplexType>()) { ComplexType taupoComplexType = this.ConvertToTaupoComplexType(edmComplexType); taupoModel.Add(taupoComplexType); } foreach (var edmEntityType in edmModel.SchemaElements.OfType <IEdmEntityType>()) { EntityType taupoEntityType = this.ConvertToTaupoEntityType(edmEntityType); taupoModel.Add(taupoEntityType); // convert to Association using information inside Navigations foreach (var edmNavigationProperty in edmEntityType.DeclaredNavigationProperties()) { if (!this.associationRegistry.IsAssociationRegistered(edmNavigationProperty)) { this.associationRegistry.RegisterAssociation(edmNavigationProperty); } } } var edmEntityContainer = edmModel.EntityContainer; if (edmEntityContainer != null) { EntityContainer taupoEntityContainer = this.ConvertToTaupoEntityContainer(edmEntityContainer); taupoModel.Add(taupoEntityContainer); } foreach (var edmFunction in edmModel.SchemaElements.OfType <IEdmOperation>()) { Function taupoFunction = this.ConvertToTaupoFunction(edmFunction); taupoModel.Add(taupoFunction); } foreach (var edmEnum in edmModel.SchemaElements.OfType <IEdmEnumType>()) { EnumType taupoEnumType = this.ConvertToTaupoEnumType(edmEnum); taupoModel.Add(taupoEnumType); } return(taupoModel.Resolve()); }
/// <summary> /// Converts a model from Edm term into Taupo term /// </summary> /// <param name="edmModel">The input model in Edm term</param> /// <returns>The output model in Taupo term</returns> public EntityModelSchema ConvertToTaupoModel(IEdmModel edmModel) { this.edmModel = edmModel; this.associationRegistry = new AssociationRegistry(); var taupoModel = new EntityModelSchema(); foreach (var edmComplexType in edmModel.SchemaElements.OfType<IEdmComplexType>()) { ComplexType taupoComplexType = this.ConvertToTaupoComplexType(edmComplexType); taupoModel.Add(taupoComplexType); } foreach (var edmEntityType in edmModel.SchemaElements.OfType<IEdmEntityType>()) { EntityType taupoEntityType = this.ConvertToTaupoEntityType(edmEntityType); taupoModel.Add(taupoEntityType); // convert to Association using information inside Navigations foreach (var edmNavigationProperty in edmEntityType.DeclaredNavigationProperties()) { if (!this.associationRegistry.IsAssociationRegistered(edmNavigationProperty)) { this.associationRegistry.RegisterAssociation(edmNavigationProperty); } } } var edmEntityContainer = edmModel.EntityContainer; if (edmEntityContainer != null) { EntityContainer taupoEntityContainer = this.ConvertToTaupoEntityContainer(edmEntityContainer); taupoModel.Add(taupoEntityContainer); } foreach (var edmFunction in edmModel.SchemaElements.OfType<IEdmOperation>()) { Function taupoFunction = this.ConvertToTaupoFunction(edmFunction); taupoModel.Add(taupoFunction); } foreach (var edmEnum in edmModel.SchemaElements.OfType<IEdmEnumType>()) { EnumType taupoEnumType = this.ConvertToTaupoEnumType(edmEnum); taupoModel.Add(taupoEnumType); } return taupoModel.Resolve(); }
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); }
public void TestTransport_fail_to_association_with_nonexisting_Address() { //arrange var registry = new AssociationRegistry(); var transportA = new TestTransport(addressA, registry); //act var result = transportA.Listen(); result.Wait(DefaultTimeout); result.Result.Item2.SetResult(new ActorAssociationEventListener(Self)); //assert intercept<InvalidAssociationException>(() => { var associateTask = transportA.Associate(nonExistantAddress); associateTask.Wait(DefaultTimeout); var fireException = associateTask.Result; }); }
public void TestTransport_fail_to_association_with_nonexisting_Address() { //arrange var registry = new AssociationRegistry(); var transportA = new TestTransport(addressA, registry); //act var result = transportA.Listen(); result.Wait(DefaultTimeout); result.Result.Item2.SetResult(new ActorAssociationEventListener(Self)); //assert XAssert.Throws <InvalidAssociationException>(() => { var associateTask = transportA.Associate(nonExistantAddress); associateTask.Wait(DefaultTimeout); var fireException = associateTask.Result; }); }
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) ); }
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); }
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); }
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); }
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); }
protected override void AfterAll() { Shutdown(_remoteSystem, RemainingOrDefault); AssociationRegistry.Clear(); base.AfterAll(); }
public override void Dispose() { remoteSystem.Shutdown(); AssociationRegistry.Clear(); }
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)); }
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)); }
protected override void AfterTest() { remoteSystem.Shutdown(); AssociationRegistry.Clear(); base.AfterTest(); }
protected override void AfterAll() { remoteSystem.Terminate(); AssociationRegistry.Clear(); base.AfterAll(); }
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)); }
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)); }
public void Stash_inbound_connections_until_UID_is_known_for_pending_outbound() { var localAddress = new Address("akka.test", "system1", "localhost", 1); var rawLocalAddress = new Address("test", "system1", "localhost", 1); var remoteAddress = new Address("akka.test", "system2", "localhost", 2); var rawRemoteAddress = new Address("test", "system2", "localhost", 2); var config = ConfigurationFactory.ParseString(@" akka.remote.enabled-transports = [""akka.remote.test""] akka.remote.retry-gate-closed-for = 5s akka.remote.log-remote-lifecycle-events = on akka.loglevel = DEBUG akka.remote.test { registry-key = TRKAzR local-address = """ + $"test://{localAddress.System}@{localAddress.Host}:{localAddress.Port}" + @""" }").WithFallback(_remoteSystem.Settings.Config); var thisSystem = ActorSystem.Create("this-system", config); MuteSystem(thisSystem); try { // Set up a mock remote system using the test transport var registry = AssociationRegistry.Get("TRKAzR"); var remoteTransport = new TestTransport(rawRemoteAddress, registry); var remoteTransportProbe = CreateTestProbe(); registry.RegisterTransport(remoteTransport, Task.FromResult <IAssociationEventListener> (new ActorAssociationEventListener(remoteTransportProbe))); // Hijack associations through the test transport AwaitCondition(() => registry.TransportsReady(rawLocalAddress, rawRemoteAddress)); var testTransport = registry.TransportFor(rawLocalAddress).Item1; testTransport.WriteBehavior.PushConstant(true); // Force an outbound associate on the real system (which we will hijack) // we send no handshake packet, so this remains a pending connection var dummySelection = thisSystem.ActorSelection(ActorPath.Parse(remoteAddress + "/user/noonethere")); dummySelection.Tell("ping", Sys.DeadLetters); var remoteHandle = remoteTransportProbe.ExpectMsg <InboundAssociation>(TimeSpan.FromMinutes(4)); remoteHandle.Association.ReadHandlerSource.TrySetResult((IHandleEventListener)(new ActionHandleEventListener(ev => { }))); // Now we initiate an emulated inbound connection to the real system var inboundHandleProbe = CreateTestProbe(); var inboundHandleTask = remoteTransport.Associate(rawLocalAddress); inboundHandleTask.Wait(TimeSpan.FromSeconds(3)); var inboundHandle = inboundHandleTask.Result; inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(inboundHandleProbe)); AwaitAssert(() => { registry.GetRemoteReadHandlerFor(inboundHandle.AsInstanceOf <TestAssociationHandle>()).Should().NotBeNull(); }); var pduCodec = new AkkaPduProtobuffCodec(Sys); var handshakePacket = pduCodec.ConstructAssociate(new HandshakeInfo(rawRemoteAddress, 0)); var brokenPacket = pduCodec.ConstructPayload(ByteString.CopyFrom(0, 1, 2, 3, 4, 5, 6)); // Finish the inbound handshake so now it is handed up to Remoting inboundHandle.Write(handshakePacket); // Now bork the connection with a malformed packet that can only signal an error if the Endpoint is already registered // but not while it is stashed inboundHandle.Write(brokenPacket); // No disassociation now - the connection is still stashed inboundHandleProbe.ExpectNoMsg(1000); // Finish the handshake for the outbound connection - this will unstash the inbound pending connection. remoteHandle.Association.Write(handshakePacket); inboundHandleProbe.ExpectMsg <Disassociated>(TimeSpan.FromMinutes(5)); } finally { Shutdown(thisSystem); } }
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; }
public void Properly_quarantine_stashed_inbound_connections() { var localAddress = new Address("akka.test", "system1", "localhost", 1); var rawLocalAddress = new Address("test", "system1", "localhost", 1); var remoteAddress = new Address("akka.test", "system2", "localhost", 2); var rawRemoteAddress = new Address("test", "system2", "localhost", 2); var remoteUID = 16; var config = ConfigurationFactory.ParseString(@" akka.remote.enabled-transports = [""akka.remote.test""] akka.remote.retry-gate-closed-for = 5s akka.remote.log-remote-lifecycle-events = on akka.remote.test { registry-key = JMeMndLLsw local-address = """ + $"test://{localAddress.System}@{localAddress.Host}:{localAddress.Port}" + @""" }").WithFallback(_remoteSystem.Settings.Config); var thisSystem = ActorSystem.Create("this-system", config); MuteSystem(thisSystem); try { // Set up a mock remote system using the test transport var registry = AssociationRegistry.Get("JMeMndLLsw"); var remoteTransport = new TestTransport(rawRemoteAddress, registry); var remoteTransportProbe = CreateTestProbe(); registry.RegisterTransport(remoteTransport, Task.FromResult <IAssociationEventListener> (new ActorAssociationEventListener(remoteTransportProbe))); // Hijack associations through the test transport AwaitCondition(() => registry.TransportsReady(rawLocalAddress, rawRemoteAddress)); var testTransport = registry.TransportFor(rawLocalAddress).Item1; testTransport.WriteBehavior.PushConstant(true); // Force an outbound associate on the real system (which we will hijack) // we send no handshake packet, so this remains a pending connection var dummySelection = thisSystem.ActorSelection(ActorPath.Parse(remoteAddress + "/user/noonethere")); dummySelection.Tell("ping", Sys.DeadLetters); var remoteHandle = remoteTransportProbe.ExpectMsg <InboundAssociation>(TimeSpan.FromMinutes(4)); remoteHandle.Association.ReadHandlerSource.TrySetResult((IHandleEventListener)(new ActionHandleEventListener(ev => {}))); // Now we initiate an emulated inbound connection to the real system var inboundHandleProbe = CreateTestProbe(); var inboundHandleTask = remoteTransport.Associate(rawLocalAddress); inboundHandleTask.Wait(TimeSpan.FromSeconds(3)); var inboundHandle = inboundHandleTask.Result; inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(inboundHandleProbe)); AwaitAssert(() => { registry.GetRemoteReadHandlerFor(inboundHandle.AsInstanceOf <TestAssociationHandle>()).Should().NotBeNull(); }); var pduCodec = new AkkaPduProtobuffCodec(Sys); var handshakePacket = pduCodec.ConstructAssociate(new HandshakeInfo(rawRemoteAddress, remoteUID)); // Finish the inbound handshake so now it is handed up to Remoting inboundHandle.Write(handshakePacket); // No disassociation now, the connection is still stashed inboundHandleProbe.ExpectNoMsg(1000); // Quarantine unrelated connection RARP.For(thisSystem).Provider.Quarantine(remoteAddress, -1); inboundHandleProbe.ExpectNoMsg(1000); // Quarantine the connection RARP.For(thisSystem).Provider.Quarantine(remoteAddress, remoteUID); // Even though the connection is stashed it will be disassociated inboundHandleProbe.ExpectMsg <Disassociated>(); } finally { Shutdown(thisSystem); } }
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; }
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; }
public override void Cleanup() { // nuke all registries AssociationRegistry.Clear(); base.Cleanup(); }
private Akka.Remote.Transport.Transport NewTransportB(AssociationRegistry registry) { return(WrapTransport(FreshTransport(new TestTransport(addressBTest, registry)))); }