private ServiceBeacon CreateBeacon(IZooKeeperClient zooKeeperClient, BuildContext context) { var settings = new ServiceBeaconSettings(); if (registrationDeniedFromNonActiveDatacenters) { settings.RegistrationAllowedProvider = LocalDatacenterIsActive(context.Datacenters); } settingsCustomization.Customize(settings); return(new ServiceBeacon( zooKeeperClient, s => { s.SetProperty(WellKnownApplicationIdentityProperties.Project, context.ApplicationIdentity.Project); s.SetProperty(WellKnownApplicationIdentityProperties.Subproject, context.ApplicationIdentity.Subproject); s.SetProperty(WellKnownApplicationIdentityProperties.Environment, context.ApplicationIdentity.Environment); s.SetProperty(WellKnownApplicationIdentityProperties.Application, context.ApplicationIdentity.Application); s.SetProperty(WellKnownApplicationIdentityProperties.Instance, context.ApplicationIdentity.Instance); replicaInfoCustomization.Customize(s); }, settings, context.Log)); }
protected ServiceBeacon GetServiceBeacon(ReplicaInfo replica, ZooKeeperClient client = null, Func <bool> registrationAllowedProvider = null) { client = client ?? ZooKeeperClient; var settings = new ServiceBeaconSettings { IterationPeriod = 60.Seconds(), MinimumTimeBetweenIterations = 100.Milliseconds(), RegistrationAllowedProvider = registrationAllowedProvider }; return(new ServiceBeacon(client, replica, settings, Log)); }
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); }