Skip to content

Commit

Permalink
ElasticsearchNode should use DesiredPort from NodeConfiguration (
Browse files Browse the repository at this point in the history
…#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)
  • Loading branch information
russcam committed Jun 29, 2017
1 parent f816b46 commit 45ac1fe
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/Nest/Nest.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\Clients.Common.targets" />
<PropertyGroup>
<TargetFrameworks Condition="'$(DotNetCoreOnly)'==''">net45;net46;netstandard1.3</TargetFrameworks>
Expand All @@ -23,6 +23,8 @@
<Folder Include="Cluster\RemoteInfo" />
<Folder Include="Document\Single\SourceExists" />
<Folder Include="Mapping\Types\Specialized\Attachment" />
<Folder Include="QueryDsl\FullText\MatchPhrase" />
<Folder Include="QueryDsl\FullText\MatchPhrasePrefix" />
<Folder Include="Search\FieldCapabilities" />
<Folder Include="XPack\Info\XPackInfo" />
<Folder Include="XPack\Info\XPackInfo" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ protected override string[] AdditionalServerSettings
{
get
{
var es = this.Node.Version > new ElasticsearchVersion("5.0.0-alpha2") ? "" : "es.";
var es = this.Node.Version > ElasticsearchVersion.GetOrAdd("5.0.0-alpha2") ? "" : "es.";

return new[]
{
Expand Down
8 changes: 4 additions & 4 deletions src/Tests/Document/Multiple/BulkAll/BulkAllApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void DisposingObservableCancelsBulkAll()
var handle = new ManualResetEvent(false);

var size = 1000;
var pages = 100;
var pages = 1000;
var seenPages = 0;
var numberOfDocuments = size * pages;
var documents = this.CreateLazyStreamOfDocuments(numberOfDocuments);
Expand All @@ -146,7 +146,7 @@ public void DisposingObservableCancelsBulkAll()
observableBulk.Subscribe(bulkObserver);

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

var size = 1000;
var pages = 100;
var pages = 1000;
var seenPages = 0;
var numberOfDocuments = size * pages;
var documents = this.CreateLazyStreamOfDocuments(numberOfDocuments);
Expand All @@ -191,7 +191,7 @@ public void CancelBulkAll()
observableBulk.Subscribe(bulkObserver);

//we wait Nseconds to see some bulks
handle.WaitOne(TimeSpan.FromSeconds(1));
handle.WaitOne(TimeSpan.FromSeconds(3));
tokenSource.Cancel();
//we wait Nseconds to give in flight request a chance to cancel
handle.WaitOne(TimeSpan.FromSeconds(3));
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/Framework/Configuration/EnvironmentConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class EnvironmentConfiguration : TestConfigurationBase
{
public override bool TestAgainstAlreadyRunningElasticsearch { get; protected set; } = false;
public override bool ForceReseed { get; protected set; } = true;
public override ElasticsearchVersion ElasticsearchVersion { get; protected set; } = new ElasticsearchVersion("5.0.0");
public override ElasticsearchVersion ElasticsearchVersion { get; protected set; } = ElasticsearchVersion.GetOrAdd("5.0.0");
public override TestMode Mode { get; protected set; } = TestMode.Unit;
public override string ClusterFilter { get; protected set; }
public override string TestFilter { get; protected set; }
Expand All @@ -23,7 +23,7 @@ public EnvironmentConfiguration()
var version = Environment.GetEnvironmentVariable("NEST_INTEGRATION_VERSION");
if (!string.IsNullOrEmpty(version)) Mode = TestMode.Integration;

this.ElasticsearchVersion = new ElasticsearchVersion(string.IsNullOrWhiteSpace(version) ? "5.0.0" : version);
this.ElasticsearchVersion = ElasticsearchVersion.GetOrAdd(string.IsNullOrWhiteSpace(version) ? "5.0.0" : version);
this.ClusterFilter = Environment.GetEnvironmentVariable("NEST_INTEGRATION_CLUSTER");
this.TestFilter = Environment.GetEnvironmentVariable("NEST_TEST_FILTER");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Net;
using System.Threading;
using System.Xml.Linq;
using Nest;
Expand All @@ -15,6 +16,7 @@ public class ElasticsearchVersion : Version
private static readonly object _lock = new { };
private static readonly ConcurrentDictionary<string, string> SnapshotVersions = new ConcurrentDictionary<string, string>();
private static readonly string SonaTypeUrl = "https://oss.sonatype.org/content/repositories/snapshots/org/elasticsearch/distribution/zip/elasticsearch";
private static readonly ConcurrentDictionary<string, ElasticsearchVersion> Versions = new ConcurrentDictionary<string, ElasticsearchVersion>();

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

public override string ToString() => this.Version;

public static ElasticsearchVersion GetOrAdd(string version) =>
Versions.GetOrAdd(version, v => new ElasticsearchVersion(v));
}
}
2 changes: 1 addition & 1 deletion src/Tests/Framework/Configuration/YamlConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public YamlConfiguration(string configurationFile)
.ToDictionary(ConfigName, ConfigValue);

this.Mode = GetTestMode(config["mode"]);
this.ElasticsearchVersion = new ElasticsearchVersion(config["elasticsearch_version"]);
this.ElasticsearchVersion = ElasticsearchVersion.GetOrAdd(config["elasticsearch_version"]);
this.ForceReseed = bool.Parse(config["force_reseed"]);
this.TestAgainstAlreadyRunningElasticsearch = bool.Parse(config["test_against_already_running_elasticsearch"]);
this.ClusterFilter = config.ContainsKey("cluster_filter") ? config["cluster_filter"] : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ public class ElasticsearchNode : IDisposable
private readonly NodeConfiguration _config;

public ElasticsearchVersion Version => _config.ElasticsearchVersion;

public NodeFileSystem FileSystem { get; }

public bool Started { get; private set; }

public int Port { get; private set; } = 9200;
public int Port { get; private set; }

private bool RunningOnCI { get; }

public ElasticsearchNode(NodeConfiguration config)
{
this._config = config;
this.FileSystem = config.FileSystem;

this.RunningOnCI = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION"));
this.Port = config.DesiredPort;
if (this._config.RunIntegrationTests && !this._config.TestAgainstAlreadyRunningElasticsearch) return;
}

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

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

private void HandleConsoleMessage(ElasticsearchConsoleOut consoleOut, XplatManualResetEvent handle)
{
Console.WriteLine(consoleOut.Data);
//no need to snoop for metadata if we already started
if (!this._config.RunIntegrationTests || this.Started) return;
//if we are running on CI and not started dump elasticsearch stdout/err
//before the started notification to help debug failures to start
if (this.RunningOnCI && !this.Started)
{
if (consoleOut.Error) Console.Error.WriteLine(consoleOut.Data);
else Console.WriteLine(consoleOut.Data);
}

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

string version;
int? pid;
int port;

if (this.ProcessId == null && consoleOut.TryParseNodeInfo(out version, out pid))
{
var startedVersion = new ElasticsearchVersion(version);
var startedVersion = ElasticsearchVersion.GetOrAdd(version);
this.ProcessId = pid;
if (this.Version != startedVersion)
throw new Exception($"Booted elasticsearch is version {startedVersion} but the test config dictates {this.Version}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public NodeConfiguration(ITestConfiguration configuration, ClusterBase cluster)
this.DesiredPort = cluster.DesiredPort;

var attr = v.Major >= 5 ? "attr." : "";
var indexedOrStored = v > new ElasticsearchVersion("5.0.0-alpha1") ? "stored" : "indexed";
var shieldOrSecurity = v > new ElasticsearchVersion("5.0.0-alpha1") ? "xpack.security" : "shield";
var es = v > new ElasticsearchVersion("5.0.0-alpha2") ? "" : "es.";
var indexedOrStored = v > ElasticsearchVersion.GetOrAdd("5.0.0-alpha1") ? "stored" : "indexed";
var shieldOrSecurity = v > ElasticsearchVersion.GetOrAdd("5.0.0-alpha1") ? "xpack.security" : "shield";
var es = v > ElasticsearchVersion.GetOrAdd("5.0.0-alpha2") ? "" : "es.";
var b = this.XPackEnabled.ToString().ToLowerInvariant();
var sslEnabled = this.EnableSsl.ToString().ToLowerInvariant();
this.DefaultNodeSettings = new List<string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public class ElasticsearchPluginCollection : KeyedCollection<ElasticsearchPlugin
public static ElasticsearchPluginCollection Supported { get; } =
new ElasticsearchPluginCollection
{
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.DeleteByQuery, version => version < new ElasticsearchVersion("5.0.0-alpha3")),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.DeleteByQuery, version => version < ElasticsearchVersion.GetOrAdd("5.0.0-alpha3")),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.MapperMurmer3),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.XPack),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestGeoIp, version => version >= new ElasticsearchVersion("5.0.0-alpha3")),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestAttachment, version => version >= new ElasticsearchVersion("5.0.0-alpha3")),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestGeoIp, version => version >= ElasticsearchVersion.GetOrAdd("5.0.0-alpha3")),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.IngestAttachment, version => version >= ElasticsearchVersion.GetOrAdd("5.0.0-alpha3")),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.AnalysisKuromoji),
new ElasticsearchPluginConfiguration(ElasticsearchPlugin.AnalysisIcu)
};

