public async Task CloseAsyncWillCallCloseAsyncOfAllFsmsTest() { var endpoint = new TestEndpoint("endpoint1"); endpoint.CanProcess = false; var storingAsyncEndpointExecutor = new StoringAsyncEndpointExecutor( endpoint, new NullCheckpointerFactory(), new EndpointExecutorConfig(TimeSpan.FromHours(1), RetryStrategy.DefaultFixed, TimeSpan.FromHours(1)), new AsyncEndpointExecutorOptions(10, TimeSpan.FromMilliseconds(1)), new TestMessageStore()); await storingAsyncEndpointExecutor.UpdatePriorities(new List <uint>() { 0 }, Option.None <Endpoint>()); var message = GetNewMessages(1, 0).First(); await storingAsyncEndpointExecutor.Invoke(message, 0, 3600); // await Task.Delay(1000); Assert.Equal(0, endpoint.N); Task closeTask = storingAsyncEndpointExecutor.CloseAsync(); Task timeoutTask = Task.Delay(5000); var firstCompletedTask = await Task.WhenAny(closeTask, timeoutTask); Assert.True(firstCompletedTask == closeTask, "storingAsyncEndpointExecutor can't close when processing a message"); }
public async Task TestSetEndpoint() { var endpoint1 = new TestEndpoint("id"); var endpoint2 = new NullEndpoint("id"); var endpoint3 = new TestEndpoint("id1"); ICheckpointer checkpointer = await Checkpointer.CreateAsync("cid", new CheckpointStore()); var endpointExecutorConfig = new EndpointExecutorConfig(TimeSpan.FromHours(1), RetryStrategy.NoRetry, TimeSpan.FromHours(1)); var asyncEndpointExecutorOptions = new AsyncEndpointExecutorOptions(1, TimeSpan.FromSeconds(1)); var messageStore = new TestMessageStore(); var executor = new StoringAsyncEndpointExecutor(endpoint1, checkpointer, endpointExecutorConfig, asyncEndpointExecutorOptions, messageStore); Assert.Equal(endpoint1, executor.Endpoint); await Assert.ThrowsAsync <ArgumentNullException>(() => executor.SetEndpoint(null)); await Assert.ThrowsAsync <ArgumentException>(() => executor.SetEndpoint(endpoint3)); await executor.SetEndpoint(endpoint2); Assert.Equal(endpoint2, executor.Endpoint); await executor.CloseAsync(); await Assert.ThrowsAsync <InvalidOperationException>(() => executor.SetEndpoint(endpoint1)); }
public async Task TestSetEndpoint() { var endpoint1 = new TestEndpoint("id"); var endpoint2 = new NullEndpoint("id"); var endpoint3 = new TestEndpoint("id1"); var priorities = new List <uint>() { 100, 101, 102, 0, 1, 2 }; var checkpointerFactory = new NullCheckpointerFactory(); var endpointExecutorConfig = new EndpointExecutorConfig(TimeSpan.FromHours(1), RetryStrategy.NoRetry, TimeSpan.FromHours(1)); var asyncEndpointExecutorOptions = new AsyncEndpointExecutorOptions(1, TimeSpan.FromSeconds(1)); var messageStore = new TestMessageStore(); var executor = new StoringAsyncEndpointExecutor(endpoint1, checkpointerFactory, endpointExecutorConfig, asyncEndpointExecutorOptions, messageStore); await executor.UpdatePriorities(priorities, Option.None <Endpoint>()); Assert.Equal(endpoint1, executor.Endpoint); await Assert.ThrowsAsync <ArgumentNullException>(() => executor.SetEndpoint(null, new List <uint>() { 0 })); await Assert.ThrowsAsync <ArgumentNullException>(() => executor.SetEndpoint(endpoint1, null)); await Assert.ThrowsAsync <ArgumentException>(() => executor.SetEndpoint(endpoint3, new List <uint>() { 0 })); await executor.SetEndpoint(endpoint2, new List <uint>() { 103, 104, 105, 0, 1, 2, 2 }); Assert.Equal(endpoint2, executor.Endpoint); await executor.CloseAsync(); await Assert.ThrowsAsync <InvalidOperationException>(() => executor.SetEndpoint(endpoint1, new List <uint>() { 0 })); }