public static async Task <EventStoreInstance> StartAsync() { var installedSoftware = await InstallHelper.InstallAsync(SoftwareDescription).ConfigureAwait(false); var tcpPort = TcpHelper.GetFreePort(); var httpPort = TcpHelper.GetFreePort(); var connectionStringUri = new Uri($"tcp://*****:*****@{IPAddress.Loopback}:{tcpPort}"); var exePath = Path.Combine(installedSoftware.InstallPath, "EventStore.ClusterNode.exe"); IDisposable processDisposable = null; try { processDisposable = ProcessHelper.StartExe( exePath, "'admin' user added to $users", "--mem-db=True", "--cluster-size=1", $"--ext-tcp-port={tcpPort}", $"--ext-http-port={httpPort}"); var connectionSettings = ConnectionSettings.Create() .EnableVerboseLogging() .KeepReconnecting() .SetDefaultUserCredentials(new UserCredentials("admin", "changeit")) .Build(); using (var eventStoreConnection = EventStoreConnection.Create(connectionSettings, connectionStringUri)) { var start = DateTimeOffset.Now; while (true) { if (start + TimeSpan.FromSeconds(10) < DateTimeOffset.Now) { throw new Exception("Failed to connect to EventStore"); } try { await eventStoreConnection.ConnectAsync().ConfigureAwait(false); break; } catch (Exception) { Console.WriteLine("Failed to connect, retrying"); } } } } catch (Exception) { processDisposable.DisposeSafe("Failed to dispose EventStore process"); throw; } return(new EventStoreInstance( connectionStringUri, processDisposable)); }
public static async Task <ElasticsearchInstance> StartAsync() { if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("JAVA_HOME"))) { throw new InvalidOperationException("The 'JAVA_HOME' environment variable is required"); } var installedSoftware = await InstallHelper.InstallAsync(SoftwareDescription).ConfigureAwait(false); var version = SoftwareDescription.Version; var installPath = Path.Combine(installedSoftware.InstallPath, $"elasticsearch-{version.Major}.{version.Minor}.{version.Build}"); var tcpPort = TcpHelper.GetFreePort(); var exePath = Path.Combine(installPath, "bin", "elasticsearch.bat"); var nodeName = $"node-{Guid.NewGuid().ToString("N")}"; var settings = new Dictionary <string, string> { { "http.port", tcpPort.ToString() }, { "node.name", nodeName }, { "index.number_of_shards", "1" }, { "index.number_of_replicas", "0" }, { "gateway.expected_nodes", "1" }, { "discovery.zen.ping.multicast.enabled", "false" }, { "cluster.routing.allocation.disk.threshold_enabled", "false" } }; var configFilePath = Path.Combine(installPath, "config", "elasticsearch.yml"); if (!File.Exists(configFilePath)) { throw new ApplicationException($"Could not find config file at '{configFilePath}'"); } File.WriteAllLines(configFilePath, settings.Select(kv => $"{kv.Key}: {kv.Value}")); IDisposable processDisposable = null; try { processDisposable = ProcessHelper.StartExe(exePath, $"[${nodeName}] started"); var elasticsearchInstance = new ElasticsearchInstance( new Uri($"http://127.0.0.1:{tcpPort}"), processDisposable); await elasticsearchInstance.WaitForGeenStateAsync().ConfigureAwait(false); await elasticsearchInstance.DeleteEverythingAsync().ConfigureAwait(false); return(elasticsearchInstance); } catch (Exception) { processDisposable.DisposeSafe("Failed to dispose Elasticsearch process"); throw; } }