diff --git a/Vostok.ServiceDiscovery.Tests/ServiceLocatorStorage/EnvironmentsStorage_Tests.cs b/Vostok.ServiceDiscovery.Tests/ServiceLocatorStorage/EnvironmentsStorage_Tests.cs index 139897d..20fae4e 100644 --- a/Vostok.ServiceDiscovery.Tests/ServiceLocatorStorage/EnvironmentsStorage_Tests.cs +++ b/Vostok.ServiceDiscovery.Tests/ServiceLocatorStorage/EnvironmentsStorage_Tests.cs @@ -182,13 +182,13 @@ public void Should_not_delete_environment_from_cache_when_observation_of_deleted CreateEnvironmentNode("default", "parent"); var expectedInfo = new EnvironmentInfo("default", "parent", null); - ShouldReturn(storage, "default", expectedInfo); + ShouldReturnImmediately(storage, "default", expectedInfo); Ensemble.Stop(); storage.UpdateAll(); storage.Contains("default").Should().BeTrue(); - ShouldReturn(storage, "default", expectedInfo); + ShouldReturnImmediately(storage, "default", expectedInfo); } } @@ -200,14 +200,14 @@ public void Should_delete_environment_from_cache_if_node_was_deleted_when_observ CreateEnvironmentNode("default", "parent"); var expectedInfo = new EnvironmentInfo("default", "parent", null); - storage.Get("default").Should().BeEquivalentTo(expectedInfo); + ShouldReturnImmediately(storage, "default", expectedInfo); DeleteEnvironmentNode("default"); storage.UpdateAll(); storage.Contains("default").Should().BeFalse(); CreateEnvironmentNode("default", "parent"); - storage.Get("default").Should().BeEquivalentTo(expectedInfo); + ShouldReturnImmediately(storage, "default", expectedInfo); } } diff --git a/Vostok.ServiceDiscovery/ServiceLocatorStorage/ApplicationWithReplicas.cs b/Vostok.ServiceDiscovery/ServiceLocatorStorage/ApplicationWithReplicas.cs index abad5fc..02d1170 100644 --- a/Vostok.ServiceDiscovery/ServiceLocatorStorage/ApplicationWithReplicas.cs +++ b/Vostok.ServiceDiscovery/ServiceLocatorStorage/ApplicationWithReplicas.cs @@ -60,7 +60,7 @@ public ApplicationWithReplicas( public void Update(out bool appExists) { appExists = true; - + if (isDisposed) return; @@ -68,9 +68,7 @@ public void Update(out bool appExists) { var applicationExists = zooKeeperClient.Exists(new ExistsRequest(applicationNodePath) {Watcher = existsWatcher}); if (!applicationExists.IsSuccessful) - { return; - } if (applicationExists.Stat == null) { @@ -83,7 +81,11 @@ public void Update(out bool appExists) { var applicationData = zooKeeperClient.GetData(new GetDataRequest(applicationNodePath) {Watcher = nodeWatcher}); if (applicationData.Status == ZooKeeperStatus.NodeNotFound) + { + appExists = false; Clear(); + } + if (!applicationData.IsSuccessful) return; @@ -96,7 +98,11 @@ public void Update(out bool appExists) { var applicationChildren = zooKeeperClient.GetChildren(new GetChildrenRequest(applicationNodePath) {Watcher = nodeWatcher}); if (applicationChildren.Status == ZooKeeperStatus.NodeNotFound) + { + appExists = false; Clear(); + } + if (!applicationChildren.IsSuccessful) return; diff --git a/Vostok.ServiceDiscovery/ServiceLocatorStorage/EnvironmentsStorage.cs b/Vostok.ServiceDiscovery/ServiceLocatorStorage/EnvironmentsStorage.cs index d1d4b15..97f608d 100644 --- a/Vostok.ServiceDiscovery/ServiceLocatorStorage/EnvironmentsStorage.cs +++ b/Vostok.ServiceDiscovery/ServiceLocatorStorage/EnvironmentsStorage.cs @@ -26,7 +26,6 @@ private readonly ConcurrentDictionary container) var environmentData = zooKeeperClient.GetData(new GetDataRequest(environmentPath) {Watcher = nodeWatcher}); if (environmentData.Status == ZooKeeperStatus.NodeNotFound) + { + if (!observeNonExistentEnvironments) + { + environments.TryRemove(name, out _); + return; + } + container.Clear(); + } + if (!environmentData.IsSuccessful) return;