Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElasticsearchNode should use DesiredPort from NodeConfiguration #2794

Merged
merged 2 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,11 +26,12 @@ 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; }

Expand All @@ -39,7 +40,7 @@ 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 @@ -91,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 Down Expand Up @@ -133,7 +134,7 @@ private void HandleConsoleMessage(ElasticsearchConsoleOut consoleOut, XplatManua

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 All @@ -78,7 +78,7 @@ public NodeConfiguration(ITestConfiguration configuration, ClusterBase cluster)
$"{es}{shieldOrSecurity}.authc.realms.pki1.enabled={sslEnabled}",

};
if (v >= new ElasticsearchVersion("5.4.0"))
if (v >= ElasticsearchVersion.GetOrAdd("5.4.0"))
this.DefaultNodeSettings.Add($"{es}search.remote.connect=true");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ 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.MapperAttachments),
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)
};
Expand Down
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