Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gladysheva committed Feb 13, 2024
1 parent ea69c19 commit 8df5ca2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ public ApplicationWithReplicas(
public void Update(out bool appExists)
{
appExists = true;

if (isDisposed)
return;

try
{
var applicationExists = zooKeeperClient.Exists(new ExistsRequest(applicationNodePath) {Watcher = existsWatcher});
if (!applicationExists.IsSuccessful)
{
return;
}

if (applicationExists.Stat == null)
{
Expand All @@ -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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ private readonly ConcurrentDictionary<string, Lazy<VersionedContainer<Environmen
private readonly AdHocNodeWatcher existsWatcher;
private readonly AtomicBoolean isDisposed = new AtomicBoolean(false);


public EnvironmentsStorage(
IZooKeeperClient zooKeeperClient,
ServiceDiscoveryPathHelper pathHelper,
Expand Down Expand Up @@ -125,7 +124,16 @@ private void Update(string name, VersionedContainer<EnvironmentInfo> 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;

Expand Down

0 comments on commit 8df5ca2

Please sign in to comment.