Esempio n. 1
0
        public YamlConfiguration(string configurationFile)
        {
            if (!File.Exists(configurationFile))
            {
                return;
            }

            _config = File.ReadAllLines(configurationFile)
                      .Where(l => !l.Trim().StartsWith("#") && !string.IsNullOrWhiteSpace(l))
                      .ToDictionary(ConfigName, ConfigValue);

            this.Mode = GetTestMode(_config["mode"]);
            this.ElasticsearchVersion = ElasticsearchVersion.GetOrAdd(_config["elasticsearch_version"]);
            this.ForceReseed          = BoolConfig("force_reseed", false);
            this.TestAgainstAlreadyRunningElasticsearch = BoolConfig("test_against_already_running_elasticsearch", false);
            this.ClusterFilter = _config.ContainsKey("cluster_filter") ? _config["cluster_filter"] : null;
            this.TestFilter    = _config.ContainsKey("test_filter") ? _config["test_filter"] : null;

            this.Seed       = _config.TryGetValue("seed", out var seed) ? int.Parse(seed) : 1337;
            Randomizer.Seed = new Random(this.Seed);
            var randomizer = new Randomizer();

            this.Random = new RandomConfiguration
            {
                SourceSerializer = RandomBool("source_serializer", randomizer),
                TypedKeys        = RandomBool("typed_keys", randomizer)
            };
        }
        public EnvironmentConfiguration()
        {
            //if env var NEST_INTEGRATION_VERSION is set assume integration mode
            //used by the build script FAKE
            var version = Environment.GetEnvironmentVariable("NEST_INTEGRATION_VERSION");

            if (!string.IsNullOrEmpty(version))
            {
                Mode = TestMode.Integration;
            }

            this.ElasticsearchVersion = ElasticsearchVersion.GetOrAdd(string.IsNullOrWhiteSpace(version) ? DefaultVersion : version);
            this.ClusterFilter        = Environment.GetEnvironmentVariable("NEST_INTEGRATION_CLUSTER");
            this.TestFilter           = Environment.GetEnvironmentVariable("NEST_TEST_FILTER");

            var newRandom = new Random().Next(1, 100000);

            this.Seed       = TryGetEnv("NEST_TEST_SEED", out var seed) ? int.Parse(seed) : newRandom;
            Randomizer.Seed = new Random(this.Seed);
            var randomizer = new Randomizer();

            this.Random = new RandomConfiguration
            {
                SourceSerializer = RandomBoolConfig("SOURCESERIALIZER", randomizer),
                TypedKeys        = RandomBoolConfig("TYPEDKEYS", randomizer),
            };
        }
        private void HandleConsoleMessage(ElasticsearchConsoleOut consoleOut, XplatManualResetEvent handle)
        {
            //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(consoleOut.Data);
            }

            string version;
            int?   pid;
            int    port;

            if (this.ProcessId == null && consoleOut.TryParseNodeInfo(out version, out pid))
            {
                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}");
                }
            }
            else if (consoleOut.TryGetPortNumber(out port))
            {
                this.Port = port;
            }
            else if (consoleOut.TryGetStartedConfirmation())
            {
                this.Started = true;
                handle.Set();
            }
        }
        public EnvironmentConfiguration()
        {
            //if env var NEST_INTEGRATION_VERSION is set assume integration mode
            //used by the build script FAKE
            var version = Environment.GetEnvironmentVariable("NEST_INTEGRATION_VERSION");

            if (!string.IsNullOrEmpty(version))
            {
                Mode = TestMode.Integration;
            }

            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");
        }
Esempio n. 5
0
        public NodeConfiguration(ITestConfiguration configuration, ClusterBase cluster)
        {
            this._cluster  = cluster;
            this.EnableSsl = cluster.SkipValidation;

            this.RequiredPlugins = ClusterRequiredPlugins(cluster);
            this.Mode            = configuration.Mode;

            var v = configuration.ElasticsearchVersion;

            this.ElasticsearchVersion = v;
            this.ForceReseed          = configuration.ForceReseed;
            this.TestAgainstAlreadyRunningElasticsearch = configuration.TestAgainstAlreadyRunningElasticsearch;
            this.RunIntegrationTests = configuration.RunIntegrationTests;
            this.RunUnitTests        = configuration.RunUnitTests;
            this.ClusterFilter       = configuration.ClusterFilter;
            this.TestFilter          = configuration.TestFilter;
            this.FileSystem          = new NodeFileSystem(configuration.ElasticsearchVersion, this.ClusterName, this.NodeName);
            this.DesiredPort         = cluster.DesiredPort;

            var attr             = v.Major >= 5 ? "attr." : "";
            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>
            {
                $"{es}cluster.name={this.ClusterName}",
                $"{es}node.name={this.NodeName}",
                $"{es}path.repo={this.FileSystem.RepositoryPath}",
                $"{es}path.data={this.FileSystem.DataPath}",
                $"{es}http.port={this.DesiredPort}",
                $"{es}script.inline=true",
                $"{es}script.max_compilations_per_minute=10000",
                $"{es}script.{indexedOrStored}=true",
                $"{es}node.{attr}testingcluster=true",
                $"{es}node.{attr}gateway=true",
                $"{es}{shieldOrSecurity}.enabled={b}",
                $"{es}{shieldOrSecurity}.http.ssl.enabled={sslEnabled}",
                $"{es}{shieldOrSecurity}.authc.realms.pki1.enabled={sslEnabled}",
                $"{es}search.remote.connect=true"
            };
        }
        public YamlConfiguration(string configurationFile)
        {
            if (!File.Exists(configurationFile))
            {
                return;
            }

            var config = File.ReadAllLines(configurationFile)
                         .Where(l => !l.Trim().StartsWith("#") && !string.IsNullOrWhiteSpace(l))
                         .ToDictionary(ConfigName, ConfigValue);

            this.Mode = GetTestMode(config["mode"]);
            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;
            this.TestFilter    = config.ContainsKey("test_filter") ? config["test_filter"] : null;
        }
        public override void Validate(IElasticClient client, NodeConfiguration configuration)
        {
            if (!configuration.TestAgainstAlreadyRunningElasticsearch)
            {
                return;
            }
            var alreadyUp = client.RootNodeInfo();

            if (!alreadyUp.IsValid)
            {
                return;
            }
            var v = configuration.ElasticsearchVersion;

            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}");
            }
        }