Example #1
0
        public void When_Connecting_To_Dead_IP_Connection_Fails_After_n_Seconds()
        {
            const int    connectionTimedOut   = 10060;
            const string ipThatDoesNotExist   = "198.0.0.1:11210";
            var          ipEndpoint           = UriExtensions.GetEndPoint(ipThatDoesNotExist);
            var          connectionPoolConfig = new PoolConfiguration
            {
                ConnectTimeout = 1000 //set really low for test
            };
            var connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, ipEndpoint);

            var stopWatch = new Stopwatch();

            try
            {
                stopWatch.Start();
                var connection = connectionPool.Acquire();
            }
            catch (SocketException e)
            {
                Assert.AreEqual(connectionTimedOut, e.ErrorCode);
            }
            finally
            {
                stopWatch.Stop();
                Assert.AreEqual(1.0d, Math.Round((double)stopWatch.Elapsed.Seconds));
            }
        }
Example #2
0
        /// <summary>
        /// Has to be implemented in implementation.
        /// PoolBase will call this to figure out how big a pool should be dependent on the given configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns>The number of pooled objects this pool should support.</returns>
        protected override int GetPoolSize(PoolConfiguration configuration)
        {
            int max = 1000;

            // most if not all messages needs at least one string builder, if multiple targets, they need one or more each.
            return(Math.Min(max, configuration.EstimatedLogEventsPerSecond * 4));
        }
        public void Test_Authenticate(bool isAuthenticated, bool isEncrypted, bool isSigned)
        {
            var endpoint     = IPEndPointExtensions.GetEndPoint(TestConfiguration.Settings.Hostname, 11207);
            var bootstrapUri = new Uri($@"https://{endpoint.Address}:8091/pools");
            var socket       = new Socket(SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(endpoint);

            var poolConfig = new PoolConfiguration {
                UseSsl = true, Uri = bootstrapUri, ClientConfiguration = new ClientConfiguration()
            };
            var sslStream = new Mock <SslStream>(new MemoryStream(), true, new RemoteCertificateValidationCallback(ServerCertificateValidationCallback));

            sslStream.Setup(x => x.IsAuthenticated).Returns(isAuthenticated);
            sslStream.Setup(x => x.IsEncrypted).Returns(isEncrypted);
            sslStream.Setup(x => x.IsSigned).Returns(isSigned);

            var connPool = new Mock <IConnectionPool <IConnection> >();

            connPool.Setup(x => x.Configuration).Returns(poolConfig);
            var conn = new SslConnection(connPool.Object, socket, sslStream.Object, new DefaultConverter(),
                                         new BufferAllocator(1024, 1024));

            if (isAuthenticated && isEncrypted && isSigned)
            {
                Assert.DoesNotThrow(conn.Authenticate);
            }
            else
            {
                Assert.Throws <AuthenticationException>(conn.Authenticate);
            }
        }
Example #4
0
        public void When_Connecting_To_Good_IP_Connection_Succeeds_Before_ConnectTimeout()
        {
            const int connectionTimedOut   = 10060;
            string    ipThatDoesExist      = ConfigurationManager.AppSettings["OperationTestAddress"];
            var       ipEndpoint           = UriExtensions.GetEndPoint(ipThatDoesExist);
            var       connectionPoolConfig = new PoolConfiguration
            {
                ConnectTimeout = 5000 //set really low for test
            };
            var connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, ipEndpoint);

            IConnection connection = null;
            var         stopWatch  = new Stopwatch();

            try
            {
                stopWatch.Start();
                connection = connectionPool.Acquire();
            }
            catch (SocketException e)
            {
                Assert.AreEqual(connectionTimedOut, e.ErrorCode);
            }
            finally
            {
                stopWatch.Stop();
                Assert.IsNotNull(connection);
                Assert.IsTrue(connection.Socket.Connected);
                connection.Dispose();
            }
        }
Example #5
0
 /// <summary>
 /// CTOR for testing/dependency injection.
 /// </summary>
 /// <param name="configuration">The <see cref="PoolConfiguration"/> to use.</param>
 /// <param name="endPoint">The <see cref="IPEndPoint"/> of the Couchbase Server.</param>
 /// <param name="factory">A functory for creating <see cref="IConnection"/> objects./></param>
 public ConnectionPool(PoolConfiguration configuration, IPEndPoint endPoint, Func <ConnectionPool <T>, IByteConverter, T> factory, IByteConverter converter)
 {
     _configuration = configuration;
     _factory       = factory;
     _converter     = converter;
     EndPoint       = endPoint;
 }
        /// <summary>
        /// Implementations of pools can inspect the pool configuration and tweak their configuration based on the new configuration.
        /// Do not copy the configuration to a local variable.
        /// </summary>
        /// <param name="configuration">The new configuration to use.</param>
        protected override void PoolLimitsChanged(PoolConfiguration configuration)
        {
            this.individualArraySize = DefaultIndividualArraySize;

            if (configuration.LoggingConfiguration != null)
            {
                this.numberOfTargets = configuration.LoggingConfiguration.AllTargets.Count;
                InternalLogger.Info("Setting numberOfTargets to be:{0}", this.numberOfTargets);
                int maxQueue = 0;

                for (int x = 0; x < configuration.LoggingConfiguration.AllTargets.Count; x++)
                {
                    var target = configuration.LoggingConfiguration.AllTargets[x] as AsyncTargetWrapper;

                    if (target != null)
                    {
                        if (target.BatchSize > maxQueue)
                        {
                            maxQueue = target.BatchSize;
                        }
                    }
                }
                InternalLogger.Info("Setting individual array size for AsyncContinuationListPool to be:{0}", maxQueue);
                // Set a good default array size to accomodate the highest batchsize of the async targets.
                this.individualArraySize = maxQueue;
            }
        }
        /// <summary>
        /// Has to be implemented in implementation.
        /// PoolBase will call this to figure out how big a pool should be dependent on the given configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns>The number of pooled objects this pool should support.</returns>
        protected override int GetPoolSize(PoolConfiguration configuration)
        {
            var size = this.NumberOfTargets * 100;

            InternalLogger.Info("Setting PoolSize for:{0} to be:{1}", this.GetType().FullName, size.AsString());
            return(size);
        }
Example #8
0
        public void TestFixtureSetUp()
        {
            var ipEndpoint           = UriExtensions.GetEndPoint(_address);
            var connectionPoolConfig = new PoolConfiguration();

            _connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, ipEndpoint);
        }
Example #9
0
        protected override void PoolLimitsChanged(PoolConfiguration configuration)
        {
            this.IndividualArraySize = 100;

            if (configuration.LoggingConfiguration != null)
            {
                this.NumberOfTargets = configuration.LoggingConfiguration.AllTargets.Count;
                InternalLogger.Info("Setting numberOfTargets for:{0} to be:{1}", this.GetType().FullName, this.NumberOfTargets);
                this.MaxQueueSize = 0;

                for (int x = 0; x < configuration.LoggingConfiguration.AllTargets.Count; x++)
                {
                    var target = configuration.LoggingConfiguration.AllTargets[x] as AsyncTargetWrapper;

                    if (target != null)
                    {
                        if (target.BatchSize > this.MaxQueueSize)
                        {
                            this.MaxQueueSize = target.BatchSize;
                        }
                    }
                }

                InternalLogger.Info("Setting individual array size for {0} to be:{1}", this.GetType().FullName, this.MaxQueueSize);

                // Set a good default array size to accomodate the highest batchsize of the async targets.
                this.IndividualArraySize = this.MaxQueueSize;
            }
        }
Example #10
0
 /// <summary>
 /// Sets the initial size of the memory stream, by guessing a good initial size based on the estimated max message size and the number of log events per second.
 /// </summary>
 /// <param name="configuration">The pool configuration.</param>
 private void SetStreamSize(PoolConfiguration configuration)
 {
     this.initialStreamSize = configuration.EstimatedMaxMessageSize * configuration.EstimatedLogEventsPerSecond * 4;
     if (this.initialStreamSize < 0)
     {
         this.initialStreamSize = 16384;
     }
 }
        public void OneTimeSetUp()
        {
            var ipEndpoint           = UriExtensions.GetEndPoint(_address);
            var connectionPoolConfig = new PoolConfiguration();

            _connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, ipEndpoint);
            _ioService      = new PooledIOService(_connectionPool);
        }
Example #12
0
        public void TestFixtureSetUp()
        {
            _endPoint = UriExtensions.GetEndPoint(Address);
            var connectionPoolConfig = new PoolConfiguration();

            _connectionPool = new DefaultConnectionPool(connectionPoolConfig, _endPoint);
            _ioStrategy     = new AwaitableIOStrategy(_connectionPool);
        }
 /// <summary>
 /// CTOR for testing/dependency injection.
 /// </summary>
 /// <param name="configuration">The <see cref="PoolConfiguration"/> to use.</param>
 /// <param name="endPoint">The <see cref="IPEndPoint"/> of the Couchbase Server.</param>
 /// <param name="factory">A functory for creating <see cref="IConnection"/> objects./></param>
 internal ConnectionPool(PoolConfiguration configuration, IPEndPoint endPoint, Func <ConnectionPool <T>, IByteConverter, BufferAllocator, T> factory, IByteConverter converter)
 {
     _configuration   = configuration;
     _factory         = factory;
     _converter       = converter;
     _bufferAllocator = Configuration.BufferAllocator(Configuration);
     EndPoint         = endPoint;
 }
        public void TestFixtureSetUp()
        {
            var ipEndpoint           = UriExtensions.GetEndPoint(Address);
            var connectionPoolConfig = new PoolConfiguration();

            _connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, ipEndpoint);
            _ioStrategy     = new DefaultIOStrategy(_connectionPool);
        }
Example #15
0
 /// <summary>
 /// CTOR for testing/dependency injection.
 /// </summary>
 /// <param name="configuration">The <see cref="PoolConfiguration"/> to use.</param>
 /// <param name="endPoint">The <see cref="IPEndPoint"/> of the Couchbase Server.</param>
 /// <param name="factory">A functory for creating <see cref="IConnection"/> objects./></param>
 /// <param name="converter">The <see cref="IByteConverter"/>that this instance is using.</param>
 internal ConnectionPoolBase(PoolConfiguration configuration, IPEndPoint endPoint, Func <IConnectionPool <T>, IByteConverter, BufferAllocator, T> factory, IByteConverter converter)
 {
     Configuration   = configuration;
     Factory         = factory;
     Converter       = converter;
     BufferAllocator = Configuration.BufferAllocator(Configuration);
     EndPoint        = endPoint;
 }
Example #16
0
        /// <summary>
        /// Implementations of pools can inspect the pool configuration and tweak their configuration based on the new configuration.
        /// Do not copy the configuration to a local variable.
        /// </summary>
        /// <param name="configuration">The new configuration to use.</param>
        protected override void PoolLimitsChanged(PoolConfiguration configuration)
        {
            base.PoolLimitsChanged(configuration);

            // hard coded to 180k to be put into LOH immediately
            // bigger buffers give better performance when converting to bytes, via encoding.
            this.IndividualArraySize = 180000;
        }
Example #17
0
        /// <summary>
        /// Implementations of pools can inspect the pool configuration and tweak their configuration based on the new configuration.
        /// Do not copy the configuration to a local variable.
        /// </summary>
        /// <param name="configuration">The new configuration to use.</param>
        protected override void PoolLimitsChanged(PoolConfiguration configuration)
        {
            base.PoolLimitsChanged(configuration);

            // set array size to be at least 90k to get above 85k elements, so it gets put into LOH immediately
            int min = 90000 * 8;

            this.IndividualArraySize = Math.Max(min, this.MaxQueueSize);
        }
Example #18
0
        public void OneTimeSetUp()
        {
            var ipEndpoint           = UriExtensions.GetEndPoint(_address);
            var connectionPoolConfig = new PoolConfiguration {
                UseSsl = false
            };

            _connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, ipEndpoint);
        }
        public virtual void TestFixtureSetUp()
        {
            EndPoint = UriExtensions.GetEndPoint(Address);
            var connectionPoolConfig = new PoolConfiguration();

            _connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, EndPoint);
            _ioService      = new PooledIOService(_connectionPool);
            Transcoder      = new DefaultTranscoder();
        }
        IConnectionPool CreateConnectionPool(PoolConfiguration poolConfiguration, IPEndPoint endpoint)
        {
            var connectionPool = ConnectionPoolFactory(poolConfiguration, endpoint);

            connectionPool.SaslMechanism = SaslFactory(UserName, Password, connectionPool, Transcoder);
            connectionPool.Initialize();

            return(connectionPool);
        }
        public virtual void TestFixtureSetUp()
        {
            EndPoint = UriExtensions.GetEndPoint(Address);
            var connectionPoolConfig = new PoolConfiguration();

            _connectionPool = new ConnectionPool <EapConnection>(connectionPoolConfig, EndPoint);
            _ioStrategy     = new DefaultIOStrategy(_connectionPool);
            Transcoder      = new DefaultTranscoder(Converter);
        }
Example #22
0
        public void TestFixtureSetUp()
        {
            var ipEndpoint           = UriExtensions.GetEndPoint(Address);
            var connectionPoolConfig = new PoolConfiguration();

            _connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, ipEndpoint);
            _connectionPool.Initialize();
            _ioService = new PooledIOService(_connectionPool, null);
        }
Example #23
0
        public void SetUp()
        {
            var ipEndpoint = UriExtensions.GetEndPoint(_address);
            var factory    = DefaultConnectionFactory.GetGeneric <Connection>();

            _configuration  = new PoolConfiguration(MaxSize, MinSize, WaitTimeout, RecieveTimeout, ShutdownTimeout, SendTimeout, ConnectTimeout, MaxConnectionAcquireCount, BucketName);
            _connectionPool = new ConnectionPool <Connection>(_configuration, ipEndpoint, factory, new DefaultConverter());
            _connectionPool.Initialize();
        }
        public void SetUp()
        {
            var ipEndpoint = UriExtensions.GetEndPoint(Address);
            var factory    = DefaultConnectionFactory.GetDefault();

            _configuration  = new PoolConfiguration(MaxSize, MinSize, WaitTimeout, RecieveTimeout, ShutdownTimeout, SendTimeout);
            _connectionPool = new DefaultConnectionPool(_configuration, ipEndpoint, factory);
            _connectionPool.Initialize();
        }
        /// <summary>
        /// Implementations of pools can inspect the pool configuration and tweak their configuration based on the new configuration.
        /// Do not copy the configuration to a local variable.
        /// </summary>
        /// <param name="configuration">The new configuration to use.</param>
        protected override void PoolLimitsChanged(PoolConfiguration configuration)
        {
            base.PoolLimitsChanged(configuration);

            // set array size to be at least 90k to get above 85k elements, so it gets put into LOH immediately
            int min = 90000;

            this.IndividualArraySize = Math.Max(min, this.MaxQueueSize);
            InternalLogger.Info("Setting IndividualArraySize for:{0} to be:{1}", this.GetType().FullName, this.IndividualArraySize.AsString());
        }
Example #26
0
        /// <summary>
        /// Restarts the pool with the new settings
        /// </summary>
        /// <param name="configuration">The configuration with the new settings.</param>
        private void Restart(PoolConfiguration configuration)
        {
            this.preFill      = configuration.PrefillPools;
            this.autoIncrease = configuration.AutoIncreasePoolSizes;

            this.poolSize = this.GetPoolSize(configuration);
            this.enabled  = configuration.Enabled;

            this.RestartPool(configuration);
        }
Example #27
0
        public void TestFixtureSetUp()
        {
            var ipEndpoint           = UriExtensions.GetEndPoint(_address);
            var connectionPoolConfig = new PoolConfiguration {
                UseSsl = false
            };

            _connectionPool = new ConnectionPool <Connection>(connectionPoolConfig, ipEndpoint);
            _ioService      = new PooledIOService(_connectionPool);
        }
        protected IIOService CreateIOService(PoolConfiguration poolConfiguration, IPEndPoint endpoint)
        {
            var connectionPool = ConnectionPoolFactory(poolConfiguration, endpoint);

            connectionPool.SaslMechanism = SaslFactory(UserName, Password, connectionPool, Transcoder);

            var ioService = IOServiceFactory(connectionPool);

            connectionPool.Initialize();

            return(ioService);
        }
        public void TestFixtureSetUp()
        {
            var ipEndpoint           = UriExtensions.GetEndPoint(Address);
            var connectionPoolConfig = new PoolConfiguration
            {
                UseSsl = true
            };

            _connectionPool = new ConnectionPool <SslConnection>(connectionPoolConfig, ipEndpoint);
            _connectionPool.Initialize();
            _ioStrategy = new DefaultIOStrategy(_connectionPool, null);
        }
        public void TestFixtureSetUp()
        {
            var ipEndpoint           = UriExtensions.GetEndPoint(_address.Replace("11210", "11207"));
            var connectionPoolConfig = new PoolConfiguration
            {
                UseSsl = true
            };

            _connectionPool = new ConnectionPool <SslConnection>(connectionPoolConfig, ipEndpoint);
            _connectionPool.Initialize();
            _ioService = new PooledIOService(_connectionPool, null);
        }
Example #31
0
 internal MemoryManager(PoolConfiguration configuration)
 {
     _configuration = configuration;
 }