Пример #1
0
        //[I]
        public async Task UserCancellationDoesNotCauseFailOverToNextNode()
        {
            //this tests assumes only a single node is running under 9200 and fiddler is set up to artificially delay results
            var client = TestClient.GetClient(
                createPool: u => new StaticConnectionPool(new [] { TestClient.CreateUri(9200), TestClient.CreateUri(9201), TestClient.CreateUri(9202) }, randomize: false),
                modifySettings: c => c.RequestTimeout(TimeSpan.FromSeconds(2)));

            var ctx  = new CancellationTokenSource();
            var task = client.SearchAsync <Project>(s => s, ctx.Token);
            await Task.Delay(100);

            ctx.Cancel();
            var response = await task;

            response.ShouldNotBeValid();
            response.ApiCall.AuditTrail.Should().Contain(a => a.Event == AuditEvent.CancellationRequested);
            response.ApiCall.AuditTrail.Should().NotContain(a => a.Event == AuditEvent.MaxTimeoutReached);


            //Assert no failover happened, PingFailure would occur on 9201 normally.
            response.ApiCall.AuditTrail.Should().NotContain(a => a.Event == AuditEvent.PingFailure);
            //Assert no failover happened, for explicitness sake we only expect to see a single BadRequest or BadResponse
            //(depending on how fast Task.Delay kicks in)
            response.ApiCall.AuditTrail.Should().ContainSingle(a => a.Event == AuditEvent.BadRequest || a.Event == AuditEvent.BadResponse);
            //nothing in our trail should have gone to anything other then node 9200
            var trailsWithNodes = response.ApiCall.AuditTrail.Where(a => a.Node != null);

            trailsWithNodes.Should().NotBeEmpty().And.NotContain(a => a.Node.Uri.Port != 9200);

            //throw new Exception(response.DebugInformation);
        }
        private IRequestPipeline CreatePipeline(
            Func <IEnumerable <Uri>, IConnectionPool> setupPool, Func <ConnectionSettings, ConnectionSettings> settingsSelector = null, IDateTimeProvider dateTimeProvider = null, InMemoryConnection connection = null)
        {
            var pool     = setupPool(new[] { TestClient.CreateUri(), TestClient.CreateUri(9201) });
            var settings = new ConnectionSettings(pool, connection ?? new InMemoryConnection());

            settings = settingsSelector?.Invoke(settings) ?? settings;
            return(new FixedPipelineFactory(settings, dateTimeProvider ?? DateTimeProvider.Default).Pipeline);
        }
Пример #3
0
        //[I]
        public void ServerTestWhenThrowExceptionsDisabled()
        {
            var settings = new ConnectionSettings(TestClient.CreateUri(_port));
            var client   = new ElasticClient(settings);
            var response = client.GetMapping <Project>(s => s.Index("doesntexist"));

            // HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set
            response.ApiCall.OriginalException.Should().BeNull();
        }
        private RequestPipeline CreatePipeline()
        {
            var uri = TestClient.CreateUri(this._cluster.Nodes.First().Port ?? 9200);

            this._settings = new ConnectionSettings(new SniffingConnectionPool(new[] { uri }));
            var pipeline = new RequestPipeline(this._settings, DateTimeProvider.Default, new MemoryStreamFactory(),
                                               new SearchRequestParameters());

            return(pipeline);
        }
Пример #5
0
        //[I]
        public void ServerTestWhenThrowExceptionsEnabled()
        {
            var settings = new ConnectionSettings(TestClient.CreateUri(_port))
                           .ThrowExceptions();
            var client    = new ElasticClient(settings);
            var exception = Assert.Throws <ElasticsearchClientException>(() => client.GetMapping <Project>(s => s.Index("doesntexist")));

            // HttpClient does not throw on "known error" status codes (i.e. 404) thus the inner exception should not be set
            exception.InnerException.Should().BeNull();
            exception.Response.Should().NotBeNull();
        }
        //[I]
        public void ServerTestWhenThrowExceptionsDisabled()
        {
            var settings = new ConnectionSettings(TestClient.CreateUri(_port));
            var client   = new ElasticClient(settings);
            var response = client.GetMapping <Project>(s => s.Index("doesntexist"));

#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().NotBeNull();
            response.CallDetails.ServerError.Status.Should().BeGreaterThan(0);
        }