Пример #1
0
        public void should_use_the_config_file_value()
        {
            var args     = new string[] { "-config", "TestConfigs/test_config.yaml" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual("~/logDirectoryFromConfigFile", testArgs.Log);
        }
 protected EventStoreHostedService(string[] args)
 {
     try {
         Options = EventStoreOptions.Parse <TOptions>(args, Opts.EnvPrefix,
                                                      Path.Combine(Locations.DefaultConfigurationDirectory, DefaultFiles.DefaultConfigFile),
                                                      MutateEffectiveOptions);
         if (Options.Help)
         {
             Console.WriteLine("Options:");
             Console.WriteLine(EventStoreOptions.GetUsage <TOptions>());
             _skipRun = true;
         }
         else if (Options.Version)
         {
             Console.WriteLine("EventStore version {0} ({1}/{2}, {3})",
                               VersionInfo.Version, VersionInfo.Branch, VersionInfo.Hashtag, VersionInfo.Timestamp);
             _skipRun = true;
         }
         else
         {
             PreInit(Options);
             Init(Options);
             Create(Options);
         }
     } catch (OptionException exc) {
         Console.Error.WriteLine("Error while parsing options:");
         Console.Error.WriteLine(FormatExceptionMessage(exc));
         Console.Error.WriteLine();
         Console.Error.WriteLine("Options:");
         Console.Error.WriteLine(EventStoreOptions.GetUsage <TOptions>());
         throw;
     }
 }
Пример #3
0
        public void should_use_the_supplied_argument()
        {
            var args     = new[] { "--log=~/customLogDirectory" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual("~/customLogDirectory", testArgs.Log);
        }
Пример #4
0
        public void should_warn_the_user_about_unknown_argument_when_from_config_file()
        {
            var args            = new string[] { "-config", "TestConfigs/test_config_with_unknown_option.yaml" };
            var optionException = Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); });

            Assert.True(optionException.Message.Contains("UnknownOption"));
        }
Пример #5
0
 protected ProgramBase(string[] args)
 {
     Application.RegisterExitAction(Exit);
     try {
         var options = EventStoreOptions.Parse <TOptions>(args, Opts.EnvPrefix,
                                                          Path.Combine(Locations.DefaultConfigurationDirectory, DefaultFiles.DefaultConfigFile),
                                                          MutateEffectiveOptions);
         if (options.Help)
         {
             Console.WriteLine("Options:");
             Console.WriteLine(EventStoreOptions.GetUsage <TOptions>());
             _skipRun = true;
         }
         else if (options.Version)
         {
             Console.WriteLine("EventStore version {0} ({1}/{2}, {3})",
                               VersionInfo.Version, VersionInfo.Branch, VersionInfo.Hashtag, VersionInfo.Timestamp);
             _skipRun = true;
         }
         else
         {
             PreInit(options);
             Init(options);
             Create(options);
             _startupSource.SetResult(true);
         }
     } catch (OptionException exc) {
         Console.Error.WriteLine("Error while parsing options:");
         Console.Error.WriteLine(FormatExceptionMessage(exc));
         Console.Error.WriteLine();
         Console.Error.WriteLine("Options:");
         Console.Error.WriteLine(EventStoreOptions.GetUsage <TOptions>());
         _startupSource.SetException(exc);
     } catch (ApplicationInitializationException ex) {
         var msg = String.Format("Application initialization error: {0}", FormatExceptionMessage(ex));
         if (LogManager.Initialized)
         {
             Log.FatalException(ex, msg);
         }
         else
         {
             Console.Error.WriteLine(msg);
         }
         _startupSource.SetException(ex);
     } catch (Exception ex) {
         var msg = "Unhandled exception while starting application:";
         if (LogManager.Initialized)
         {
             Log.FatalException(ex, msg);
         }
         else
         {
             Console.Error.WriteLine(msg);
             Console.Error.WriteLine(FormatExceptionMessage(ex));
         }
         _startupSource.SetException(ex);
     } finally {
         Log.Flush();
     }
 }
