public void RetryAtMostRespectsMaximumAttempts([Range(0, 10)] int maxAttempts) { var retry = Retry.AtMost(maxAttempts); for (var attempt = 0; attempt < maxAttempts; attempt++) { Assert.That(retry.RetryDelay(attempt, TimeSpan.FromHours(1)), Is.EqualTo(TimeSpan.Zero)); } Assert.That(retry.RetryDelay(maxAttempts, TimeSpan.FromHours(1)), Is.Null); Assert.That(retry.RetryDelay(maxAttempts + 1, TimeSpan.FromHours(1)), Is.Null); }
public async Task ConsumerDoesNotThowArgumentExceptionWhenMemberMetadataIsKnownByConsumer() { var router = Substitute.For <IRouter>(); var conn = Substitute.For <IConnection>(); router.GetGroupConnectionAsync(Arg.Any <string>(), Arg.Any <CancellationToken>()) .Returns(_ => Task.FromResult(new GroupConnection(_.Arg <string>(), 0, conn))); router.Configuration.Returns(new RouterConfiguration(refreshRetry: new Retry(1, TimeSpan.FromSeconds(2)))); var configuration = new ConsumerConfiguration(coordinationRetry: Retry.AtMost(2)); var encoders = ConnectionConfiguration.Defaults.Encoders(); await AssertAsync.Throws <RequestException>( () => router.CreateGroupConsumerAsync("group", ConsumerEncoder.Protocol, new ByteTypeMetadata("mine", new ArraySegment <byte>()), configuration, encoders, CancellationToken.None)); }
public void WillRetryOnly3Times() { int retries = 0; try { Retry.AtMost(3).Try(() => { retries++; throw new InvalidOperationException(); }); } catch (AggregateException e) { Assert.That(3, Is.EqualTo(e.InnerExceptions.Cast <InvalidOperationException>().Count())); } Assert.That(retries, Is.EqualTo(3)); }
public void WillRetryOnly3Times() { int retries = 0; try { Retry.AtMost(3).Try(() => { retries++; throw new InvalidOperationException(); }); } catch (AggregateException e) { e.InnerExceptions.Cast <InvalidOperationException>().Count().ShouldBe(3); } retries.ShouldBe(3); }
public async Task WhenNoConnectionThrowSocketExceptionAfterMaxRetry() { var connectionAttempts = 0; const int maxRetries = 2; var endpoint = TestConfig.ServerEndpoint(); var config = new ConnectionConfiguration( Retry.AtMost(maxRetries), onConnecting: (e, attempt, elapsed) => Interlocked.Increment(ref connectionAttempts) ); using (var transport = CreateTransport(endpoint, config, TestConfig.Log)) { try { await transport.ConnectAsync(CancellationToken.None); Assert.Fail("Did not throw ConnectionException"); } catch (ConnectionException) { // expected } Assert.That(connectionAttempts, Is.EqualTo(1 + maxRetries)); } }
public void Start() { try { var configurationPort = configuration.Port; HttpServer server = null; pipe = Retry.AtMost(5).Try(() => { var host = new IPEndPoint(IPAddress.Any, configurationPort); server = new HttpServer(host); logger.Debug("Staring diagnostics service on " + host); try { return(server.Start()); } catch (Exception) { configurationPort++; throw; } }); server.Host((env, respond, error) => { try { var path = (string)env["Owin.RequestUri"]; path = path.ToLower(); if (path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); } var queryStringIdx = path.IndexOf("?"); var parameters = queryStringIdx == -1 ? new NameValueCollection() : HttpUtility.ParseQueryString(path.Substring(path.IndexOf("?"))); IResourceHandler handler; if (path.StartsWith("/stats")) { handler = statsHandler; } else if (path.StartsWith("/server_info")) { handler = serviceInfoHandler; } else if (path.StartsWith("/ping")) { handler = pingHandler; } else if (path.StartsWith("/static")) { handler = staticResourceHandler; } else if (path.StartsWith("/report")) { path = "/static/report.html"; handler = staticResourceHandler; } else if (path.StartsWith("/graph_data")) { handler = graphDataHandler; } else if (path.StartsWith("/graph")) { path = "/static/graph.html"; handler = staticResourceHandler; } else { path = "/static/index.html"; handler = staticResourceHandler; } handler.Handle(path, parameters, respond); } catch (Exception e) { error(e); respond("500 Internal Server Error", new Dictionary <string, IList <string> > { { "Content-Type", new[] { "text/html" } } }, new[] { string.Empty }); } }); logger.Debug("Listening on " + server.ListenEndPoint); } // ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { } }
public void RetryAtMostRetriesWithNoDelay() { Assert.That(Retry.AtMost(1).RetryDelay(0, TimeSpan.Zero), Is.EqualTo(TimeSpan.Zero)); }
public RouterConfiguration(IRetry refreshRetry = null, TimeSpan?cacheExpiration = null, IRetry sendRetry = null) { RefreshRetry = refreshRetry ?? Defaults.RefreshRetry(); CacheExpiration = cacheExpiration ?? TimeSpan.FromSeconds(Defaults.CacheExpirationSeconds); SendRetry = sendRetry ?? Retry.AtMost(Defaults.MaxSendRetryAttempts); }