}
@Test
public void testCreateModes() throws Exception
{
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
client.start();
try
{
byte[] writtenBytes = {1, 2, 3};
client.create().forPath("/test", writtenBytes); // should be persistent
client.close();
client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
client.start();
byte[] readBytes = client.getData().forPath("/test");
Assert.assertEquals(writtenBytes, readBytes);
client.create().withMode(CreateMode.EPHEMERAL).forPath("/ghost", writtenBytes);
client.close();
client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
client.start();
readBytes = client.getData().forPath("/test");
Assert.assertEquals(writtenBytes, readBytes);
Stat stat = client.checkExists().forPath("/ghost");
Assert.assertNull(stat);
String realPath = client.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/pseq", writtenBytes);
Assert.assertNotSame(realPath, "/pseq");
client.close();
client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
client.start();
readBytes = client.getData().forPath(realPath);
Assert.assertEquals(writtenBytes, readBytes);
realPath = client.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/eseq", writtenBytes);
Assert.assertNotSame(realPath, "/eseq");
client.close();
client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
client.start();
stat = client.checkExists().forPath(realPath);
Assert.assertNull(stat);
}
finally
{
client.close();
}
}