Created
February 22, 2012 19:22
-
-
Save itissid/1886760 to your computer and use it in GitHub Desktop.
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
@Test | |
public void testScratch() throws Exception{ | |
ZookeeperConfig config = new ZookeeperConfig(); | |
config.port = server.getPort(); | |
//Gets a client instance from the builder | |
CuratorFramework cf1 = config.connect(); | |
cf1.start(); | |
final AtomicInteger i =new AtomicInteger(); | |
cf1.getCuratorListenable().addListener(new CuratorListener() { | |
@Override | |
public void eventReceived(CuratorFramework client, CuratorEvent event) | |
throws Exception { | |
System.out.println("*****Got an event in listener 1: "+event.getType()+" :: Path: "+event.getPath()); | |
if(event.getPath()!=null){ | |
//Set a data watch again..? | |
System.out.println("**Setting the watch again"); | |
client.getData().watched().forPath(event.getPath()); | |
i.incrementAndGet();//Increments the integer atomically | |
} | |
} | |
}); | |
//cf1.checkExists().watched().forPath("/FooBar"); | |
//A watched on check exists | |
System.out.println("**Setting watch for the data node 2"); | |
cf1.checkExists().watched().forPath("/FooBar2"); | |
//cf1.().watched().forPath("/FooBar2"); | |
cf1.create().forPath("/FooBar"); | |
System.out.println("**Creating the data node 2"); | |
cf1.create().forPath("/FooBar2"); | |
for(int j =0 ; j< 1000; j++) | |
cf1.setData().forPath("/FooBar2", "Blah dede blah".getBytes()); | |
System.out.println("**Count: "+i.get()); | |
/*****Fails... Why?*****/ | |
Assert.assertEquals(i.get(), 999); | |
cf1.close(); | |
System.out.println("Done!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment