public void TestSkipStreamListenerActorInstanceCreationWhenFixtureHasMatchOver() { // //Arrange // SettingsMock.SetupGet(a => a.FixtureCreationConcurrency).Returns(10); var resourceFacadeMock = new Mock <IResourceFacade>(); resourceFacadeMock.SetupGet(o => o.Id).Returns("Fixture1Id"); resourceFacadeMock.SetupGet(o => o.MatchStatus).Returns(MatchStatus.MatchOver); // //Act // var streamListenerBuilderActorRef = ActorOfAsTestActorRef <StreamListenerBuilderActor>( Props.Create(() => new StreamListenerBuilderActor( SettingsMock.Object, new Mock <IActorContext>().Object, PluginMock.Object, StateManagerMock.Object, SuspensionManagerMock.Object, StreamHealthCheckValidationMock.Object, FixtureValidationMock.Object)), StreamListenerBuilderActor.ActorName); // //Act // streamListenerBuilderActorRef.Tell( new CreateStreamListenerMsg { Resource = resourceFacadeMock.Object }); Task.Delay(TimeSpan.FromMilliseconds(100)); streamListenerBuilderActorRef.Tell( new CheckFixtureStateMsg { Resource = resourceFacadeMock.Object, ShouldProcessFixture = false }); // //Assert // AwaitAssert(() => { Assert.AreEqual( StreamListenerBuilderState.Active, streamListenerBuilderActorRef.UnderlyingActor.State); Assert.AreEqual( 0, streamListenerBuilderActorRef.UnderlyingActor.CreationInProgressFixtureIdSetCount); }, TimeSpan.FromMilliseconds(ASSERT_WAIT_TIMEOUT), TimeSpan.FromMilliseconds(ASSERT_EXEC_INTERVAL)); }
public void ConnectToStreamingServerAndProcessSnapshot() { // //Arrange // Fixture snapshot; Mock <IResourceFacade> resourceFacadeMock; SetupCommonMockObjects( /*sport*/ FootabllSportMock.Object.Name, /*fixtureData*/ FixtureSamples.football_setup_snapshot_2, /*storedData*/ new { Epoch = 3, Sequence = 1, MatchStatus = MatchStatus.Setup }, out snapshot, out resourceFacadeMock); ServiceMock.Setup(o => o.GetResources(It.Is <string>(s => s.Equals(FootabllSportMock.Object.Name)))) .Returns(new List <IResourceFacade> { resourceFacadeMock.Object }); StreamHealthCheckValidationMock.Setup(a => a.CanConnectToStreamServer( It.IsAny <IResourceFacade>(), It.IsAny <StreamListenerState>())) .Returns(false); SettingsMock.SetupGet(a => a.AllowFixtureStreamingInSetupMode).Returns(false); FixtureValidationMock.Setup(a => a.IsSnapshotNeeded( It.IsAny <IResourceFacade>(), It.IsAny <FixtureState>())) .Returns(true); // //Act // var streamListenerManagerActor = ActorOfAsTestActorRef <StreamListenerManagerActor>( Props.Create(() => new StreamListenerManagerActor( SettingsMock.Object, PluginMock.Object, StateManagerMock.Object, SuspensionManagerMock.Object, StreamHealthCheckValidationMock.Object, FixtureValidationMock.Object)), StreamListenerManagerActor.ActorName); var sportProcessorRouterActor = ActorOfAsTestActorRef <SportProcessorRouterActor>( Props.Create(() => new SportProcessorRouterActor(ServiceMock.Object)) .WithRouter(new SmallestMailboxPool(SettingsMock.Object.FixtureCreationConcurrency)), SportProcessorRouterActor.ActorName); sportProcessorRouterActor.Tell(new ProcessSportMsg { Sport = FootabllSportMock.Object.Name }); IActorRef streamListenerActorRef; StreamListenerActor streamListenerActor = null; IActorRef resourceActorRef; IActorRef healthCheckActorRef; //Get child actors instances AwaitAssert(() => { streamListenerActorRef = GetChildActorRef( streamListenerManagerActor, StreamListenerActor.GetName(resourceFacadeMock.Object.Id)); streamListenerActor = GetUnderlyingActor <StreamListenerActor>(streamListenerActorRef); resourceActorRef = GetChildActorRef(streamListenerActorRef, ResourceActor.ActorName); healthCheckActorRef = GetChildActorRef(streamListenerActorRef, StreamHealthCheckActor.ActorName); Assert.NotNull(streamListenerActorRef); Assert.NotNull(streamListenerActor); Assert.NotNull(resourceActorRef); Assert.NotNull(healthCheckActorRef); Assert.AreEqual(StreamListenerState.Initialized, streamListenerActor.State); }, TimeSpan.FromMilliseconds(ASSERT_WAIT_TIMEOUT), TimeSpan.FromMilliseconds(ASSERT_EXEC_INTERVAL)); StreamHealthCheckValidationMock.Reset(); StreamHealthCheckValidationMock.Setup(a => a.CanConnectToStreamServer( It.IsAny <IResourceFacade>(), It.IsAny <StreamListenerState>())) .Returns(true); StreamHealthCheckValidationMock.Setup(a => a.ValidateStream( It.IsAny <IResourceFacade>(), It.IsAny <StreamListenerState>(), It.IsAny <int>())) .Returns(true); //This call will trigger health check message sportProcessorRouterActor.Tell(new ProcessSportMsg { Sport = FootabllSportMock.Object.Name }); // //Assert // AwaitAssert(() => { resourceFacadeMock.Verify(a => a.GetSnapshot(), Times.Exactly(2)); PluginMock.Verify(a => a.ProcessSnapshot(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), false), Times.Exactly(2)); PluginMock.Verify(a => a.ProcessSnapshot(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), true), Times.Never); PluginMock.Verify(a => a.ProcessMatchStatus(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id))), Times.Never); SuspensionManagerMock.Verify(a => a.Unsuspend(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id))), Times.Never); SuspensionManagerMock.Verify(a => a.Suspend(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), SuspensionReason.SUSPENSION), Times.Never); Assert.AreEqual(StreamListenerState.Streaming, streamListenerActor.State); }, TimeSpan.FromMilliseconds(ASSERT_WAIT_TIMEOUT), TimeSpan.FromMilliseconds(ASSERT_EXEC_INTERVAL)); }
public void WhenStartStreamingIsNotRespondingThenStopStreamListener() { // //Arrange // Fixture snapshot; Mock <IResourceFacade> resourceFacadeMock; SetupCommonMockObjects( /*sport*/ FootabllSportMock.Object.Name, /*fixtureData*/ FixtureSamples.football_inplay_snapshot_2, /*storedData*/ new { Epoch = 7, Sequence = 1, MatchStatus = MatchStatus.InRunning }, out snapshot, out resourceFacadeMock); StreamHealthCheckValidationMock.Setup(a => a.CanConnectToStreamServer( It.IsAny <IResourceFacade>(), It.IsAny <StreamListenerState>())) .Returns(true); SettingsMock.SetupGet(o => o.StartStreamingTimeoutInSeconds).Returns(1); SettingsMock.SetupGet(o => o.StartStreamingAttempts).Returns(3); ServiceMock.Setup(o => o.GetResources(It.Is <string>(s => s.Equals(FootabllSportMock.Object.Name)))) .Returns(new List <IResourceFacade> { resourceFacadeMock.Object }); resourceFacadeMock.Reset(); resourceFacadeMock.Setup(o => o.Id).Returns(snapshot.Id); resourceFacadeMock.Setup(o => o.Sport).Returns(FootabllSportMock.Object.Name); resourceFacadeMock.Setup(o => o.MatchStatus).Returns((MatchStatus)Convert.ToInt32(snapshot.MatchStatus)); resourceFacadeMock.Setup(o => o.Content).Returns(new Summary { Id = snapshot.Id, Sequence = snapshot.Sequence, MatchStatus = Convert.ToInt32(snapshot.MatchStatus), StartTime = snapshot.StartTime?.ToString("yyyy-MM-ddTHH:mm:ssZ") }); // //Act // var streamListenerManagerActor = ActorOfAsTestActorRef <StreamListenerManagerActor>( Props.Create(() => new StreamListenerManagerActor( SettingsMock.Object, PluginMock.Object, StateManagerMock.Object, SuspensionManagerMock.Object, StreamHealthCheckValidationMock.Object, FixtureValidationMock.Object)), StreamListenerManagerActor.ActorName); var sportProcessorRouterActor = ActorOfAsTestActorRef <SportProcessorRouterActor>( Props.Create(() => new SportProcessorRouterActor(ServiceMock.Object)) .WithRouter(new SmallestMailboxPool(SettingsMock.Object.FixtureCreationConcurrency)), SportProcessorRouterActor.ActorName); sportProcessorRouterActor.Tell(new ProcessSportMsg { Sport = FootabllSportMock.Object.Name }); //wait for 5 seconds while the health checks run every second and after 3 attempts the manager kills the actor Task.Delay(5000).Wait(); // //Assert // AwaitAssert(() => { resourceFacadeMock.Verify(a => a.GetSnapshot(), Times.Never); PluginMock.Verify(a => a.ProcessSnapshot(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), false), Times.Never); PluginMock.Verify(a => a.ProcessSnapshot(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), true), Times.Never); PluginMock.Verify(a => a.ProcessStreamUpdate(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), false), Times.Never); SuspensionManagerMock.Verify(a => a.Unsuspend(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id))), Times.Never); SuspensionManagerMock.Verify(a => a.Suspend(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), SuspensionReason.SUSPENSION), Times.Never); SuspensionManagerMock.Verify(a => a.Suspend(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), SuspensionReason.FIXTURE_ERRORED), Times.Never); SuspensionManagerMock.Verify(a => a.Suspend(It.Is <Fixture>(f => f.Id.Equals(resourceFacadeMock.Object.Id)), SuspensionReason.DISCONNECT_EVENT), Times.Never); Assert.Throws <AggregateException>(() => { Sys.ActorSelection( streamListenerManagerActor, StreamListenerActor.GetName(resourceFacadeMock.Object.Id)) .ResolveOne(TimeSpan.FromSeconds(5)).Wait(); }).InnerException.Should().BeOfType <ActorNotFoundException>(); }, TimeSpan.FromMilliseconds(ASSERT_WAIT_TIMEOUT), TimeSpan.FromMilliseconds(ASSERT_EXEC_INTERVAL)); }
public void TestConcurrentStreamListenerCreationLimit() { // //Arrange // SettingsMock.SetupGet(a => a.FixtureCreationConcurrency).Returns(3); var resource1FacadeMock = new Mock <IResourceFacade>(); var resource2FacadeMock = new Mock <IResourceFacade>(); var resource3FacadeMock = new Mock <IResourceFacade>(); var resource4FacadeMock = new Mock <IResourceFacade>(); var resource5FacadeMock = new Mock <IResourceFacade>(); resource1FacadeMock.Setup(o => o.Id).Returns("Fixture1Id"); resource2FacadeMock.Setup(o => o.Id).Returns("Fixture2Id"); resource3FacadeMock.Setup(o => o.Id).Returns("Fixture3Id"); resource4FacadeMock.Setup(o => o.Id).Returns("Fixture4Id"); resource5FacadeMock.Setup(o => o.Id).Returns("Fixture5Id"); // //Act // var streamListenerBuilderActorRef = ActorOfAsTestActorRef <StreamListenerBuilderActor>( Props.Create(() => new StreamListenerBuilderActor( SettingsMock.Object, new Mock <IActorContext>().Object, PluginMock.Object, StateManagerMock.Object, SuspensionManagerMock.Object, StreamHealthCheckValidationMock.Object, FixtureValidationMock.Object)), StreamListenerBuilderActor.ActorName); // //Assert // AwaitAssert(() => { Assert.AreEqual( StreamListenerBuilderState.Active, streamListenerBuilderActorRef.UnderlyingActor.State); }, TimeSpan.FromMilliseconds(ASSERT_WAIT_TIMEOUT), TimeSpan.FromMilliseconds(ASSERT_EXEC_INTERVAL)); // //Act // streamListenerBuilderActorRef.Tell(new CreateStreamListenerMsg { Resource = resource1FacadeMock.Object }); Task.Delay(TimeSpan.FromMilliseconds(50)); streamListenerBuilderActorRef.Tell(new CreateStreamListenerMsg { Resource = resource2FacadeMock.Object }); Task.Delay(TimeSpan.FromMilliseconds(50)); streamListenerBuilderActorRef.Tell(new CreateStreamListenerMsg { Resource = resource3FacadeMock.Object }); Task.Delay(TimeSpan.FromMilliseconds(50)); streamListenerBuilderActorRef.Tell(new CreateStreamListenerMsg { Resource = resource4FacadeMock.Object }); Task.Delay(TimeSpan.FromMilliseconds(50)); streamListenerBuilderActorRef.Tell(new CreateStreamListenerMsg { Resource = resource5FacadeMock.Object }); // //Assert // AwaitAssert(() => { Assert.AreEqual( StreamListenerBuilderState.Busy, streamListenerBuilderActorRef.UnderlyingActor.State); }, TimeSpan.FromMilliseconds(ASSERT_WAIT_TIMEOUT), TimeSpan.FromMilliseconds(ASSERT_EXEC_INTERVAL)); // //Act // Task.Delay(TimeSpan.FromMilliseconds(50)); streamListenerBuilderActorRef.Tell(new StreamListenerCreationCompletedMsg { FixtureId = resource1FacadeMock.Object.Id }); Task.Delay(TimeSpan.FromMilliseconds(50)); streamListenerBuilderActorRef.Tell(new StreamListenerCreationCompletedMsg { FixtureId = resource2FacadeMock.Object.Id }); Task.Delay(TimeSpan.FromMilliseconds(50)); streamListenerBuilderActorRef.Tell(new StreamListenerCreationFailedMsg { FixtureId = resource4FacadeMock.Object.Id }); // //Assert // AwaitAssert(() => { Assert.AreEqual( StreamListenerBuilderState.Active, streamListenerBuilderActorRef.UnderlyingActor.State); }, TimeSpan.FromMilliseconds(ASSERT_WAIT_TIMEOUT), TimeSpan.FromMilliseconds(ASSERT_EXEC_INTERVAL)); }