public void IsTakingTooLong() { var dateTime = new TestableDateTimeProvider(); var singleNodePipeline = CreatePipeline(uris => new SingleNodeConnectionPool(uris.First(), dateTime), dateTimeProvider: dateTime); var staticPipeline = CreatePipeline(uris => new StaticConnectionPool(uris, dateTimeProvider: dateTime), dateTimeProvider: dateTime); var sniffingPipeline = CreatePipeline(uris => new SniffingConnectionPool(uris, dateTimeProvider: dateTime), dateTimeProvider: dateTime); singleNodePipeline.IsTakingTooLong.Should().BeFalse(); staticPipeline.IsTakingTooLong.Should().BeFalse(); sniffingPipeline.IsTakingTooLong.Should().BeFalse(); /** go one hour into the future */ dateTime.ChangeTime(d => d.Add(TimeSpan.FromHours(2))); /**connection pools that do not support reseeding never go stale */ singleNodePipeline.IsTakingTooLong.Should().BeTrue(); staticPipeline.IsTakingTooLong.Should().BeTrue(); /** the sniffing connection pool supports reseeding so the pipeline will signal the state is out of date */ sniffingPipeline.IsTakingTooLong.Should().BeTrue(); /** request pipeline exposes the DateTime it started, here we assert it started 2 hours in the past */ (dateTime.Now() - singleNodePipeline.StartedOn).Should().BePositive().And.BeCloseTo(TimeSpan.FromHours(2)); (dateTime.Now() - staticPipeline.StartedOn).Should().BePositive().And.BeCloseTo(TimeSpan.FromHours(2)); (dateTime.Now() - sniffingPipeline.StartedOn).Should().BePositive().And.BeCloseTo(TimeSpan.FromHours(2)); }
public void SetsSniffPathUsingToTimespan() { var dateTime = new TestableDateTimeProvider(); var sniffingPipeline = CreatePipeline(uris => new SniffingConnectionPool(uris, dateTimeProvider: dateTime), dateTimeProvider: dateTime) as RequestPipeline; sniffingPipeline.SniffPath.Should().Be("_nodes/_all/settings?flat_settings&timeout=2s"); }
public void SniffsOnStaleCluster() { var dateTime = new TestableDateTimeProvider(); var singleNodePipeline = CreatePipeline(uris => new SingleNodeConnectionPool(uris.First(), dateTime), dateTimeProvider: dateTime); var staticPipeline = CreatePipeline(uris => new StaticConnectionPool(uris, dateTimeProvider: dateTime), dateTimeProvider: dateTime); var sniffingPipeline = CreatePipeline(uris => new SniffingConnectionPool(uris, dateTimeProvider: dateTime), dateTimeProvider: dateTime); singleNodePipeline.SniffsOnStaleCluster.Should().BeFalse(); staticPipeline.SniffsOnStaleCluster.Should().BeFalse(); sniffingPipeline.SniffsOnStaleCluster.Should().BeTrue(); singleNodePipeline.StaleClusterState.Should().BeFalse(); staticPipeline.StaleClusterState.Should().BeFalse(); sniffingPipeline.StaleClusterState.Should().BeFalse(); /** go one hour into the future */ dateTime.ChangeTime(d => d.Add(TimeSpan.FromHours(2))); /**connection pools that do not support reseeding never go stale */ singleNodePipeline.StaleClusterState.Should().BeFalse(); staticPipeline.StaleClusterState.Should().BeFalse(); /** the sniffing connection pool supports reseeding so the pipeline will signal the state is out of date */ sniffingPipeline.StaleClusterState.Should().BeTrue(); }
internal VirtualizedCluster(TestableDateTimeProvider dateTimeProvider, TransportConfiguration settings) { _dateTimeProvider = dateTimeProvider; _settings = settings; _exposingRequestPipeline = new ExposingPipelineFactory <TransportConfiguration>(settings, _dateTimeProvider); _syncCall = (t, r) => t.Request <VirtualResponse>( HttpMethod.GET, "/", PostData.Serializable(new {}), new RequestParameters(HttpMethod.GET, supportsBody: false) { RequestConfiguration = r?.Invoke(new RequestConfigurationDescriptor(null)) }); _asyncCall = async(t, r) => { var res = await t.RequestAsync <VirtualResponse> ( HttpMethod.GET, "/", CancellationToken.None, PostData.Serializable(new { }), new RequestParameters(HttpMethod.GET, supportsBody : false) { RequestConfiguration = r?.Invoke(new RequestConfigurationDescriptor(null)) } ).ConfigureAwait(false); return((ITransportResponse)res); }; }
[U] public void ViewSeesResurrectedNodes() { var dateTimeProvider = new TestableDateTimeProvider(); var seeds = Enumerable.Range(9200, NumberOfNodes).Select(p => new Node(new Uri("http://localhost:" + p))).ToList(); seeds.First().MarkDead(dateTimeProvider.Now().AddDays(1)); var pool = new StickyConnectionPool(seeds, dateTimeProvider: dateTimeProvider); for (var i = 0; i < 20; i++) { var node = pool.CreateView().First(); node.Uri.Port.Should().Be(9201); node = pool.CreateView().First(); node.Uri.Port.Should().Be(9201); } /** If we forward our clock 2 days the node that was marked dead until tomorrow (or yesterday!) should be resurrected */ dateTimeProvider.ChangeTime(d => d.AddDays(2)); var n = pool.CreateView().First(); n.Uri.Port.Should().Be(9200); n = pool.CreateView().First(); n.Uri.Port.Should().Be(9200); n = pool.CreateView().First(); n.Uri.Port.Should().Be(9200); n.IsResurrected.Should().BeTrue(); }
internal SealedVirtualCluster(VirtualCluster cluster, IConnectionPool pool, TestableDateTimeProvider dateTimeProvider, IMockProductRegistration productRegistration) { _connectionPool = pool; _connection = new VirtualClusterConnection(cluster, dateTimeProvider); _dateTimeProvider = dateTimeProvider; _productRegistration = productRegistration; }
public VirtualizedCluster(TestableDateTimeProvider dateTimeProvider, ConnectionSettings settings) { _dateTimeProvider = dateTimeProvider; _settings = settings; _fixedRequestPipeline = new FixedPipelineFactory(settings, _dateTimeProvider); _syncCall = (c, r) => c.Search <Project>(s => s.RequestConfiguration(r)); _asyncCall = async(c, r) => { var res = await c.SearchAsync <Project>(s => s.RequestConfiguration(r)); return((IResponse)res); }; }
public void SniffsOnStaleCluster() { /** * A connection pool that supports reseeding will sniff after a period of time * to ensure that its understanding of the state of the cluster is not stale. * * Let's set up three request pipelines with different connection pools and a * date time provider that will allow us to artificially change the time */ var dateTime = new TestableDateTimeProvider(); var singleNodePipeline = CreatePipeline(uris => new SingleNodeConnectionPool(uris.First(), dateTime), dateTimeProvider: dateTime); var staticPipeline = CreatePipeline(uris => new StaticConnectionPool(uris, dateTimeProvider: dateTime), dateTimeProvider: dateTime); var sniffingPipeline = CreatePipeline(uris => new SniffingConnectionPool(uris, dateTimeProvider: dateTime), dateTimeProvider: dateTime); /** * On the request pipeline with the Sniffing connection pool will sniff when its * understanding of the cluster is stale */ singleNodePipeline.SniffsOnStaleCluster.Should().BeFalse(); staticPipeline.SniffsOnStaleCluster.Should().BeFalse(); sniffingPipeline.SniffsOnStaleCluster.Should().BeTrue(); /** * To begin with, all request pipelines have a _fresh_ view of cluster state i.e. not stale */ singleNodePipeline.StaleClusterState.Should().BeFalse(); staticPipeline.StaleClusterState.Should().BeFalse(); sniffingPipeline.StaleClusterState.Should().BeFalse(); /** Now, if we go two hours into the future */ dateTime.ChangeTime(d => d.Add(TimeSpan.FromHours(2))); /** Those connection pools that do not support reseeding never go stale */ singleNodePipeline.StaleClusterState.Should().BeFalse(); staticPipeline.StaleClusterState.Should().BeFalse(); /** * but the Request pipeline using the Sniffing connection pool that supports reseeding, * signals that its understanding of the cluster state is out of date */ sniffingPipeline.StaleClusterState.Should().BeTrue(); }
public VirtualizedCluster(TestableDateTimeProvider dateTimeProvider, ConnectionConfiguration settings) { _dateTimeProvider = dateTimeProvider; _settings = settings; _fixedRequestPipeline = new FixedPipelineFactory(settings, _dateTimeProvider); _syncCall = (c, r) => c.Search <VirtualResponse>(PostData.Serializable(new {}), new SearchRequestParameters { RequestConfiguration = r?.Invoke(new RequestConfigurationDescriptor(null)) }); _asyncCall = async(c, r) => { var res = await c.SearchAsync <VirtualResponse> ( PostData.Serializable(new { }), new SearchRequestParameters { RequestConfiguration = r?.Invoke(new RequestConfigurationDescriptor(null)) }, CancellationToken.None ).ConfigureAwait(false); return((IElasticsearchResponse)res); }; }
internal VirtualClusterConnection(VirtualCluster cluster, TestableDateTimeProvider dateTimeProvider) { UpdateCluster(cluster); _dateTimeProvider = dateTimeProvider; }
internal VirtualClusterConnection(VirtualCluster cluster, TestableDateTimeProvider dateTimeProvider) { UpdateCluster(cluster); _dateTimeProvider = dateTimeProvider; _productRegistration = cluster.ProductRegistration; }
public SealedVirtualCluster(VirtualCluster cluster, IConnectionPool pool, TestableDateTimeProvider dateTimeProvider) { _connectionPool = pool; _connection = new VirtualClusterConnection(cluster, dateTimeProvider); _dateTimeProvider = dateTimeProvider; }