我目前有一个设置有一个zookeeper节点和Curator来访问数据。读取数据是通过Curator TreeCache完成的。
我有以下测试:
public void test_callback_successive_changes_success_global_new_version() throws InterruptedException {
ZookeeperTestsHelper.createNewNodeInZookeeperSingleCommand("/my/path/new_node", "some string4", curator);
ZookeeperTestsHelper.createNewNodeInZookeeperSingleCommand("/my/path/new_node", "some string5", curator);
Thread.sleep(1000);
assertThat(<check what events the listener heard>);
}
请注意&#34; new_node&#34;在测试执行之前不存在。
public static void createNewNodeInZookeeperSingleCommand(final String fullPathOfValueInZookeeper, final String valueToSet, final CuratorFramework curator) {
try {
if (curator.checkExists().forPath(fullPathOfValueInZookeeper) != null) {
System.out.println("E: " + valueToSet);
//Node already exists just set it
curator.setData().forPath(fullPathOfValueInZookeeper, valueToSet.getBytes());
} else {
System.out.println("N: " + valueToSet);
//Node needs to be created
curator.create().creatingParentsIfNeeded().forPath(fullPathOfValueInZookeeper, valueToSet.getBytes());
}
} catch (Exception e) {
throw new IllegalStateException("Error", e);
}
}
我期待缓存监听器首先会听到节点添加的事件&#34;某些字符串4&#34;然后听到另一个节点事件更新了&#34;一些字符串5&#34;。
相反,我只接收添加了值&#34的节点的事件;某些字符串5&#34;
查看日志正在执行两个命令。即&#34; N:某些字符串4&#34;和&#34; E:一些字符串5&#34;都记录了。 Zookeeper中的最终值是正确的(&#34;某些字符串5&#34;)但我不明白为什么Curator缓存只能看到一个事件?
答案 0 :(得分:3)
ZooKeeper(或策展人的TreeCache)并不保证您不会错过连续更改的事件。保证是您不会看到与其他客户看到的顺序不同的连续更改。