Reputation: 13
I have written test code about my service. My code looks like below.
Object obj = new Object();
service.add(obj); // zookeeper node created in service.add
Thread.sleep(7000); // wait until it is created
Boolean created = OtherService.pick(a2, a2); // use node date in OtherService
assertThat(created).isTrue();
In this case, i don't want to use Thread.sleep. Is there any way to get an event or callback from TestingServer to test whether node is created?? not using thread.sleep ??
Upvotes: 0
Views: 145
Reputation: 13
I used latch for the synchronization with zookeeper's node creation.
TreeCacheListener listener = (curator, event) -> {
switch (event.getType()) {
case NODE_ADDED:
createdLatch.countDown();
}
};
cache.getListenable().addListener(listener);
Object obj = new Object();
service.add(obj); // node creation by zookeeper
// Wait until Node is created
timing.awaitLatch(createdLatch);
Boolean created = OtherService.pick(a2, a2); // use node date in OtherService
assertThat(created).isTrue();
Upvotes: 1