CuratorDatabase { List<String> getChildren(Path path) { return getSession().getChildren(path); } CuratorDatabase(Curator curator, Path root, boolean useCache); List<HostName> cluster(); Lock lock(Path path, Duration timeout); CuratorTransaction newCuratorTransactionIn(NestedTransaction transaction);  }
@Test public void testTransactionsIncreaseCounter() throws Exception { MockCurator curator = new MockCurator(); CuratorDatabase database = new CuratorDatabase(curator, Path.fromString("/"), true); assertEquals(0L, (long)curator.counter("/changeCounter").get().get().postValue()); commitCreate("/1", database); commitCreate("/2", database); commitCreate("/1/1", database); commitCreate("/2/1", database); assertEquals(8L, (long)curator.counter("/changeCounter").get().get().postValue()); List<String> children1Call1 = database.getChildren(Path.fromString("/1")); List<String> children1Call2 = database.getChildren(Path.fromString("/1")); assertTrue("We reuse cached data when there are no commits", children1Call1 == children1Call2); assertEquals(1, database.getChildren(Path.fromString("/2")).size()); commitCreate("/2/2", database); List<String> children1Call3 = database.getChildren(Path.fromString("/1")); assertEquals(2, database.getChildren(Path.fromString("/2")).size()); assertFalse("We do not reuse cached data in different parts of the tree when there are commits", children1Call3 == children1Call2); }
@Test public void testTransactionsWithDeactivatedCache() throws Exception { MockCurator curator = new MockCurator(); CuratorDatabase database = new CuratorDatabase(curator, Path.fromString("/"), false); assertEquals(0L, (long)curator.counter("/changeCounter").get().get().postValue()); commitCreate("/1", database); commitCreate("/2", database); commitCreate("/1/1", database); commitCreate("/2/1", database); assertEquals(8L, (long)curator.counter("/changeCounter").get().get().postValue()); List<String> children1Call0 = database.getChildren(Path.fromString("/1")); List<String> children1Call1 = database.getChildren(Path.fromString("/1")); List<String> children1Call2 = database.getChildren(Path.fromString("/1")); assertTrue("No cache, no reused data", children1Call1 != children1Call2); }