Пример #6
0
        public void with_config()
        {
            var configFile = HelperExtensions.GetFilePathFromAssembly("TestConfigs/invalid_format_config.yaml");
            var args       = new string[] { "-config", configFile };

            Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); });
        }
Пример #7
0
        public void should_use_the_defaults()
        {
            var args     = new string[] { };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual("~/logs", testArgs.Log);
        }
Пример #8
0
        public void should_warn_the_user_about_unknown_argument_when_from_command_line()
        {
            var args            = new string[] { "-unknown-option", "true" };
            var optionException = Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); });

            Assert.True(optionException.Message.Contains("unknownoption"));
        }
Пример #9
0
        public void should_use_the_argument_over_the_config_file_value()
        {
            var args     = new string[] { "-config", "TestConfigs/test_config.yaml", "-log", "~/customLogsDirectory" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual("~/customLogsDirectory", testArgs.Log);
        }
        public void should_use_the_environment_variable_over_the_default_value()
        {
            Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111");
            var args     = new string[] { };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual(2111, testArgs.HttpPort);
        }
Пример #11
0
        public void should_use_the_config_file_value()
        {
            var configFile = HelperExtensions.GetFilePathFromAssembly("TestConfigs/test_config.yaml");
            var args       = new string[] { "-config", configFile };
            var testArgs   = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual("~/logDirectoryFromConfigFile", testArgs.Log);
        }
Пример #12
0
        public void should_inform_the_user_of_the_incorrectly_cased_option()
        {
            var args            = new string[] { "-config", "TestConfigs/test_config_with_incorrectly_cased_option.yaml" };
            var optionException = Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); });

            Assert.That(optionException.Message.Contains("log should be Log"));
            Assert.That(optionException.Message.Contains("runProjections should be RunProjections"));
        }
Пример #13
0
        public void should_use_the_config_value_over_the_environment_variable()
        {
            Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111");
            var args     = new string[] { "-config", "TestConfigs/test_config.yaml" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual(2115, testArgs.HttpPort);
        }
Пример #14
0
        public void should_be_able_to_parse_the_option_ignoring_casing()
        {
            var args    = new string[] { "-config", "TestConfigs/test_config_with_incorrectly_cased_option.yaml" };
            var options = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual("~/gesLogs", options.Log);
            Assert.AreEqual(ProjectionType.All, options.RunProjections);
        }
Пример #15
0
        public void should_not_require_equals_in_method()
        {
            var args     = new[] { "--log", "./customLogDirectory", "--run-projections", "all" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual("./customLogDirectory", testArgs.Log);
            Assert.AreEqual(ProjectionType.All, testArgs.RunProjections);
        }
Пример #16
0
        public void with_environment_variable()
        {
            Environment.SetEnvironmentVariable(Opts.EnvPrefix + "HTTP_PORT", "invalid_format");
            var args = new string[] { };

            Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); });
            Environment.SetEnvironmentVariable(Opts.EnvPrefix + "HTTP_PORT", null);
        }
Пример #17
0
        public void should_not_contain_the_unknown_option_in_the_dumping_of_the_options_environment_variable()
        {
            Environment.SetEnvironmentVariable(String.Format("{0}UNKNOWN_OPTION", Opts.EnvPrefix), "true");
            var args = new string[] { };

            EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.False(EventStoreOptions.DumpOptions().Contains(String.Format("{0}UNKNOWN_OPTION", Opts.EnvPrefix)));
        }
Пример #18
0
        public void should_use_the_command_line_argument()
        {
            Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111");
            var args     = new string[] { "-config", "TestConfigs/test_config.yaml", "-httpPort", "2115" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual(2115, testArgs.HttpPort);
            Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), String.Empty);
        }
