Skip to content

Commit 9b0d36b

Browse files
authored
ElasticsearchNode should use DesiredPort from NodeConfiguration (#2794)
* ElasticsearchNode should use DesiredPort from NodeConfiguration Share ElasticsearchVersion instances * Allow more time for flaky integration tests Increase number of documents and wait time for BulkAll cancellation and dispose tests Increase request timeout for Watcher inline execution test
1 parent 2b8f7eb commit 9b0d36b

File tree

11 files changed

+35
-22
lines changed

11 files changed

+35
-22
lines changed

src/Tests/ClientConcepts/ConnectionPooling/Sniffing/RoleDetection.doc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ protected override string[] AdditionalServerSettings
355355
{
356356
get
357357
{
358-
var es = this.Node.Version > new ElasticsearchVersion("5.0.0-alpha2") ? "" : "es.";
358+
var es = this.Node.Version > ElasticsearchVersion.GetOrAdd("5.0.0-alpha2") ? "" : "es.";
359359

360360
return new[]
361361
{

src/Tests/Document/Multiple/BulkAll/BulkAllApiTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void DisposingObservableCancelsBulkAll()
120120
var handle = new ManualResetEvent(false);
121121

122122
var size = 1000;
123-
var pages = 100;
123+
var pages = 1000;
124124
var seenPages = 0;
125125
var numberOfDocuments = size * pages;
126126
var documents = this.CreateLazyStreamOfDocuments(numberOfDocuments);
@@ -146,7 +146,7 @@ public void DisposingObservableCancelsBulkAll()
146146
observableBulk.Subscribe(bulkObserver);
147147

148148
//we wait N seconds to see some bulks
149-
handle.WaitOne(TimeSpan.FromSeconds(1));
149+
handle.WaitOne(TimeSpan.FromSeconds(3));
150150
observableBulk.Dispose();
151151
//we wait N seconds to give in flight request a chance to cancel
152152
handle.WaitOne(TimeSpan.FromSeconds(3));
@@ -165,7 +165,7 @@ public void CancelBulkAll()
165165
var handle = new ManualResetEvent(false);
166166

167167
var size = 1000;
168-
var pages = 100;
168+
var pages = 1000;
169169
var seenPages = 0;
170170
var numberOfDocuments = size * pages;
171171
var documents = this.CreateLazyStreamOfDocuments(numberOfDocuments);
@@ -191,7 +191,7 @@ public void CancelBulkAll()
191191
observableBulk.Subscribe(bulkObserver);
192192

193193
//we wait Nseconds to see some bulks
194-
handle.WaitOne(TimeSpan.FromSeconds(1));
194+
handle.WaitOne(TimeSpan.FromSeconds(3));
195195
tokenSource.Cancel();
196196
//we wait Nseconds to give in flight request a chance to cancel
197197
handle.WaitOne(TimeSpan.FromSeconds(3));

src/Tests/Framework/Configuration/EnvironmentConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class EnvironmentConfiguration : TestConfigurationBase
1111
{
1212
public override bool TestAgainstAlreadyRunningElasticsearch { get; protected set; } = false;
1313
public override bool ForceReseed { get; protected set; } = true;
14-
public override ElasticsearchVersion ElasticsearchVersion { get; protected set; } = new ElasticsearchVersion("5.0.0");
14+
public override ElasticsearchVersion ElasticsearchVersion { get; protected set; } = ElasticsearchVersion.GetOrAdd("5.0.0");
1515
public override TestMode Mode { get; protected set; } = TestMode.Unit;
1616
public override string ClusterFilter { get; protected set; }
1717
public override string TestFilter { get; protected set; }
@@ -23,7 +23,7 @@ public EnvironmentConfiguration()
2323
var version = Environment.GetEnvironmentVariable("NEST_INTEGRATION_VERSION");
2424
if (!string.IsNullOrEmpty(version)) Mode = TestMode.Integration;
2525

26-
this.ElasticsearchVersion = new ElasticsearchVersion(string.IsNullOrWhiteSpace(version) ? "5.0.0" : version);
26+
this.ElasticsearchVersion = ElasticsearchVersion.GetOrAdd(string.IsNullOrWhiteSpace(version) ? "5.0.0" : version);
2727
this.ClusterFilter = Environment.GetEnvironmentVariable("NEST_INTEGRATION_CLUSTER");
2828
this.TestFilter = Environment.GetEnvironmentVariable("NEST_TEST_FILTER");
2929
}

src/Tests/Framework/Configuration/Versions/ElasticsearchVersion.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Linq;
4+
using System.Net;
45
using System.Threading;
56
using System.Xml.Linq;
67
using Nest;
@@ -15,6 +16,7 @@ public class ElasticsearchVersion : Version
1516
private static readonly object _lock = new { };
1617
private static readonly ConcurrentDictionary<string, string> SnapshotVersions = new ConcurrentDictionary<string, string>();
1718
private static readonly string SonaTypeUrl = "https://oss.sonatype.org/content/repositories/snapshots/org/elasticsearch/distribution/zip/elasticsearch";
19+
private static readonly ConcurrentDictionary<string, ElasticsearchVersion> Versions = new ConcurrentDictionary<string, ElasticsearchVersion>();
1820

1921
private string RootUrl => this.IsSnapshot
2022
? SonaTypeUrl
@@ -127,5 +129,8 @@ public string DownloadUrl
127129
public bool IsSnapshot => this.Version?.ToLower().Contains("snapshot") ?? false;
128130

129131
public override string ToString() => this.Version;
132+
133+
public static ElasticsearchVersion GetOrAdd(string version) =>
134+
Versions.GetOrAdd(version, v => new ElasticsearchVersion(v));
130135
}
131136
}

src/Tests/Framework/Configuration/YamlConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public YamlConfiguration(string configurationFile)
2323
.ToDictionary(ConfigName, ConfigValue);
2424

2525
this.Mode = GetTestMode(config["mode"]);
26-
this.ElasticsearchVersion = new ElasticsearchVersion(config["elasticsearch_version"]);
26+
this.ElasticsearchVersion = ElasticsearchVersion.GetOrAdd(config["elasticsearch_version"]);
2727
this.ForceReseed = bool.Parse(config["force_reseed"]);
2828
this.TestAgainstAlreadyRunningElasticsearch = bool.Parse(config["test_against_already_running_elasticsearch"]);
2929
this.ClusterFilter = config.ContainsKey("cluster_filter") ? config["cluster_filter"] : null;

src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ public class ElasticsearchNode : IDisposable
2626
private readonly NodeConfiguration _config;
2727

2828
public ElasticsearchVersion Version => _config.ElasticsearchVersion;
29+
2930
public NodeFileSystem FileSystem { get; }
3031

3132
public bool Started { get; private set; }
3233

33-
public int Port { get; private set; } = 9200;
34+
public int Port { get; private set; }
3435

3536
private bool RunningOnCI { get; }
3637

@@ -39,7 +40,7 @@ public ElasticsearchNode(NodeConfiguration config)
3940
this._config = config;
4041
this.FileSystem = config.FileSystem;
4142
this.RunningOnCI = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION"));
42-
43+
this.Port = config.DesiredPort;
4344
if (this._config.RunIntegrationTests && !this._config.TestAgainstAlreadyRunningElasticsearch) return;
4445
}
4546

@@ -91,7 +92,7 @@ public void Start(string[] settings)
9192
{
9293
var subscription = Observable.Using(() => process, p => p.Start())
9394
.Select(c => new ElasticsearchConsoleOut(this._config.ElasticsearchVersion, c.Error, c.Data))
94-
.Subscribe(s => this.HandleConsoleMessage(s, handle), e => { throw e; }, () => handle.Set());
95+
.Subscribe(s => this.HandleConsoleMessage(s, handle), e => throw e, () => handle.Set());
9596
this._composite.Add(subscription);
9697

9798
if (!handle.WaitOne(timeout, true))
@@ -133,7 +134,7 @@ private void HandleConsoleMessage(ElasticsearchConsoleOut consoleOut, XplatManua
133134

134135
if (this.ProcessId == null && consoleOut.TryParseNodeInfo(out version, out pid))
135136
{
136-
var startedVersion = new ElasticsearchVersion(version);
137+
var startedVersion = ElasticsearchVersion.GetOrAdd(version);
137138
this.ProcessId = pid;
138139
if (this.Version != startedVersion)
139140
throw new Exception($"Booted elasticsearch is version {startedVersion} but the test config dictates {this.Version}");

src/Tests/Framework/ManagedElasticsearch/Nodes/NodeConfiguration.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public NodeConfiguration(ITestConfiguration configuration, ClusterBase cluster)
5656
this.DesiredPort = cluster.DesiredPort;
5757

5858
var attr = v.Major >= 5 ? "attr." : "";
59-
var indexedOrStored = v > new ElasticsearchVersion("5.0.0-alpha1") ? "stored" : "indexed";
60-
var shieldOrSecurity = v > new ElasticsearchVersion("5.0.0-alpha1") ? "xpack.security" : "shield";
61-
var es = v > new ElasticsearchVersion("5.0.0-alpha2") ? "" : "es.";
59+
var indexedOrStored = v > ElasticsearchVersion.GetOrAdd("5.0.0-alpha1") ? "stored" : "indexed";
60+
var shieldOrSecurity = v > ElasticsearchVersion.GetOrAdd("5.0.0-alpha1") ? "xpack.security" : "shield";
61+
var es = v > ElasticsearchVersion.GetOrAdd("5.0.0-alpha2") ? "" : "es.";
6262
var b = this.XPackEnabled.ToString().ToLowerInvariant();
6363
var sslEnabled = this.EnableSsl.ToString().ToLowerInvariant();
6464
this.DefaultNodeSettings = new List<string>
@@ -78,7 +78,7 @@ public NodeConfiguration(ITestConfiguration configuration, ClusterBase cluster)
7878
$"{es}{shieldOrSecurity}.authc.realms.pki1.enabled={sslEnabled}",
7979

8080
};
81-
if (v >= new ElasticsearchVersion("5.4.0"))
81+
if (v >= ElasticsearchVersion.GetOrAdd("5.4.0"))
8282
this.DefaultNodeSettings.Add($"{es}search.remote.connect=true");
8383
}
8484

src/Tests/Framework/ManagedElasticsearch/Plugins/ElasticsearchPluginCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public class ElasticsearchPluginCollection : KeyedCollection<ElasticsearchPlugin
88
public static ElasticsearchPluginCollection Supported { get; } =
99
new ElasticsearchPluginCollection
1010
{
11-
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.DeleteByQuery, version => version < new ElasticsearchVersion("5.0.0-alpha3")),
11+
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.DeleteByQuery, version => version < ElasticsearchVersion.GetOrAdd("5.0.0-alpha3")),
1212
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.MapperAttachments),
1313
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.MapperMurmer3),
1414
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.XPack),
15-
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestGeoIp, version => version >= new ElasticsearchVersion("5.0.0-alpha3")),
16-
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestAttachment, version => version >= new ElasticsearchVersion("5.0.0-alpha3")),
15+
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestGeoIp, version => version >= ElasticsearchVersion.GetOrAdd("5.0.0-alpha3")),
16+
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestAttachment, version => version >= ElasticsearchVersion.GetOrAdd("5.0.0-alpha3")),
1717
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.AnalysisKuromoji),
1818
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.AnalysisIcu)
1919
};

