Created
June 7, 2012 22:01
-
-
Save bbeck/2891890 to your computer and use it in GitHub Desktop.
EnsurePath bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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