Пример #19
0
        public int Run(string[] args)
        {
            try
            {
                Application.RegisterExitAction(Exit);

                var options = EventStoreOptions.Parse <TOptions>(args, Opts.EnvPrefix, Path.Combine(Locations.DefaultConfigurationDirectory, DefaultFiles.DefaultConfigFile));
                if (options.Help)
                {
                    Console.WriteLine("Options:");
                    Console.WriteLine(EventStoreOptions.GetUsage <TOptions>());
                }
                else if (options.Version)
                {
                    Console.WriteLine("EventStore version {0} ({1}/{2}, {3})",
                                      VersionInfo.Version, VersionInfo.Branch, VersionInfo.Hashtag, VersionInfo.Timestamp);
                    Application.ExitSilent(0, "Normal exit.");
                }
                else
                {
                    PreInit(options);
                    Init(options);
                    CommitSuicideIfInBoehmOrOnBadVersionsOfMono(options);
                    Create(options);
                    Start();

                    _exitEvent.Wait();
                }
            }
            catch (OptionException exc)
            {
                Console.Error.WriteLine("Error while parsing options:");
                Console.Error.WriteLine(FormatExceptionMessage(exc));
                Console.Error.WriteLine();
                Console.Error.WriteLine("Options:");
                Console.Error.WriteLine(EventStoreOptions.GetUsage <TOptions>());
            }
            catch (ApplicationInitializationException ex)
            {
                Log.FatalException(ex, "Application initialization error: {0}", FormatExceptionMessage(ex));
                Application.Exit(ExitCode.Error, FormatExceptionMessage(ex));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Log.FatalException(ex, "Unhandled exception while starting application:\n{0}", FormatExceptionMessage(ex));
                Application.Exit(ExitCode.Error, FormatExceptionMessage(ex));
            }
            finally
            {
                Log.Flush();
            }

            Application.ExitSilent(_exitCode, "Normal exit.");
            return(_exitCode);
        }
Пример #20
0
        public void should_be_able_to_parse_the_value_from_a_config_file()
        {
            var args     = new string[] { "-config", "TestConfigs/test_config.yaml" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual(new IPEndPoint[] {
                new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1000),
                new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2000)
            }, testArgs.GossipSeed);
        }
Пример #21
0
        public void should_be_able_to_parse_the_value_from_command_line()
        {
            var args     = new string[] { "-gossip-seed", "127.0.0.1:1000,127.0.0.2:2000" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual(new IPEndPoint[] {
                new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1000),
                new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2000)
            }, testArgs.GossipSeed);
        }
Пример #22
0
        public void should_be_able_to_parse_the_value_from_an_environment_variable()
        {
            Environment.SetEnvironmentVariable(String.Format("{0}GOSSIP_SEED", Opts.EnvPrefix), "127.0.0.1:1000,127.0.0.2:2000");
            var args     = new string[] {};
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual(new IPEndPoint[] {
                new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1000),
                new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2000)
            }, testArgs.GossipSeed);
        }
        public void should_use_the_environment_variable_over_the_config_value()
        {
            var configFile = HelperExtensions.GetFilePathFromAssembly("TestConfigs/test_config.yaml");

            Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111");
            var args     = new string[] { "-config", configFile };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual(2111, testArgs.HttpPort);
            Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), String.Empty);
        }
Пример #24
0
        public void should_use_the_command_line_argument()
        {
            var configFile = HelperExtensions.GetFilePathFromAssembly("TestConfigs/test_config.yaml");

            Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111", EnvironmentVariableTarget.Process);
            var args     = new string[] { "-config", configFile, "-httpPort", "2115" };
            var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix);

            Assert.AreEqual(2115, testArgs.HttpPort);
            Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), null, EnvironmentVariableTarget.Process);
        }
Пример #25
0
        public void with_command_line_argument()
        {
            var args = new string[] { "-httpPort", "invalid_format" };

            Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); });
        }
Пример #26
0
        public void with_config()
        {
            var args = new string[] { "-config", "TestConfigs/invalid_format_config.yaml" };

            Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); });
        }
Пример #27
0
 public TOptions LoadConfig() => EventStoreOptions.Parse <TOptions>(_args, Opts.EnvPrefix,
                                                                    Path.Combine(Locations.DefaultConfigurationDirectory, DefaultFiles.DefaultConfigFile),
                                                                    MutateEffectiveOptions);