protected override void DoSubscribe(string groupPath, INotifyListener listener) { _zkClient.EnsurePathRecursive(groupPath, false); ConcurrentDictionary <INotifyListener, ChildListener> listeners; if (_zkListeners.TryGetValue(groupPath, out listeners) == false) { listeners = _zkListeners.GetOrAdd(groupPath, new ConcurrentDictionary <INotifyListener, ChildListener>()); } ChildListener childListener; if (listeners.TryGetValue(listener, out childListener) == false) { childListener = new ChildListener(_zkClient, groupPath); childListener.OnMetadataChanged += (metas) => this.Notify(groupPath, listener, metas); listeners.TryAdd(listener, childListener); } var children = _zkClient.SubscribeChildListener(childListener); var metadatas = children.Select(child => _zkClient.GetData(groupPath + "/" + child, false, null).ToMetadata()).ToList(); this.Notify(groupPath, listener, metadatas); }
public override void OnChildrenChanged(List <string> children) { System.Console.WriteLine("ChildListener.OnChildrenChanged = [{0}]", string.Join(",", children)); var metadataBytes = children.Select(child => _zkClient.GetData(child, false, null)); this.Metadatas = metadataBytes.Select(bytes => bytes.ToMetadata()).ToList(); this.OnMetadataChangedHandle(this.Metadatas); }
public void GetData_should_not_add_watch_triggered_by_Created() { var path = "/watch/new"; var watcher = new TestWatcher(); client.GetData(new GetDataRequest(path) { Watcher = watcher }).Status.Should().Be(ZooKeeperStatus.NodeNotFound); client.Create(new CreateRequest(path, CreateMode.Persistent)).EnsureSuccess(); watcher.ShouldNotBeTriggered(); }
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 Start_should_create_node_with_replica_properties() { var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok"); replica.SetProperty("key", "value"); CreateEnvironmentNode(replica.Environment); using (var beacon = GetServiceBeacon(replica)) { beacon.Start(); beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout); var path = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance) .BuildReplicaPath(replica.Environment, replica.Application, replica.Replica); var data = ZooKeeperClient.GetData(path).Data; var dict = ReplicaNodeDataSerializer.Deserialize(replica.Environment, replica.Application, replica.Replica, data).Properties; dict["key"].Should().Be("value"); } }
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"); } }