private static List <ZooKeeperInstance> CreateInstances(ZooKeeperEnsembleSettings settings, ILog log) { var instances = new List <ZooKeeperInstance>(settings.Size); for (var i = 0; i < settings.Size; i++) { var clientPort = settings.InstancesPorts?[i] ?? FreeTcpPortFinder.GetFreePort(); var peerPort = FreeTcpPortFinder.GetFreePort(); var electionPort = FreeTcpPortFinder.GetFreePort(); var index = settings.StartingId + i; var instanceDirectoryPath = "ZK-" + index; if (!string.IsNullOrEmpty(settings.BaseDirectory)) { instanceDirectoryPath = Path.Combine(settings.BaseDirectory, instanceDirectoryPath); } instanceDirectoryPath = Path.GetFullPath(instanceDirectoryPath); instances.Add(new ZooKeeperInstance(index, instanceDirectoryPath, clientPort, peerPort, electionPort, log)); } log.Info("Created instances: \n\t" + string.Join("\n\t", instances.Select(i => i.ToString()))); return(instances); }
private TestServer() { Port = FreeTcpPortFinder.GetFreePort(); Host = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Dns.GetHostName() : "localhost"; listener = new HttpListener(); listener.Prefixes.Add($"http://+:{Port}/"); }
public static void EnsurePort([NotNull] Type applicationType, [NotNull] IVostokHostingEnvironmentBuilder builder) { if (RequirementDetector.RequiresPort(applicationType)) { builder.SetPort(FreeTcpPortFinder.GetFreePort()); } }
public async Task StartAsync(CancellationToken cancellationToken) { logger.LogInformation($"Starting {configuration.Value.CountOfAgents} agents"); var agentRunner = new AgentRunner(new AgentRunnerConfiguration { AgentRepositoryUrl = configuration.Value.AgentRepositoryUrl }, loggerFactory); var info = FreeTcpPortFinder.GetAvailablePort(10000, configuration.Value.CountOfAgents).Select(x => new StartAgentInformation(x)).ToArray(); var runAgentsResult = await agentRunner.RunAgentsAsync(info); if (!runAgentsResult.IsSuccessful) { logger.LogError(runAgentsResult.Error); } else { foreach (var agentInformation in runAgentsResult.Value) { agentsService.AddAgent(agentInformation); logger.LogInformation($"Started agent on {agentInformation.Url}"); } } agentsService.Start(); }
public static KafkaInstance DeployNew(KafkaSettings settings, ILog log) { var baseDirectory = GetBaseDirectory(settings); Directory.CreateDirectory(baseDirectory); var kafkaDirectory = GetKafkaDirectory(settings); if (Directory.Exists(kafkaDirectory)) { Directory.Delete(kafkaDirectory, true); } var deployerLog = log.ForContext(nameof(KafkaDeployer)); deployerLog.Debug("Started Kafka extraction..."); ResourceHelper.ExtractResource <KafkaInstance>($"Vostok.Kafka.Local.Resources.{KafkaDirectoryName}.tgz", baseDirectory); deployerLog.Debug("Finished Kafka extraction."); var kafkaPort = FreeTcpPortFinder.GetFreePort(); var instance = new KafkaInstance(kafkaDirectory, kafkaPort, log); GenerateConfig(instance, settings); return(instance); }
public TestServer() { Port = FreeTcpPortFinder.GetFreePort(); listener = new HttpListener(); listener.Prefixes.Add(Url); response = Responses.ServiceUnavailable; }
private SocketTestServer(string response, Action <TcpClient> onBeforeRequestReading) { this.onBeforeRequestReading = onBeforeRequestReading; this.response = Encoding.UTF8.GetBytes(response); Port = FreeTcpPortFinder.GetFreePort(); Host = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Dns.GetHostName() : "localhost"; listener = new TcpListener(IPAddress.Any, Port); }
public async Task OneTimeSetup() { Log = new SynchronousConsoleLog(); var serverPort = FreeTcpPortFinder.GetFreePort(); Client = CreateClusterClient(serverPort); testHost = await StartHost(serverPort); }
public override void Start() { Port = FreeTcpPortFinder.GetFreePort(); Properties["http.server.host"] = Host; Properties["http.server.port"] = Port.ToString(); Properties["application.host"] = Host; Properties["application.port"] = Port.ToString(); base.Start(); if (!new HerculesHttpServiceHealthChecker(Log, Host, Port).WaitStarted(startTimeout)) { throw new TimeoutException($"{componentSettings.GetDisplayName()} has not warmed up in {startTimeout} minutes."); } }
public void DeployNew_should_run_instances_on_specified_ports() { var port1 = FreeTcpPortFinder.GetFreePort(); var port2 = FreeTcpPortFinder.GetFreePort(); using (var ensemble = ZooKeeperEnsemble.DeployNew( new ZooKeeperEnsembleSettings { Size = 2, InstancesPorts = new List <int> { port1, port2 } }, log)) { ensemble.IsRunning.Should().BeTrue(); ensemble.Instances.Count.Should().Be(2); ensemble.Instances[0].ClientPort.Should().Be(port1); ensemble.Instances[1].ClientPort.Should().Be(port2); } }
public void DeployNew_should_fail_to_start_if_port_is_busy() { var port = FreeTcpPortFinder.GetFreePort(); var listener = new TcpListener(IPAddress.Loopback, port); try { listener.Start(); Action deployment = () => ZooKeeperEnsemble.DeployNew( new ZooKeeperEnsembleSettings { InstancesPorts = new List <int> { port } }, log); deployment.Should().Throw <Exception>(); } finally { listener.Stop(); } }
public void Should_return_ConnectFailure_code_when_server_does_not_listen_on_needed_port() { var response = Send(Request.Get($"http://localhost:{FreeTcpPortFinder.GetFreePort()}/")); response.Code.Should().Be(ResponseCode.ConnectFailure); }