Ejemplo n.º 1
0
        public void ReadChannelMessage_ShouldReadChannel()
        {
            // Arrange
            var channelName = "SomeChannel";
            var driver = new MeterDriverFake();
            var sut = Sys.ActorOf(DriverActor.CreateProps(driver));

            // Act
            sut.Tell(new DriverActor.ReadChannel(channelName));

            // Assert
            ExpectMsg<DriverActor.ReadingsAvailable>(msg => msg.ChannelName == channelName);
        }
Ejemplo n.º 2
0
        public void ReadChannelMessage_ShouldBeStashedIfBusy()
        {
            // Arrange
            var channelName = "SomeChannel";
            var driver = new MeterDriverFake { ReadDuration = TimeSpan.FromSeconds(3) };
            var sut = ActorOfAsTestActorRef<DriverActor>(DriverActor.CreateProps(driver));

            sut.Tell(new DriverActor.ReadChannel(channelName));

            // Act
            sut.Tell(new DriverActor.ReadChannel(channelName));

            // Assert
            Assert.Equal(1, sut.UnderlyingActor.Stash.ClearStash().Count());
        }
Ejemplo n.º 3
0
        public void ReadChannelMessage_ShouldNotConnectIfAlreadyConnected()
        {
            // Arrange
            var channelName = "SomeChannel";
            var driver = new MeterDriverFake();
            var sut = Sys.ActorOf(DriverActor.CreateProps(driver));

            // Get some readings to make sure the driver is connected.
            sut.Tell(new DriverActor.ReadChannel(channelName));
            ExpectMsg<DriverActor.ReadingsAvailable>();

            // Act
            sut.Tell(new DriverActor.ReadChannel(channelName));

            // Assert
            ExpectMsg<DriverActor.ReadingsAvailable>(msg => msg.ChannelName == channelName);

            // Check that we haven't connected more than once.
            Assert.Equal(1, driver.ConnectCount);
        }
Ejemplo n.º 4
0
        public void ReadChannelMessage_ShouldRetryIfConnectionFailed()
        {
            // Arrange
            var channelName = "SomeChannel";
            var supervisor = CreateTestProbe("supervisor");
            var driver = new MeterDriverFake { ThrowExceptionOnFirstConnect = true };
            var sut = ActorOfAsTestActorRef<DriverActor>(DriverActor.CreateProps(driver), supervisor);

            // Act
            sut.Tell(new DriverActor.ReadChannel(channelName));

            // Assert

            var errorMessage = supervisor.ExpectMsg<DriverActor.ErrorOccured>();

            Scheduler.Advance(errorMessage.RetryWaitTime);

            ExpectMsg<DriverActor.ReadingsAvailable>(msg => msg.ChannelName == channelName);
            
            Assert.Equal(2, driver.ConnectCount);
        }