예제 #1
0
        public void Setup()
        {
            _capturedEvents = new EventCapturer();
            _streamFactory  = Substitute.For <IStreamFactory>();

            _endPoint = new DnsEndPoint("localhost", 27017);
            var serverId = new ServerId(new ClusterId(), _endPoint);

            _connectionInitializer = Substitute.For <IConnectionInitializer>();
            _connectionInitializer.InitializeConnection(null, CancellationToken.None)
            .ReturnsForAnyArgs(new ConnectionDescription(
                                   new ConnectionId(serverId),
                                   new IsMasterResult(new BsonDocument()),
                                   new BuildInfoResult(new BsonDocument("version", "2.6.3"))));
            _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
            .ReturnsForAnyArgs(Task.FromResult(new ConnectionDescription(
                                                   new ConnectionId(serverId),
                                                   new IsMasterResult(new BsonDocument()),
                                                   new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _streamFactory,
                connectionInitializer: _connectionInitializer,
                eventSubscriber: _capturedEvents);
        }
예제 #2
0
        // constructors
        public BinaryConnection(ServerId serverId, EndPoint endPoint, ConnectionSettings settings, IStreamFactory streamFactory, IConnectionInitializer connectionInitializer, IEventSubscriber eventSubscriber)
        {
            Ensure.IsNotNull(serverId, "serverId");
            _endPoint              = Ensure.IsNotNull(endPoint, "endPoint");
            _settings              = Ensure.IsNotNull(settings, "settings");
            _streamFactory         = Ensure.IsNotNull(streamFactory, "streamFactory");
            _connectionInitializer = Ensure.IsNotNull(connectionInitializer, "connectionInitializer");
            Ensure.IsNotNull(eventSubscriber, "eventSubscriber");

            _backgroundTaskCancellationTokenSource = new CancellationTokenSource();
            _backgroundTaskCancellationToken       = _backgroundTaskCancellationTokenSource.Token;

            _connectionId       = new ConnectionId(serverId);
            _receiveCoordinator = new ReceiveCoordinator();
            _sendLock           = new SemaphoreSlim(1);
            _state = new InterlockedInt32(State.Initial);

            eventSubscriber.TryGetEventHandler(out _failedEventHandler);
            eventSubscriber.TryGetEventHandler(out _closingEventHandler);
            eventSubscriber.TryGetEventHandler(out _closedEventHandler);
            eventSubscriber.TryGetEventHandler(out _openingEventHandler);
            eventSubscriber.TryGetEventHandler(out _openedEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedOpeningEventHandler);
            eventSubscriber.TryGetEventHandler(out _receivingMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _receivedMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedReceivingMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _sendingMessagesEventHandler);
            eventSubscriber.TryGetEventHandler(out _sentMessagesEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedSendingMessagesEvent);
        }
        public void Setup()
        {
            _capturedEvents = new EventCapturer()
                .Capture<CommandStartedEvent>()
                .Capture<CommandSucceededEvent>()
                .Capture<CommandFailedEvent>();

            _streamFactory = Substitute.For<IStreamFactory>();

            _endPoint = new DnsEndPoint("localhost", 27017);
            var serverId = new ServerId(new ClusterId(), _endPoint);

            _connectionInitializer = Substitute.For<IConnectionInitializer>();
            _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
                .ReturnsForAnyArgs(Task.FromResult(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _streamFactory,
                connectionInitializer: _connectionInitializer,
                eventSubscriber: _capturedEvents);

            _stream = new BlockingMemoryStream();
            _streamFactory.CreateStreamAsync(null, CancellationToken.None)
                .ReturnsForAnyArgs(Task.FromResult<Stream>(_stream));
            _subject.OpenAsync(CancellationToken.None).Wait();
            _capturedEvents.Clear();

            _operationIdDisposer = EventContext.BeginOperation();
        }
예제 #4
0
        private ChannelConnectionPool CreatePool(IConnectionInitializer connectionInitializer = null,
                                                 IConnectionFactory connectionFactory         = null)
        {
            if (connectionInitializer == null)
            {
                var connectionInitializerMock = new Mock <IConnectionInitializer>();
                connectionInitializerMock
                .SetupGet(m => m.EndPoint)
                .Returns(_ipEndPoint);

                connectionInitializer = connectionInitializerMock.Object;
            }

            if (connectionFactory == null)
            {
                var connectionFactoryMock = new Mock <IConnectionFactory>();
                connectionFactoryMock
                .Setup(m => m.CreateAndConnectAsync(_ipEndPoint, It.IsAny <CancellationToken>()))
                .ReturnsAsync(() => new Mock <IConnection>().Object);

                connectionFactory = connectionFactoryMock.Object;
            }

            return(new ChannelConnectionPool(connectionInitializer, connectionFactory,
                                             new Mock <IConnectionPoolScaleController>().Object,
                                             new Mock <IRedactor>().Object,
                                             new Logger(_testOutput),
                                             (int)new ClusterOptions().KvSendQueueCapacity));
        }
 // constructors
 public BinaryConnectionFactory(ConnectionSettings settings, IStreamFactory streamFactory, IEventSubscriber eventSubscriber)
 {
     _settings = Ensure.IsNotNull(settings, nameof(settings));
     _streamFactory = Ensure.IsNotNull(streamFactory, nameof(streamFactory));
     _eventSubscriber = Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));
     _connectionInitializer = new ConnectionInitializer(settings.ApplicationName);
 }
        // constructors
        public BinaryConnection(ServerId serverId, EndPoint endPoint, ConnectionSettings settings, IStreamFactory streamFactory, IConnectionInitializer connectionInitializer, IEventSubscriber eventSubscriber)
        {
            Ensure.IsNotNull(serverId, nameof(serverId));
            _endPoint = Ensure.IsNotNull(endPoint, nameof(endPoint));
            _settings = Ensure.IsNotNull(settings, nameof(settings));
            _streamFactory = Ensure.IsNotNull(streamFactory, nameof(streamFactory));
            _connectionInitializer = Ensure.IsNotNull(connectionInitializer, nameof(connectionInitializer));
            Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));

            _backgroundTaskCancellationTokenSource = new CancellationTokenSource();
            _backgroundTaskCancellationToken = _backgroundTaskCancellationTokenSource.Token;

            _connectionId = new ConnectionId(serverId);
            _receiveLock = new SemaphoreSlim(1);
            _sendLock = new SemaphoreSlim(1);
            _state = new InterlockedInt32(State.Initial);

            _commandEventHelper = new CommandEventHelper(eventSubscriber);
            eventSubscriber.TryGetEventHandler(out _failedEventHandler);
            eventSubscriber.TryGetEventHandler(out _closingEventHandler);
            eventSubscriber.TryGetEventHandler(out _closedEventHandler);
            eventSubscriber.TryGetEventHandler(out _openingEventHandler);
            eventSubscriber.TryGetEventHandler(out _openedEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedOpeningEventHandler);
            eventSubscriber.TryGetEventHandler(out _receivingMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _receivedMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedReceivingMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _sendingMessagesEventHandler);
            eventSubscriber.TryGetEventHandler(out _sentMessagesEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedSendingMessagesEvent);
        }
        public void Setup()
        {
            _capturedEvents = new EventCapturer()
                              .Capture <CommandStartedEvent>()
                              .Capture <CommandSucceededEvent>()
                              .Capture <CommandFailedEvent>();

            _streamFactory = Substitute.For <IStreamFactory>();

            _endPoint = new DnsEndPoint("localhost", 27017);
            var serverId = new ServerId(new ClusterId(), _endPoint);

            _connectionInitializer = Substitute.For <IConnectionInitializer>();
            _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
            .ReturnsForAnyArgs(Task.FromResult(new ConnectionDescription(
                                                   new ConnectionId(serverId),
                                                   new IsMasterResult(new BsonDocument()),
                                                   new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _streamFactory,
                connectionInitializer: _connectionInitializer,
                eventSubscriber: _capturedEvents);

            _stream = new BlockingMemoryStream();
            _streamFactory.CreateStreamAsync(null, CancellationToken.None)
            .ReturnsForAnyArgs(Task.FromResult <Stream>(_stream));
            _subject.OpenAsync(CancellationToken.None).Wait();
            _capturedEvents.Clear();

            _operationIdDisposer = EventContext.BeginOperation();
        }
        public void Setup()
        {
            _capturedEvents = new EventCapturer();
            _streamFactory = Substitute.For<IStreamFactory>();

            _endPoint = new DnsEndPoint("localhost", 27017);
            var serverId = new ServerId(new ClusterId(), _endPoint);

            _connectionInitializer = Substitute.For<IConnectionInitializer>();
            _connectionInitializer.InitializeConnection(null, CancellationToken.None)
                .ReturnsForAnyArgs(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3"))));
            _connectionInitializer.InitializeConnectionAsync(null, CancellationToken.None)
                .ReturnsForAnyArgs(Task.FromResult(new ConnectionDescription(
                    new ConnectionId(serverId),
                    new IsMasterResult(new BsonDocument()),
                    new BuildInfoResult(new BsonDocument("version", "2.6.3")))));

            _subject = new BinaryConnection(
                serverId: serverId,
                endPoint: _endPoint,
                settings: new ConnectionSettings(),
                streamFactory: _streamFactory,
                connectionInitializer: _connectionInitializer,
                eventSubscriber: _capturedEvents);
        }
예제 #9
0
 // constructors
 public BinaryConnectionFactory(ConnectionSettings settings, IStreamFactory streamFactory, IEventSubscriber eventSubscriber)
 {
     _settings              = Ensure.IsNotNull(settings, nameof(settings));
     _streamFactory         = Ensure.IsNotNull(streamFactory, nameof(streamFactory));
     _eventSubscriber       = Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));
     _connectionInitializer = new ConnectionInitializer(settings.ApplicationName, settings.Compressors);
 }
        // constructors
        public BinaryConnection(ServerId serverId, EndPoint endPoint, ConnectionSettings settings, IStreamFactory streamFactory, IConnectionInitializer connectionInitializer, IEventSubscriber eventSubscriber)
        {
            Ensure.IsNotNull(serverId, nameof(serverId));
            _endPoint              = Ensure.IsNotNull(endPoint, nameof(endPoint));
            _settings              = Ensure.IsNotNull(settings, nameof(settings));
            _streamFactory         = Ensure.IsNotNull(streamFactory, nameof(streamFactory));
            _connectionInitializer = Ensure.IsNotNull(connectionInitializer, nameof(connectionInitializer));
            Ensure.IsNotNull(eventSubscriber, nameof(eventSubscriber));

            _connectionId = new ConnectionId(serverId);
            _receiveLock  = new SemaphoreSlim(1);
            _sendLock     = new SemaphoreSlim(1);
            _state        = new InterlockedInt32(State.Initial);

            _commandEventHelper = new CommandEventHelper(eventSubscriber);
            eventSubscriber.TryGetEventHandler(out _failedEventHandler);
            eventSubscriber.TryGetEventHandler(out _closingEventHandler);
            eventSubscriber.TryGetEventHandler(out _closedEventHandler);
            eventSubscriber.TryGetEventHandler(out _openingEventHandler);
            eventSubscriber.TryGetEventHandler(out _openedEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedOpeningEventHandler);
            eventSubscriber.TryGetEventHandler(out _receivingMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _receivedMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedReceivingMessageEventHandler);
            eventSubscriber.TryGetEventHandler(out _sendingMessagesEventHandler);
            eventSubscriber.TryGetEventHandler(out _sentMessagesEventHandler);
            eventSubscriber.TryGetEventHandler(out _failedSendingMessagesEvent);

            _compressorSource = new CompressorSource(settings.Compressors);
        }
        /// <summary>
        /// Initializes the TCP socket and binds it to the appropriate local network interface
        /// </summary>
        /// <param name="parameters"></param>
        public void Initialize(IConnectionInitializer parameters)
        {
            var tcpConnection = (TcpInitialization)parameters;

            host      = tcpConnection.Host;
            port      = tcpConnection.Port;
            tcpClient = new TcpClient(tcpConnection.LocalEndpoint);
        }
예제 #12
0
 public AuthenticateConnectionInitializer(
     IConnectionInitializer connectionInitializer,
     ITokenAuthenticationService tokenAuthenticationService,
     IConnectedClientContext connectedClientContext)
 {
     _connectionInitializer      = connectionInitializer;
     _tokenAuthenticationService = tokenAuthenticationService;
     _connectedClientContext     = connectedClientContext;
 }
예제 #13
0
 public ConnectionInfo(ServerConnection connection, ushort administrationId, IClientInfo clientInfo,
                       IConnectionInitializer connectionInitializer)
 {
     ServerConnection      = connection;
     AdministrationId      = administrationId;
     _sendLock             = connection.SendLock;
     ClientInfo            = clientInfo;
     ConnectionInitializer = connectionInitializer;
 }
예제 #14
0
 public ConnectionHandler(
     ILogger <ConnectionHandler> logger,
     IConnectionInitializer connectionInitializer,
     IConnectedClientStore connectedClients,
     IMessageDispatcher messageDispatcher,
     IUpdateDetector updateDetector,
     IUpdater updater)
 {
     _logger = logger;
     _connectionInitializer = connectionInitializer;
     _connectedClients      = connectedClients;
     _messageDispatcher     = messageDispatcher;
     _updateDetector        = updateDetector;
     _updater = updater;
 }
        // constructors
        public BinaryConnection(ServerId serverId, EndPoint endPoint, ConnectionSettings settings, IStreamFactory streamFactory, IConnectionInitializer connectionInitializer, IConnectionListener listener)
        {
            Ensure.IsNotNull(serverId, "serverId");
            _endPoint              = Ensure.IsNotNull(endPoint, "endPoint");
            _settings              = Ensure.IsNotNull(settings, "settings");
            _streamFactory         = Ensure.IsNotNull(streamFactory, "streamFactory");
            _connectionInitializer = Ensure.IsNotNull(connectionInitializer, "connectionInitializer");
            _listener              = listener;

            _backgroundTaskCancellationTokenSource = new CancellationTokenSource();

            _connectionId   = new ConnectionId(serverId);
            _inboundDropbox = new AsyncDropbox <int, IByteBuffer>();
            _outboundQueue  = new AsyncQueue <OutboundQueueEntry>();
            _state          = new InterlockedInt32(State.Initial);
        }
        // constructors
        public BinaryConnection(ServerId serverId, EndPoint endPoint, ConnectionSettings settings, IStreamFactory streamFactory, IConnectionInitializer connectionInitializer, IConnectionListener listener)
        {
            Ensure.IsNotNull(serverId, "serverId");
            _endPoint              = Ensure.IsNotNull(endPoint, "endPoint");
            _settings              = Ensure.IsNotNull(settings, "settings");
            _streamFactory         = Ensure.IsNotNull(streamFactory, "streamFactory");
            _connectionInitializer = Ensure.IsNotNull(connectionInitializer, "connectionInitializer");
            _listener              = listener;

            _backgroundTaskCancellationTokenSource = new CancellationTokenSource();
            _backgroundTaskCancellationToken       = _backgroundTaskCancellationTokenSource.Token;

            _connectionId       = new ConnectionId(serverId);
            _receiveCoordinator = new ReceiveCoordinator();
            _sendLock           = new SemaphoreSlim(1);
            _state = new InterlockedInt32(State.Initial);
        }
예제 #17
0
 public ConnectionHandler(
     ILogger <ConnectionHandler> logger,
     IConnectionInitializer connectionInitializer,
     IConnectedClientStore connectedClients,
     IMessageDispatcher messageDispatcher,
     IQueryDispatcher queryDispatcher,
     IUpdateDetector updateDetector,
     IMessageTypeCache messageTypeCache,
     IEnumerable <IConnectedClientInitializer> connectedClientInitializers,
     IUpdater updater)
 {
     _logger = logger;
     _connectionInitializer       = connectionInitializer;
     _connectedClients            = connectedClients;
     _messageDispatcher           = messageDispatcher;
     _queryDispatcher             = queryDispatcher;
     _updateDetector              = updateDetector;
     _messageTypeCache            = messageTypeCache;
     _connectedClientInitializers = connectedClientInitializers;
     _updater = updater;
 }
 public StoppableDataFlowConnectionPool(IConnectionInitializer connectionInitializer, IConnectionFactory connectionFactory,
                                        IConnectionPoolScaleController scaleController, IRedactor redactor, ILogger <DataFlowConnectionPool> logger,
                                        uint kvSendQueueCapacity) : base(connectionInitializer, connectionFactory, scaleController, redactor, logger, kvSendQueueCapacity)
 {
 }
 // static constructor
 static BinaryConnectionFactory()
 {
     __connectionInitializer = new ConnectionInitializer();
 }
예제 #20
0
 protected ConnectionPoolBase(IConnectionInitializer connectionInitializer,
                              IConnectionFactory connectionFactory)
 {
     _connectionInitializer = connectionInitializer ?? throw new ArgumentNullException(nameof(connectionInitializer));
     _connectionFactory     = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
 }
예제 #21
0
 public void Initialize(IConnectionInitializer parameters)
 {
 }
예제 #22
0
 public DatabaseContext(IConnectionInitializer connectionInitializer)
 {
     this._connectionInitializer = connectionInitializer;
 }
 // static constructor
 static BinaryConnectionFactory()
 {
     __connectionInitializer = new ConnectionInitializer();
 }