@Test
public void testWatchPrefix() throws Exception {
String key = prefix + "/watch";
EtcdResult result = this.client.set(key + "/f2", "f2");
Assert.assertTrue(!result.isError());
Assert.assertNotNull(result.node);
Assert.assertEquals("f2", result.node.value);
ListenableFuture<EtcdResult> watchFuture = this.client.watch(key,
result.node.modifiedIndex + 1,
true);
try {
EtcdResult watchResult = watchFuture
.get(100, TimeUnit.MILLISECONDS);
Assert.fail("Subtree watch fired unexpectedly: " + watchResult);
} catch (TimeoutException e) {
// Expected
}
Assert.assertFalse(watchFuture.isDone());
result = this.client.set(key + "/f1", "f1");
Assert.assertTrue(!result.isError());
Assert.assertNotNull(result.node);
Assert.assertEquals("f1", result.node.value);
EtcdResult watchResult = watchFuture.get(100, TimeUnit.MILLISECONDS);
Assert.assertNotNull(watchResult);
Assert.assertTrue(!watchResult.isError());
Assert.assertNotNull(watchResult.node);
{
Assert.assertEquals(key + "/f1", watchResult.node.key);
Assert.assertEquals("f1", watchResult.node.value);