コード例 #1
0
        public async Task TestContainerWithOneEndpointWithAllConnectedSucceeeds()
        {
            var sem    = new TestServiceEndpointManager(new ServiceEndpoint(ConnectionString1));
            var throws = new ServiceConnectionNotActiveException();
            var router = new TestEndpointRouter(throws);

            var writeTcs = new TaskCompletionSource <object>();
            TestBaseServiceConnectionContainer innerContainer = null;
            var container = new MultiEndpointServiceConnectionContainer("hub",
                                                                        e => innerContainer = new TestBaseServiceConnectionContainer(new List <IServiceConnection> {
                new TestSimpleServiceConnection(writeAsyncTcs: writeTcs),
                new TestSimpleServiceConnection(writeAsyncTcs: writeTcs),
                new TestSimpleServiceConnection(writeAsyncTcs: writeTcs),
                new TestSimpleServiceConnection(writeAsyncTcs: writeTcs),
                new TestSimpleServiceConnection(writeAsyncTcs: writeTcs),
                new TestSimpleServiceConnection(writeAsyncTcs: writeTcs),
                new TestSimpleServiceConnection(writeAsyncTcs: writeTcs),
            }, e), sem, router, null);

            // All the connections started
            _ = container.StartAsync();
            await container.ConnectionInitializedTask;

            var task = container.WriteAckableMessageAsync(DefaultGroupMessage);
            await writeTcs.Task.OrTimeout();

            innerContainer.HandleAck(new AckMessage(1, (int)AckStatus.Ok));
            await task.OrTimeout();
        }
コード例 #2
0
        public async Task TestContainerWithOneEndpointWithAllConnectedSucceeeds()
        {
            var sem       = new TestServiceEndpointManager(new ServiceEndpoint(ConnectionString1));
            var throws    = new ServiceConnectionNotActiveException();
            var router    = new TestEndpointRouter(throws);
            var container = new MultiEndpointServiceConnectionContainer(
                e => new TestBaseServiceConnectionContainer(new List <IServiceConnection> {
                new TestServiceConnection(),
                new TestServiceConnection(),
                new TestServiceConnection(),
                new TestServiceConnection(),
                new TestServiceConnection(),
                new TestServiceConnection(),
                new TestServiceConnection(),
            }, e), sem, router, null);
            await container.WriteAsync(DefaultGroupMessage);

            await container.WriteAsync("1", DefaultGroupMessage);
        }
コード例 #3
0
        public async Task TestContainerWithBadRouterThrows()
        {
            var sem       = new TestServiceEndpointManager(new ServiceEndpoint(ConnectionString1));
            var throws    = new ServiceConnectionNotActiveException();
            var router    = new TestEndpointRouter(throws);
            var container = new MultiEndpointServiceConnectionContainer("hub",
                                                                        e => new TestBaseServiceConnectionContainer(new List <IServiceConnection> {
                new TestSimpleServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestSimpleServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestSimpleServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestSimpleServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestSimpleServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestSimpleServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestSimpleServiceConnection(ServiceConnectionStatus.Disconnected),
            }, e), sem, router, null);

            // All the connections started
            _ = container.StartAsync();
            await container.ConnectionInitializedTask;

            await Assert.ThrowsAsync(throws.GetType(),
                                     () => container.WriteAsync(DefaultGroupMessage)
                                     );
        }
コード例 #4
0
        public async Task TestContainerWithOneEndpointWithAllDisconnectedAndConnectionStartedThrows()
        {
            var sem       = new TestServiceEndpointManager(new ServiceEndpoint(ConnectionString1));
            var throws    = new ServiceConnectionNotActiveException();
            var router    = new TestEndpointRouter(throws);
            var container = new MultiEndpointServiceConnectionContainer(
                e => new TestBaseServiceConnectionContainer(new List <IServiceConnection> {
                new TestServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestServiceConnection(ServiceConnectionStatus.Disconnected),
                new TestServiceConnection(ServiceConnectionStatus.Disconnected),
            }, e), sem, router, null);

            await Assert.ThrowsAsync(throws.GetType(),
                                     () => container.WriteAsync(DefaultGroupMessage)
                                     );

            await Assert.ThrowsAsync(throws.GetType(),
                                     () => container.WriteAsync("1", DefaultGroupMessage)
                                     );
        }