public void Should_locate_registered_ServiceBeacon_service_with_custom_path_escaper() { var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok"); ZooKeeperClient.Create("/service-discovery/v2/ZGVmYXVsdA==", CreateMode.Persistent); using (var beacon = new ServiceBeacon( ZooKeeperClient, replica, new ServiceBeaconSettings { IterationPeriod = 60.Seconds(), MinimumTimeBetweenIterations = 100.Milliseconds(), ZooKeeperNodesPathEscaper = new CustomPathEscaper() }, Log)) { beacon.Start(); WaitNodeExists("/service-discovery/v2/ZGVmYXVsdA==/dm9zdG9r/aHR0cHM6Ly9naXRodWIuY29tL3Zvc3Rvaw=="); using (var locator = new ServiceLocator( ZooKeeperClient, new ServiceLocatorSettings { ZooKeeperNodesPathEscaper = new CustomPathEscaper() }, Log)) { ShouldLocateImmediately(locator, replica.Environment, replica.Application, replica.Replica); } } }
public void Should_use_default_replica_builder() { CreateEnvironmentNode("default"); using (var beacon = new ServiceBeacon(ZooKeeperClient)) { beacon.Start(); beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout); var builder = ReplicaInfoBuilder.Build(null, true); var path = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance) .BuildReplicaPath(builder.Environment, builder.Application, builder.Replica); var data = ZooKeeperClient.GetData(path).Data; var dict = ReplicaNodeDataSerializer.Deserialize(builder.Environment, builder.Application, builder.Replica, data).Properties; dict[ReplicaInfoKeys.Application].Should().Be(builder.Application); } }
public void Should_not_throw_if_someone_else_dispose_zookeeper_client_before_start() { var disposedClient = GetZooKeeperClient(); disposedClient.Dispose(); var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok"); var t = Task.Run( () => { using (var beacon = new ServiceBeacon(disposedClient, replica, null, Log)) { beacon.Start(); } }); t.ShouldCompleteIn(DefaultTimeout); }
public void Should_not_throw_if_someone_else_dispose_zookeeper_client_after_start() { var disposedClient = GetZooKeeperClient(); var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok"); CreateEnvironmentNode(replica.Environment); using (var beacon = new ServiceBeacon(disposedClient, replica, null, Log)) { ReplicaRegistered(replica).Should().BeFalse(); beacon.Start(); beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout); ReplicaRegistered(replica).Should().BeTrue(); disposedClient.Dispose(); beacon.Stop(); } }
public void Should_use_replica_builder() { var url = "https://github.com/vostok"; CreateEnvironmentNode("default"); using (var beacon = new ServiceBeacon( ZooKeeperClient, setup => setup.SetUrl(new Uri(url)).SetApplication("test"))) { beacon.Start(); beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout); var path = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance) .BuildReplicaPath("default", "test", url); var data = ZooKeeperClient.GetData(path).Data; var dict = ReplicaNodeDataSerializer.Deserialize("default", "test", url, data).Properties; dict[ReplicaInfoKeys.Replica].Should().Be(url); dict[ReplicaInfoKeys.Application].Should().Be("test"); } }
public void Start_should_run_iterations_loop() { var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok"); var calls = 0; var client = Substitute.For <IZooKeeperClient>(); client.OnConnectionStateChanged.Returns(new CachingObservable <ConnectionState>(ConnectionState.Connected)); client.ExistsAsync(Arg.Any <ExistsRequest>()) .Returns( c => { Log.Info($"{c.Args()[0]}"); Interlocked.Increment(ref calls); return(Task.FromResult(ExistsResult.Successful("", new NodeStat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)))); }); client.DeleteAsync(Arg.Any <DeleteRequest>()).Returns(Task.FromResult(DeleteResult.Successful(""))); var settings = new ServiceBeaconSettings { IterationPeriod = 200.Milliseconds(), MinimumTimeBetweenIterations = 0.Milliseconds() }; using (var beacon = new ServiceBeacon(client, replica, settings, Log)) { beacon.Start(); Thread.Sleep((4 * 200).Milliseconds()); beacon.Stop(); } // One call for environment, one for node. calls.Should().BeInRange(2 * 2, 2 * 10); }
private void SetUpServices(IAppBuilder appBuilder, Container container) { var log = container.GetInstance <ILog>(); var serviceSettings = container.GetInstance <IServiceSettings>(); ProcessPriorityHelper.SetMemoryPriority(ProcessMemoryPriority.Normal, log); ProcessPriorityHelper.SetProcessPriorityClass(ProcessPriorityClass.Normal, log); ThreadPoolUtility.SetUp(log, serviceSettings.GetThreadMultiplier()); var serviceBeacon = new ServiceBeacon(log, serviceSettings.GetPort()); serviceBeacon.Start(); var metricsWorker = container.GetInstance <MetricsWorker>(); metricsWorker.Start(); appBuilder.OnDisposing( () => { serviceBeacon.Stop(); metricsWorker.Stop(); }); }