public void SendTransportMessageFromClientToServer()
        {
            RunWith10SecTimeout(async() =>
            {
                using (var clientConnection = await _client.ConnectAsync(BrokerWorkingDir))
                    using (var serverConnection = await _server.In.ReadAsync())
                    {
                        var clientSender    = new MessagingSendProcessor(clientConnection, SerializationProvider.GetSerializer());
                        var serverReceiver  = new MessagingReceiveProcessor(serverConnection, SerializationProvider.GetDeserializer(TransportHeaderPool.Instance));
                        var connectionOpen  = new TransportMessage(TransportHeaderPool.Instance.CreateConnectionOpenHeader(UniqueId.Generate()));
                        var connectionClose = new TransportMessage(TransportHeaderPool.Instance.CreateConnectionCloseHeader(CompletionHeader.Completed));
                        await clientSender.Out.WriteAsync(connectionOpen);
                        await clientSender.Out.WriteAsync(connectionClose);
                        clientSender.Out.TryComplete();

                        var received1 = await serverReceiver.In.ReadAsync();
                        var received2 = await serverReceiver.In.ReadAsync();

                        Should.CompleteIn(serverReceiver.In.Completion, Timeout1Sec);
                        received1.Header.ShouldBeAssignableTo <ITransportConnectionOpenHeader>();
                        received2.Header.ShouldBeAssignableTo <ITransportConnectionCloseHeader>();
                    }
            });
        }
Exemple #2
0
        public async ValueTask <ITransportConnection> ConnectAsync(string brokerWorkingDir, CancellationToken cancellationToken)
        {
            var transmissionConnection = await _transmissionClient.ConnectAsync(brokerWorkingDir, cancellationToken).ConfigureAwait(false);

            try
            {
                return(_connectionFactory.Create(transmissionConnection));
            }
            catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested)
            {
                Log.Trace("Connection canceled");
                transmissionConnection.Dispose();
                throw;
            }
            catch (Exception ex)
            {
                Log.Trace("Connection failed: {0}", ex.FormatTypeAndMessage());
                transmissionConnection.Dispose();
                throw;
            }
        }