public async Task CircuitBreaker_must_reply_with_special_failure_message_on_Write_requests_if_open()
        {
            var events = new[] { new DurableEvent("a", "emitter") };

            breaker.Tell(ServiceEvent.Failed(LogId, 1, TestLogFailureException));
            breaker.Tell(new Write(events, probe.Ref, probe.Ref, 1, 2));
            probe.ExpectMsg(new WriteFailure(events, CircuitBreaker.Exception, 1, 2));
            probe.Sender.Should().Be(probe.Ref);
        }
 public async Task CircuitBreaker_must_open_after_first_failed_retry()
 {
     breaker.Tell(ServiceEvent.Failed(LogId, 1, TestLogFailureException));
     try
     {
         await breaker.Ask("a", Timeout);
     }
     catch (AggregateException e) when(e.Flatten().InnerException is EventLogUnavailableException)
     {
         // as expected
     }
 }
        public async Task CircuitBreaker_must_publish_ServiceNormal_once_on_event_stream_when_closed()
        {
            Sys.EventStream.Subscribe(probe.Ref, typeof(ServiceEvent));

            breaker.Tell(ServiceEvent.Failed(LogId, 1, TestLogFailureException));
            probe.FishForMessage(msg => msg is ServiceEvent e && e.Type == ServiceEvent.EventType.ServiceFailed);
            breaker.Tell(ServiceEvent.Normal(LogId));
            probe.ExpectMsg(ServiceEvent.Normal(LogId));

            breaker.Tell(ServiceEvent.Normal(LogId));
            probe.ExpectNoMsg(300.Milliseconds());
        }
        public async Task CircuitBreaker_must_publish_ServiceFailed_once_on_event_stream_when_opened()
        {
            Sys.EventStream.Subscribe(probe.Ref, typeof(ServiceEvent));

            var serviceFailed = ServiceEvent.Failed(LogId, 1, TestLogFailureException);

            breaker.Tell(serviceFailed);
            probe.ExpectMsg(serviceFailed);

            breaker.Tell(ServiceEvent.Failed(LogId, 2, TestLogFailureException));
            probe.ExpectNoMsg(300.Milliseconds());
        }
        public async Task CircuitBreaker_must_close_again_after_service_initialization()
        {
            breaker.Tell(ServiceEvent.Failed(LogId, 1, TestLogFailureException));
            try
            {
                await breaker.Ask("a", Timeout);
            }
            catch (AggregateException e) when(e.Flatten().InnerException is EventLogUnavailableException)
            {
                // as expected
            }

            breaker.Tell(ServiceEvent.Initialized(LogId));
            (await breaker.Ask("a", Timeout)).Should().Be("re-a");
        }
 public async Task CircuitBreaker_must_be_closed_after_initial_failure()
 {
     breaker.Tell(ServiceEvent.Failed(LogId, 0, TestLogFailureException));
     (await breaker.Ask("a", Timeout)).Should().Be("re-a");
 }