public void ClientTestWhenThrowExceptionsDisabled()
		{
			var settings = new ConnectionSettings(new Uri("http://doesntexist:9200"));
			var client = new ElasticClient(settings);
			var response = client.RootNodeInfo();
			response.CallDetails.OriginalException.Should().NotBeNull();
			response.CallDetails.ServerError.Should().BeNull();
		}
		public void ClientTestWhenThrowExceptionsEnabled()
		{
			var settings = new ConnectionSettings(new Uri("http://doesntexist:9200"))
				.ThrowExceptions();
			var client = new ElasticClient(settings);
			var exception = Assert.Throws<ElasticsearchClientException>(() => client.RootNodeInfo());
			var inner = exception.InnerException;
			inner.Should().NotBeNull();
		}
Пример #3
0
 protected void Connect(ElasticClient client, ConnectionSettings settings)
 {
     var result = client.RootNodeInfo();
     if (!result.IsValid)
     {
         Console.Error.WriteLine("Could not connect to {0}:\r\n{1}",
             settings.Host, result.ConnectionStatus.Error.OriginalException.Message);
         Console.Read();
     }
 }
Пример #4
0
 protected void Connect(ElasticClient client, ConnectionSettings settings)
 {
     var result = client.RootNodeInfo();
     if (!result.IsValid)
     {
         Console.Error.WriteLine("Could not connect to {0}:\r\n{1}",
             result.ConnectionStatus.RequestUrl, result.ConnectionStatus);
         Console.Read();
     }
 }
Пример #5
0
        public static void Warmup()
        {
            var client = new ElasticClient(connection: new InMemoryConnection());
            var stream = new MemoryStream("{}".Utf8Bytes());

            client.Serializer.Serialize(new SearchDescriptor <object>());
            client.Serializer.Deserialize <SearchDescriptor <object> >(stream);
            var connection = new HttpConnection(new ConnectionSettings());

            client.RootNodeInfo();
            client.Search <object>(s => s.MatchAll().Index("someindex"));
        }
		public void ClientTestWhenThrowExceptionsDisabled()
		{
			var settings = new ConnectionSettings(new Uri("http://doesntexist:9200"));
			var client = new ElasticClient(settings);
			var response = client.RootNodeInfo();
#if DOTNETCORE
			// HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set
			response.CallDetails.OriginalException.Should().BeNull();
#else
			response.CallDetails.OriginalException.Should().NotBeNull();
#endif
			response.CallDetails.ServerError.Should().BeNull();
		}
Пример #7
0
        public void connect_to_unknown_hostname()
        {
            IRootInfoResponse result = null;

            Assert.DoesNotThrow(() =>
            {
                var settings = new ConnectionSettings(new Uri("http://youdontownthis.domain.do.you"), "index");
                var client = new ElasticClient(settings);
                result = client.RootNodeInfo();
            });
            Assert.False(result.IsValid);
            Assert.NotNull(result.ConnectionStatus);
        }
		public void ClientTestWhenThrowExceptionsEnabled()
		{
			var settings = new ConnectionSettings(new Uri("http://doesntexist:9200"))
				.ThrowExceptions();
			var client = new ElasticClient(settings);
			var exception = Assert.Throws<ElasticsearchClientException>(() => client.RootNodeInfo());
			var inner = exception.InnerException;
#if DOTNETCORE
			// HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set
			inner.Should().BeNull();
#else
			inner.Should().NotBeNull();
#endif
		}
		public void StaticConnectionPool_ThrowsAndDoesNotRetry_On_401()
		{
			var nodes = new Uri[] {
				new Uri("http://*****:*****@localhost:9200"),
				new Uri("http://*****:*****@localhost:9201")
			};
			var pool = new StaticConnectionPool(nodes);
			var settings = new ConnectionSettings(pool)
				.ThrowOnElasticsearchServerExceptions()
				.MaximumRetries(3);

			var client = new ElasticClient(settings);
			var e = Assert.Throws<ElasticsearchServerException>(() => client.RootNodeInfo());
			e.Status.Should().Be(401);
		}
Пример #10
0
        public void connect_to_unknown_hostname()
        {
            IRootInfoResponse result = null;

            //this test will fail if fiddler is enabled since the proxy
            //will report a statuscode of 502 instead of -1
            Assert.Throws<MaxRetryException>(() =>
            {
                var settings = new ConnectionSettings(new Uri("http://youdontownthis.domain.do.you"), "index");
                var client = new ElasticClient(settings);
                result = client.RootNodeInfo();
                Assert.False(result.IsValid);
                Assert.NotNull(result.ConnectionStatus);
            });
        }
