コード例 #1
0
        public async Task TestSetEndpoint()
        {
            var endpoint1 = new TestEndpoint("id1");
            var endpoint2 = new TestEndpoint("id1");
            var endpoint3 = new TestEndpoint("id3");
            IEndpointExecutor executor = await Factory.CreateAsync(endpoint1);

            Assert.Equal(new List <IMessage>(), endpoint1.Processed);
            Assert.Equal(new List <IMessage>(), endpoint2.Processed);
            Assert.Equal(new List <IMessage>(), endpoint3.Processed);
            await Assert.ThrowsAsync <ArgumentException>(() => executor.SetEndpoint(endpoint3));

            await executor.Invoke(Message1);

            await executor.Invoke(Message1);

            Assert.Equal(new List <IMessage> {
                Message1, Message1
            }, endpoint1.Processed);
            Assert.Equal(new List <IMessage>(), endpoint2.Processed);
            Assert.Equal(new List <IMessage>(), endpoint3.Processed);

            await executor.SetEndpoint(endpoint2);

            Assert.Equal(new List <IMessage> {
                Message1, Message1
            }, endpoint1.Processed);
            Assert.Equal(new List <IMessage>(), endpoint2.Processed);
            Assert.Equal(new List <IMessage>(), endpoint3.Processed);

            await executor.Invoke(Message2);

            await executor.Invoke(Message3);

            Assert.Equal(new List <IMessage> {
                Message1, Message1
            }, endpoint1.Processed);
            Assert.Equal(new List <IMessage> {
                Message2, Message3
            }, endpoint2.Processed);
            Assert.Equal(new List <IMessage>(), endpoint3.Processed);

            await executor.CloseAsync();
        }
コード例 #2
0
        public async Task TestClose()
        {
            var endpoint = new TestEndpoint("id");
            IEndpointExecutor executor = await Factory.CreateAsync(endpoint);

            Task running = executor.Invoke(Default);

            await executor.CloseAsync();

            await running;

            Assert.True(running.IsCompleted);

            // ensure this doesn't throw
            await executor.CloseAsync();

            await Assert.ThrowsAsync <InvalidOperationException>(() => executor.Invoke(Default));

            await Assert.ThrowsAsync <InvalidOperationException>(() => executor.SetEndpoint(endpoint));
        }
コード例 #3
0
        public async Task TestCancellation()
        {
            var endpoint = new StalledEndpoint("id");
            IEndpointExecutor executor = await Factory.CreateAsync(endpoint, null);

            Task running = executor.Invoke(Default, 0, 3600);

            await executor.CloseAsync();

            await running;

            Assert.True(running.IsCompleted);
        }
コード例 #4
0
 async Task DispatchInternal(IEndpointExecutor exec, IMessage message)
 {
     try
     {
         await exec.Invoke(message);
     }
     catch (Exception ex) when(ex is InvalidOperationException || ex is OperationCanceledException)
     {
         // disabled
         // Executor is closed, ignore the send
         // TODO add logging?
     }
 }
コード例 #5
0
        public async Task TestClose()
        {
            var endpoint = new TestEndpoint("id");
            IEndpointExecutor executor = await Factory.CreateAsync(endpoint, null);

            Task running = executor.Invoke(Default, 0, 3600);

            await executor.CloseAsync();

            await running;

            Assert.True(running.IsCompleted);

            // ensure this doesn't throw
            await executor.CloseAsync();
        }