Skip to content

Instantly share code, notes, and snippets.

@bbeck
Created June 7, 2012 22:01
Show Gist options
  • Save bbeck/2891890 to your computer and use it in GitHub Desktop.
Save bbeck/2891890 to your computer and use it in GitHub Desktop.
EnsurePath bug
import com.google.common.io.Closeables;
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.retry.RetryNTimes;
import com.netflix.curator.test.TestingServer;
import com.netflix.curator.utils.EnsurePath;
public class EnsurePathBug {
public static void main(String[] args) throws Exception {
int iteration = 0;
while (++iteration > 0) {
long startTime = System.currentTimeMillis();
System.out.println();
System.out.println("========================================================================");
System.out.println("STARTING ITERATION #" + iteration);
System.out.println("========================================================================");
EnsurePathBug bug = null;
try {
bug = new EnsurePathBug();
bug.run();
} finally {
if (bug != null) {
bug.cleanup();
}
double duration = (System.currentTimeMillis() - startTime) / 1000.;
System.out.println("========================================================================");
System.out.println("FINISHED ITERATION #" + iteration + " (" + duration + "s)");
System.out.println("========================================================================");
System.out.println();
}
}
}
private TestingServer _server;
private CuratorFramework _curator;
private EnsurePath _ensurePath;
public EnsurePathBug() throws Exception {
_server = new TestingServer();
_curator = CuratorFrameworkFactory.newClient(_server.getConnectString(), new RetryNTimes(0, 0));
_curator.start();
_ensurePath = _curator.newNamespaceAwareEnsurePath("/foo");
}
public void cleanup() throws Exception {
_ensurePath = null;
Closeables.closeQuietly(_curator);
Closeables.closeQuietly(_server);
}
public void run() throws Exception {
boolean done = false;
long startTime = System.currentTimeMillis();
while (!done) {
try {
_ensurePath.ensure(_curator.getZookeeperClient());
done = true;
} catch (Exception e) {
e.printStackTrace();
}
}
double duration = (System.currentTimeMillis() - startTime) / 1000.;
System.out.println("Ensured path in " + duration + "s");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment