Esempio n. 1
0
        public void InitializationWithStaticConnectionPoolShouldSucceed()
        {
            ElasticClientManager.Initialize(new List <string> {
                string.Format(_testEndpoint, _testUsername, _testPassword)
            },
                                            _testIndex,
                                            null,
                                            ConnectionPool.Static);

            var testClient = ElasticClientManager.GetInstance(_testIndex);

            Assert.IsType <StaticConnectionPool>(testClient.ConnectionSettings.ConnectionPool);
        }
Esempio n. 2
0
        public void InitializationWithCertificateSucceed()
        {
            var config = new ConnectionConfig {
                ClientCerfificate = new X509Certificate()
            };

            ElasticClientManager.Initialize(new List <string> {
                string.Format(_testEndpoint, _testUsername, _testPassword)
            },
                                            _testIndex,
                                            config);

            var testClient = ElasticClientManager.GetInstance(_testIndex);

            Assert.IsType <SingleNodeConnectionPool>(testClient.ConnectionSettings.ConnectionPool);
            Assert.Contains(config.ClientCerfificate, testClient.ConnectionSettings.ClientCertificates.Cast <X509Certificate>().ToList());
        }
Esempio n. 3
0
        public void InitializationWithSettingsSucceed()
        {
            var config = new ConnectionConfig {
                BasicAuthenticationUsername = "******",
                BasicAuthenticationPassword = "******",
                ConnectionLimit             = 80,
                DeadTimeout = TimeSpan.FromMilliseconds(1000),
                DisableAutomaticProxyDetection = true,
                DisablePings          = true,
                EnableDebugMode       = true,
                EnableHttpCompression = true,
                EnableHttpPipelining  = false,
                KeepAliveTime         = TimeSpan.FromMilliseconds(2000),
                KeepAliveInterval     = TimeSpan.FromMilliseconds(2000),
                Headers = new NameValueCollection {
                    { "test", "" }
                },
                QueryStringParameters = new NameValueCollection {
                    { "test", "" }
                },
                MaxDeadTimeout                      = TimeSpan.FromMilliseconds(1000),
                MaxRetries                          = 10,
                MaxRetryTimeout                     = TimeSpan.FromMinutes(2),
                NodePredicate                       = x => x.MasterOnlyNode,
                RequestCompletedHandler             = delegate { },
                RequestDataCreatedHandler           = delegate { },
                PingTimeout                         = TimeSpan.FromMilliseconds(1000),
                ProxyAddress                        = "http://localhost:8080/",
                ProxyUsername                       = "******",
                ProxyPassword                       = "******",
                RequestTimeout                      = TimeSpan.FromMinutes(2),
                ServerCertificateValidationCallback = delegate { return(false); },
                SniffLifeSpan                       = TimeSpan.FromHours(1),
                SniffsOnConnectionFault             = false,
                SniffsOnStartup                     = false,
                ThrowExceptions                     = true
            };

            ElasticClientManager.Initialize(new List <string> {
                string.Format(_testEndpoint, _testUsername, _testPassword)
            },
                                            _testIndex,
                                            config);

            var testClient = ElasticClientManager.GetInstance(_testIndex);

            Assert.IsType <SingleNodeConnectionPool>(testClient.ConnectionSettings.ConnectionPool);
            Assert.Equal(config.ConnectionLimit, testClient.ConnectionSettings.ConnectionLimit);
            Assert.Equal(config.DeadTimeout, testClient.ConnectionSettings.DeadTimeout);
            Assert.True(testClient.ConnectionSettings.DisableAutomaticProxyDetection);
            Assert.True(testClient.ConnectionSettings.DisableDirectStreaming);
            Assert.True(testClient.ConnectionSettings.DisablePings);
            Assert.True(testClient.ConnectionSettings.EnableHttpCompression);
            Assert.False(testClient.ConnectionSettings.HttpPipeliningEnabled);
            Assert.Equal(config.KeepAliveTime, testClient.ConnectionSettings.KeepAliveTime);
            Assert.Equal(config.KeepAliveInterval, testClient.ConnectionSettings.KeepAliveInterval);
            Assert.Equal(new NameValueCollection {
                { "test", "" }
            }, testClient.ConnectionSettings.Headers);
            Assert.Equal(new NameValueCollection {
                { "pretty", "" }, { "test", "" }
            }, testClient.ConnectionSettings.QueryStringParameters);
            Assert.Equal(config.MaxDeadTimeout, testClient.ConnectionSettings.MaxDeadTimeout);
            Assert.Equal(config.MaxRetries, testClient.ConnectionSettings.MaxRetries);
            Assert.Equal(config.MaxRetryTimeout, testClient.ConnectionSettings.MaxRetryTimeout);
            Assert.True(testClient.ConnectionSettings.PrettyJson);
            Assert.Equal(config.NodePredicate, testClient.ConnectionSettings.NodePredicate);
            Assert.NotNull(testClient.ConnectionSettings.OnRequestCompleted);
            Assert.NotNull(testClient.ConnectionSettings.OnRequestDataCreated);
            Assert.Equal(config.PingTimeout, testClient.ConnectionSettings.PingTimeout);
            Assert.Equal(config.ProxyAddress, testClient.ConnectionSettings.ProxyAddress);
            Assert.Equal(config.ProxyUsername, testClient.ConnectionSettings.ProxyUsername);
            Assert.Equal(config.ProxyPassword, testClient.ConnectionSettings.ProxyPassword);
            Assert.Equal(config.RequestTimeout, testClient.ConnectionSettings.RequestTimeout);
            Assert.Equal(config.ServerCertificateValidationCallback, testClient.ConnectionSettings.ServerCertificateValidationCallback);
            Assert.Equal(config.SniffLifeSpan, testClient.ConnectionSettings.SniffInformationLifeSpan);
            Assert.False(testClient.ConnectionSettings.SniffsOnConnectionFault);
            Assert.False(testClient.ConnectionSettings.SniffsOnStartup);
            Assert.True(testClient.ConnectionSettings.ThrowExceptions);
        }
Esempio n. 4
0
 public void InitializationWithoutEndpointsShouldThrow() => Assert.Throws <ArgumentException>(
     delegate { ElasticClientManager.Initialize(null, _testIndex); });