Skip to content

Commit

Permalink
Ensure that we don't put watchers on overlapping paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmarion committed Jan 15, 2025
1 parent fb6aaa7 commit 89ccf24
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ public void addZooCacheWatcher(ZooCacheWatcher watcher) {

// Visible for testing
protected void setupWatchers(List<String> pathsToWatch) {
for (String left : pathsToWatch) {
for (String right : pathsToWatch) {
if (left != right && left.contains(right)) {
throw new IllegalArgumentException(
"Overlapping paths found in paths to watch: " + pathsToWatch);
}
}
}

try {
for (String path : pathsToWatch) {
watchedPaths.add(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
Expand Down Expand Up @@ -86,6 +87,12 @@ public void setUp() {
zc = new TestZooCache(zk, List.of(root));
}

@Test
public void testOverlappingPaths() {
assertThrows(IllegalArgumentException.class,
() -> new ZooCache(zk, List.of(root, root + "/localhost:9995")));
}

@Test
public void testGet() throws Exception {
testGet(false);
Expand Down

0 comments on commit 89ccf24

Please sign in to comment.