public void A_restart_with_backoff_source_should_restart_on_failure_when_only_due_to_failures_should_be_restarted() { this.AssertAllStagesStopped(() => { var created = new AtomicCounter(0); var probe = RestartSource.OnFailuresWithBackoff(() => { created.IncrementAndGet(); var enumerable = new List <string> { "a", "b", "c" }.Select(c => { if (c == "c") { throw new ArgumentException("failed"); } return(c); }); return(Source.From(enumerable)); }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20), 0).RunWith(this.SinkProbe <string>(), Materializer); probe.RequestNext("a"); probe.RequestNext("b"); probe.RequestNext("a"); probe.RequestNext("b"); probe.RequestNext("a"); created.Current.Should().Be(3); probe.Cancel(); }, Materializer); }
private static Source <TOut, NotUsed> RestartSourceFactory <TOut, TMat>(Func <Source <TOut, TMat> > flowFactory, TimeSpan minBackoff, TimeSpan maxBackoff, double randomFactor, int maxRestarts, bool onlyOnFailures) { return(onlyOnFailures ? RestartSource.OnFailuresWithBackoff(flowFactory, minBackoff, maxBackoff, randomFactor, maxRestarts) : RestartSource.WithBackoff(flowFactory, minBackoff, maxBackoff, randomFactor, maxRestarts)); }