public async Task TestFailedEndpoint() { var message1 = new Message(TelemetryMessageSource.Instance, new byte[] { 1, 2, 3 }, new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } }); var retryStrategy = new FixedInterval(10, TimeSpan.FromSeconds(1)); TimeSpan revivePeriod = TimeSpan.FromHours(1); TimeSpan execTimeout = TimeSpan.FromSeconds(60); var config = new EndpointExecutorConfig(execTimeout, retryStrategy, revivePeriod, true); var factory = new SyncEndpointExecutorFactory(config); var endpoint = new FailedEndpoint("endpoint1"); var endpoints = new HashSet <Endpoint> { endpoint }; var route = new Route("route1", "true", "hub", TelemetryMessageSource.Instance, endpoints); using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1))) using (Router router = await Router.CreateAsync("router1", "hub", new RouterConfig(endpoints, new HashSet <Route> { route }, Fallback), factory)) { // Because the buffer size is one and we are failing we should block on the dispatch Task routing = router.RouteAsync(message1); var endpoint2 = new TestEndpoint("endpoint1"); var newRoute = new Route("id", "true", "hub", TelemetryMessageSource.Instance, new HashSet <Endpoint> { endpoint2 }); Task setting = router.SetRoute(newRoute); Task timeout = Task.Delay(TimeSpan.FromSeconds(1), cts.Token); await Task.WhenAny(routing, setting, timeout); await router.CloseAsync(CancellationToken.None); var expected = new List <IMessage> { message1 }; Assert.Equal(expected, endpoint2.Processed); } }
public async Task TestFailedEndpoint() { var retryStrategy = new FixedInterval(10, TimeSpan.FromSeconds(1)); TimeSpan revivePeriod = TimeSpan.FromHours(1); TimeSpan execTimeout = TimeSpan.FromSeconds(60); var config = new EndpointExecutorConfig(execTimeout, retryStrategy, revivePeriod, true); var factory = new SyncEndpointExecutorFactory(config); var endpoint = new FailedEndpoint("endpoint1"); var endpoints = new Dictionary <Endpoint, IList <uint> > { { endpoint, new List <uint>() { 0 } } }; using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1))) { Dispatcher dispatcher = await Dispatcher.CreateAsync("dispatcher", "hub", endpoints, factory); // Because the buffer size is one and we are failing we should block on the dispatch Task dispatching = dispatcher.DispatchAsync(Message1, new HashSet <RouteResult> { new RouteResult(endpoint, 0, 3600) }); var endpoint2 = new TestEndpoint("endpoint1"); Task setting = dispatcher.SetEndpoint(endpoint2, new List <uint>() { 0 }); Task timeout = Task.Delay(TimeSpan.FromSeconds(1), cts.Token); await Task.WhenAny(dispatching, setting, timeout); await dispatcher.CloseAsync(CancellationToken.None); var expected = new List <IMessage> { Message1 }; Assert.Equal(expected, endpoint2.Processed); } }