Пример #11
0
        public void connect_to_unknown_hostname()
        {
            Assert.DoesNotThrow(() =>
            {
                var settings = new ConnectionSettings(new Uri("http://youdontownthis.domain.do.you"));
                var client = new ElasticClient(settings);
                var result = client.RootNodeInfo();

                Assert.False(result.IsValid);
                Assert.NotNull(result.ConnectionStatus);

                Assert.True(result.ConnectionStatus.Error.HttpStatusCode == System.Net.HttpStatusCode.BadGateway
                    || result.ConnectionStatus.Error.ExceptionMessage.StartsWith("The remote name could not be resolved"));
            });
        }
		public void StaticConnectionPool_DoesNotThrowOrRetry_On_401()
		{
			var nodes = new Uri[] {
				new Uri("http://*****:*****@localhost:9200"),
				new Uri("http://*****:*****@localhost:9201")
			};
			var pool = new StaticConnectionPool(nodes);
			var settings = new ConnectionSettings(pool)
				.MaximumRetries(3);
			var client = new ElasticClient(settings);
			var r = client.RootNodeInfo();
			r.IsValid.Should().BeFalse();
			r.ConnectionStatus.HttpStatusCode.Should().Be(401);
			r.ConnectionStatus.Metrics.Requests.Count.Should().Be(1);
			r.ConnectionStatus.Metrics.Requests[0].RequestType.Should().Be(RequestType.Ping);
			r.ConnectionStatus.NumberOfRetries.Should().Be(0);
		}
 public void OnRequestCompletedIsCalled()
 {
     var counter = 0;
     var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
     var settings = new ConnectionSettings(connectionPool, new InMemoryConnection())
         .OnRequestCompleted(r => counter++);
     var client = new ElasticClient(settings);
     client.RootNodeInfo();
     counter.Should().Be(1);
     client.RootNodeInfoAsync();
     counter.Should().Be(2);
 }
		public void Unauthorized_With_Ping_Disabled()
		{
			var nodes = new Uri[] {
				new Uri("http://*****:*****@localhost:9200"),
				new Uri("http://*****:*****@localhost:9201")
			};
			var pool = new StaticConnectionPool(nodes);
			var settings = new ConnectionSettings(pool)
				.MaximumRetries(3)
				.DisablePing();
			var client = new ElasticClient(settings);
			var r = client.RootNodeInfo();
			r.IsValid.Should().BeFalse();
			r.ConnectionStatus.HttpStatusCode.Should().Be(401);
			r.ConnectionStatus.Metrics.Requests.Count.Should().Be(1);
			r.ConnectionStatus.Metrics.Requests[0].RequestType.Should().Be(RequestType.ElasticsearchCall);
			r.ConnectionStatus.NumberOfRetries.Should().Be(0);
		}
Пример #15
0
        public void TestConnectSuccessWithUri()
        {
            var settings = new ConnectionSettings(Test.Default.Uri, "index");
            var client = new ElasticClient(settings);
            var result = client.RootNodeInfo();

            Assert.True(result.IsValid);
            Assert.NotNull(result.ConnectionStatus.HttpStatusCode);
        }
		public void ModifyJsonSerializerSettingsIsCalled()
		{
			var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
			var settings = new ConnectionSettings(connectionPool, new InMemoryConnection(), s => new MyJsonNetSerializer(s));
			var client = new ElasticClient(settings);
			client.RootNodeInfo();
			client.RootNodeInfo();
			var serializer = ((IConnectionSettingsValues)settings).Serializer as MyJsonNetSerializer;
			serializer.X.Should().BeGreaterThan(0);
		}
		public IObservable<ElasticsearchMessage> Start()
		{

			if (!this.RunningIntegrations) return Observable.Empty<ElasticsearchMessage>();

			this.Stop();
			var timeout = TimeSpan.FromSeconds(60);
			var handle = new ManualResetEvent(false);

			if (_doNotSpawnIfAlreadyRunning)
			{
			    var client = new ElasticClient();
			    var alreadyUp = client.RootNodeInfo();
				if (alreadyUp.IsValid)
				{
				    var checkPlugins = client.CatPlugins();

				    if (checkPlugins.IsValid)
				    {
				        foreach (var supportedPlugin in  SupportedPlugins)
				        {
				            if (!checkPlugins.Records.Any(r => r.Component.Equals(supportedPlugin.Key)))
				                throw new ApplicationException($"Already running elasticsearch does not have supported plugin {supportedPlugin.Key} installed.");
				        }

				        this.Started = true;
				        this.Port = 9200;
				        this.Info = new ElasticsearchNodeInfo(alreadyUp.Version.Number, null, alreadyUp.Version.LuceneVersion);
				        this._blockingSubject.OnNext(handle);
				        if (!handle.WaitOne(timeout, true))
				            throw new ApplicationException($"Could not launch tests on already running elasticsearch within {timeout}");

				        return Observable.Empty<ElasticsearchMessage>();
				    }
				}
			}

		    lock (_lock)
		    {
		        InstallPlugins();
		    }

			this._process = new ObservableProcess(this.Binary,
				$"-Des.cluster.name={this.ClusterName}",
				$"-Des.node.name={this.NodeName}",
				$"-Des.path.repo={this.RepositoryPath}",
				$"-Des.script.inline=on",
				$"-Des.script.indexed=on"
			);
			var observable = Observable.Using(() => this._process, process => process.Start())
				.Select(consoleLine => new ElasticsearchMessage(consoleLine));
			this._processListener = observable.Subscribe(onNext: s => HandleConsoleMessage(s, handle));

			if (!handle.WaitOne(timeout, true))
			{
				this.Stop();
				throw new ApplicationException($"Could not start elasticsearch within {timeout}");
			}

			return observable;
		}