src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateRunningVersion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public override void Validate(IElasticClient client, NodeConfiguration configura
1717
if (!alreadyUp.IsValid) return;
1818
var v = configuration.ElasticsearchVersion;
1919

20-
var alreadyUpVersion = new ElasticsearchVersion(alreadyUp.Version.Number);
21-
var alreadyUpSnapshotVersion = new ElasticsearchVersion(alreadyUp.Version.Number + "-SNAPSHOT");
20+
var alreadyUpVersion = ElasticsearchVersion.GetOrAdd(alreadyUp.Version.Number);
21+
var alreadyUpSnapshotVersion = ElasticsearchVersion.GetOrAdd(alreadyUp.Version.Number + "-SNAPSHOT");
2222
if (v != alreadyUpVersion && v != alreadyUpSnapshotVersion)
2323
throw new Exception($"running elasticsearch is version {alreadyUpVersion} but the test config dictates {v}");
2424
}

src/Tests/Framework/TestClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static IClrTypeMapping<Project> ProjectMapping(ClrTypeMappingDescriptor<
9696
m.Ignore(p => p.Ranges);
9797
return m;
9898
}
99-
public static string PercolatorType => Configuration.ElasticsearchVersion <= new ElasticsearchVersion("5.0.0-alpha1")
99+
public static string PercolatorType => Configuration.ElasticsearchVersion <= ElasticsearchVersion.GetOrAdd("5.0.0-alpha1")
100100
? ".percolator"
101101
: "query";
102102

src/Tests/XPack/Watcher/ExecuteWatch/ExecuteWatchApiTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ protected override LazyResponses ClientUsage() => Calls(
548548
.Body("{}")
549549
)
550550
)
551+
)
552+
.RequestConfiguration(r => r
553+
.RequestTimeout(TimeSpan.FromMinutes(2))
551554
);
552555

553556
protected override ExecuteWatchRequest Initializer =>
@@ -615,6 +618,10 @@ protected override LazyResponses ClientUsage() => Calls(
615618
Method = HttpInputMethod.Post,
616619
Body = "{}"
617620
}
621+
},
622+
RequestConfiguration = new RequestConfiguration
623+
{
624+
RequestTimeout = TimeSpan.FromMinutes(2)
618625
}
619626
};
620627

0 commit comments

Comments
 (0)