diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index a39abb44b8c..2edbcf9740b 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -1,4 +1,4 @@ - + net45;net46;netstandard1.3 @@ -23,6 +23,8 @@ + + diff --git a/src/Tests/ClientConcepts/ConnectionPooling/Sniffing/RoleDetection.doc.cs b/src/Tests/ClientConcepts/ConnectionPooling/Sniffing/RoleDetection.doc.cs index ee7ebdc100e..0fd94ecd17d 100644 --- a/src/Tests/ClientConcepts/ConnectionPooling/Sniffing/RoleDetection.doc.cs +++ b/src/Tests/ClientConcepts/ConnectionPooling/Sniffing/RoleDetection.doc.cs @@ -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[] { diff --git a/src/Tests/Document/Multiple/BulkAll/BulkAllApiTests.cs b/src/Tests/Document/Multiple/BulkAll/BulkAllApiTests.cs index 3cf26b7ad61..368f3fa107b 100644 --- a/src/Tests/Document/Multiple/BulkAll/BulkAllApiTests.cs +++ b/src/Tests/Document/Multiple/BulkAll/BulkAllApiTests.cs @@ -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); @@ -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)); @@ -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); @@ -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)); diff --git a/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs b/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs index 4259624437e..e61691a0081 100644 --- a/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs +++ b/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs @@ -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; } @@ -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"); } diff --git a/src/Tests/Framework/Configuration/Versions/ElasticsearchVersion.cs b/src/Tests/Framework/Configuration/Versions/ElasticsearchVersion.cs index 8c68938bbf6..358e5768d9d 100644 --- a/src/Tests/Framework/Configuration/Versions/ElasticsearchVersion.cs +++ b/src/Tests/Framework/Configuration/Versions/ElasticsearchVersion.cs @@ -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; @@ -15,6 +16,7 @@ public class ElasticsearchVersion : Version private static readonly object _lock = new { }; private static readonly ConcurrentDictionary SnapshotVersions = new ConcurrentDictionary(); private static readonly string SonaTypeUrl = "https://oss.sonatype.org/content/repositories/snapshots/org/elasticsearch/distribution/zip/elasticsearch"; + private static readonly ConcurrentDictionary Versions = new ConcurrentDictionary(); private string RootUrl => this.IsSnapshot ? SonaTypeUrl @@ -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)); } } diff --git a/src/Tests/Framework/Configuration/YamlConfiguration.cs b/src/Tests/Framework/Configuration/YamlConfiguration.cs index f1f285723ef..4cc32dc1319 100644 --- a/src/Tests/Framework/Configuration/YamlConfiguration.cs +++ b/src/Tests/Framework/Configuration/YamlConfiguration.cs @@ -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; diff --git a/src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs b/src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs index 3c639667f0a..3fcee83fe70 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs @@ -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; } @@ -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)) @@ -111,12 +115,17 @@ 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; @@ -124,7 +133,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}"); diff --git a/src/Tests/Framework/ManagedElasticsearch/Nodes/NodeConfiguration.cs b/src/Tests/Framework/ManagedElasticsearch/Nodes/NodeConfiguration.cs index 948a12b1e8f..875269d9401 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Nodes/NodeConfiguration.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Nodes/NodeConfiguration.cs @@ -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 diff --git a/src/Tests/Framework/ManagedElasticsearch/Plugins/ElasticsearchPluginCollection.cs b/src/Tests/Framework/ManagedElasticsearch/Plugins/ElasticsearchPluginCollection.cs index 2f662fb7e56..9ce6c6f106e 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Plugins/ElasticsearchPluginCollection.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Plugins/ElasticsearchPluginCollection.cs @@ -8,15 +8,15 @@ public class ElasticsearchPluginCollection : KeyedCollection 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; } -} \ No newline at end of file +} diff --git a/src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateRunningVersion.cs b/src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateRunningVersion.cs index dea19e38ba7..047ed20d8f4 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateRunningVersion.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateRunningVersion.cs @@ -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}"); } diff --git a/src/Tests/Framework/TestClient.cs b/src/Tests/Framework/TestClient.cs index 8fd282324f2..b34b9720a17 100644 --- a/src/Tests/Framework/TestClient.cs +++ b/src/Tests/Framework/TestClient.cs @@ -96,7 +96,7 @@ private static IClrTypeMapping 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"; diff --git a/src/Tests/XPack/Watcher/ExecuteWatch/ExecuteWatchApiTests.cs b/src/Tests/XPack/Watcher/ExecuteWatch/ExecuteWatchApiTests.cs index 089ba663280..c1fc635822d 100644 --- a/src/Tests/XPack/Watcher/ExecuteWatch/ExecuteWatchApiTests.cs +++ b/src/Tests/XPack/Watcher/ExecuteWatch/ExecuteWatchApiTests.cs @@ -548,6 +548,9 @@ protected override LazyResponses ClientUsage() => Calls( .Body("{}") ) ) + ) + .RequestConfiguration(r => r + .RequestTimeout(TimeSpan.FromMinutes(2)) ); protected override ExecuteWatchRequest Initializer => @@ -615,6 +618,10 @@ protected override LazyResponses ClientUsage() => Calls( Method = HttpInputMethod.Post, Body = "{}" } + }, + RequestConfiguration = new RequestConfiguration + { + RequestTimeout = TimeSpan.FromMinutes(2) } };