Skip to content

Commit 45ac1fe

Browse files
committed
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 (cherry picked from commit 9b0d36b)
1 parent f816b46 commit 45ac1fe

File tree

12 files changed

+49
-26
lines changed

12 files changed

+49
-26
lines changed

src/Nest/Nest.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\..\build\Clients.Common.targets" />
33
<PropertyGroup>
44
<TargetFrameworks Condition="'$(DotNetCoreOnly)'==''">net45;net46;netstandard1.3</TargetFrameworks>
@@ -23,6 +23,8 @@
2323
<Folder Include="Cluster\RemoteInfo" />
2424
<Folder Include="Document\Single\SourceExists" />
2525
<Folder Include="Mapping\Types\Specialized\Attachment" />
26+
<Folder Include="QueryDsl\FullText\MatchPhrase" />
27+
<Folder Include="QueryDsl\FullText\MatchPhrasePrefix" />
2628
<Folder Include="Search\FieldCapabilities" />
2729
<Folder Include="XPack\Info\XPackInfo" />
2830
<Folder Include="XPack\Info\XPackInfo" />

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: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ 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; }
35+
36+
private bool RunningOnCI { get; }
3437

3538
public ElasticsearchNode(NodeConfiguration config)
3639
{
3740
this._config = config;
3841
this.FileSystem = config.FileSystem;
39-
42+
this.RunningOnCI = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION"));
43+
this.Port = config.DesiredPort;
4044
if (this._config.RunIntegrationTests && !this._config.TestAgainstAlreadyRunningElasticsearch) return;
4145
}
4246

@@ -88,7 +92,7 @@ public void Start(string[] settings)
8892
{
8993
var subscription = Observable.Using(() => process, p => p.Start())
9094
.Select(c => new ElasticsearchConsoleOut(this._config.ElasticsearchVersion, c.Error, c.Data))
91-
.Subscribe(s => this.HandleConsoleMessage(s, handle), e => { throw e; }, () => handle.Set());
95+
.Subscribe(s => this.HandleConsoleMessage(s, handle), e => throw e, () => handle.Set());
9296
this._composite.Add(subscription);
9397

9498
if (!handle.WaitOne(timeout, true))
@@ -111,20 +115,25 @@ private bool UseAlreadyRunningInstance()
111115

112116
private void HandleConsoleMessage(ElasticsearchConsoleOut consoleOut, XplatManualResetEvent handle)
113117
{
114-
Console.WriteLine(consoleOut.Data);
115118
//no need to snoop for metadata if we already started
116119
if (!this._config.RunIntegrationTests || this.Started) return;
120+
//if we are running on CI and not started dump elasticsearch stdout/err
121+
//before the started notification to help debug failures to start
122+
if (this.RunningOnCI && !this.Started)
123+
{
124+
if (consoleOut.Error) Console.Error.WriteLine(consoleOut.Data);
125+
else Console.WriteLine(consoleOut.Data);
126+
}
117127

118-
if (consoleOut.Error && !this.Started && !string.IsNullOrWhiteSpace(consoleOut.Data))
119-
throw new Exception("Error out:" + consoleOut.Data);
128+
if (consoleOut.Error && !this.Started && !string.IsNullOrWhiteSpace(consoleOut.Data)) throw new Exception(consoleOut.Data);
120129

121130
string version;
122131
int? pid;
123132
int port;
124133

125134
if (this.ProcessId == null && consoleOut.TryParseNodeInfo(out version, out pid))
126135
{
127-
var startedVersion = new ElasticsearchVersion(version);
136+
var startedVersion = ElasticsearchVersion.GetOrAdd(version);
128137
this.ProcessId = pid;
129138
if (this.Version != startedVersion)
130139
throw new Exception($"Booted elasticsearch is version {startedVersion} but the test config dictates {this.Version}");

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

Lines changed: 3 additions & 3 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>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ 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.MapperMurmer3),
1313
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.XPack),
14-
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestGeoIp, version => version >= new ElasticsearchVersion("5.0.0-alpha3")),
15-
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestAttachment, version => version >= new ElasticsearchVersion("5.0.0-alpha3")),
14+
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestGeoIp, version => version >= ElasticsearchVersion.GetOrAdd("5.0.0-alpha3")),
15+
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestAttachment, version => version >= ElasticsearchVersion.GetOrAdd("5.0.0-alpha3")),
1616
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.AnalysisKuromoji),
1717
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.AnalysisIcu)
1818
};
1919

2020
protected override ElasticsearchPlugin GetKeyForItem(ElasticsearchPluginConfiguration item) => item.Plugin;
2121
}
22-
}
22+
}

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)