protected override ElasticsearchPlugin GetKeyForItem(ElasticsearchPluginConfiguration item) => item.Plugin;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public override void Validate(IElasticClient client, NodeConfiguration configura
if (!alreadyUp.IsValid) return;
var v = configuration.ElasticsearchVersion;

var alreadyUpVersion = new ElasticsearchVersion(alreadyUp.Version.Number);
var alreadyUpSnapshotVersion = new ElasticsearchVersion(alreadyUp.Version.Number + "-SNAPSHOT");
var alreadyUpVersion = ElasticsearchVersion.GetOrAdd(alreadyUp.Version.Number);
var alreadyUpSnapshotVersion = ElasticsearchVersion.GetOrAdd(alreadyUp.Version.Number + "-SNAPSHOT");
if (v != alreadyUpVersion && v != alreadyUpSnapshotVersion)
throw new Exception($"running elasticsearch is version {alreadyUpVersion} but the test config dictates {v}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Framework/TestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static IClrTypeMapping<Project> ProjectMapping(ClrTypeMappingDescriptor<
m.Ignore(p => p.Ranges);
return m;
}
public static string PercolatorType => Configuration.ElasticsearchVersion <= new ElasticsearchVersion("5.0.0-alpha1")
public static string PercolatorType => Configuration.ElasticsearchVersion <= ElasticsearchVersion.GetOrAdd("5.0.0-alpha1")
? ".percolator"
: "query";

Expand Down
7 changes: 7 additions & 0 deletions src/Tests/XPack/Watcher/ExecuteWatch/ExecuteWatchApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ protected override LazyResponses ClientUsage() => Calls(
.Body("{}")
)
)
)
.RequestConfiguration(r => r
.RequestTimeout(TimeSpan.FromMinutes(2))
);

protected override ExecuteWatchRequest Initializer =>
Expand Down Expand Up @@ -615,6 +618,10 @@ protected override LazyResponses ClientUsage() => Calls(
Method = HttpInputMethod.Post,
Body = "{}"
}
},
RequestConfiguration = new RequestConfiguration
{
RequestTimeout = TimeSpan.FromMinutes(2)
}
};

Expand Down

0 comments on commit 45ac1fe

Please sign in to comment.