Example #1
0
        protected void ExecuteBinary(string binary, string description, params string[] arguments)
        {
            Console.WriteLine($"Preparing to execute: {description} ...");
            var timeout = TimeSpan.FromSeconds(420);
            var handle  = new XplatManualResetEvent(false);
            var task    = Task.Run(() =>
            {
                using (var p = new ObservableProcess(binary, arguments))
                {
                    var o = p.Start();
                    Console.WriteLine($"Executing: {binary} {string.Join(" ", arguments)}");
                    o.Subscribe(c => Console.WriteLine(c.Data),
                                (e) =>
                    {
                        Console.WriteLine($"Failed executing: {description} {e.Message} {e.StackTrace}");
                        handle.Set();
                        throw e;
                    },
                                () =>
                    {
                        Console.WriteLine($"Finished executing {description} exit code: {p.ExitCode}");
                        handle.Set();
                    });
                    if (!handle.WaitOne(timeout, true))
                    {
                        throw new Exception($"Timeout while executing {description} exceeded {timeout}");
                    }
                }
            });

            if (!handle.WaitOne(timeout, true))
            {
                throw new Exception($"Timeout while executing {description} exceeded {timeout}");
            }

            if (task.Exception != null)
            {
                throw task.Exception;
            }
        }
Example #2
0
        public void Start(string[] settings, TimeSpan startTimeout)
        {
            if (!this._config.RunIntegrationTests || this.Started)
            {
                return;
            }
            lock (_lock)
            {
                if (!this._config.RunIntegrationTests || this.Started)
                {
                    return;
                }

                this.FreeResources();

                if (UseAlreadyRunningInstance())
                {
                    this.Started = true;
                    return;
                }

                var handle  = new XplatManualResetEvent(false);
                var booted  = false;
                var process = new ObservableProcess(this.FileSystem.Binary, settings);
                this._composite = new CompositeDisposable(process);
                Console.WriteLine($"Starting: {process.Binary} {process.Arguments}");
                try
                {
                    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());
                    this._composite.Add(subscription);

                    if (!handle.WaitOne(startTimeout, true))
                    {
                        throw new Exception($"Could not start elasticsearch within {startTimeout}");
                    }

                    booted = true;
                }
                finally
                {
                    if (!booted)
                    {
                        this.FreeResources();
                    }
                }
            }
        }