summaryrefslogtreecommitdiff
path: root/zookeeper-server/src/test/java/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'zookeeper-server/src/test/java/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java')
-rw-r--r--zookeeper-server/src/test/java/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java54
1 files changed, 24 insertions, 30 deletions
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java
index 33e0f128c..005b525f5 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/WatchEventWhenAutoResetTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,30 +18,30 @@
package org.apache.zookeeper.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher.Event.EventType;
+import org.apache.zookeeper.ZKTestCase;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
-import org.apache.zookeeper.ZKTestCase;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public class WatchEventWhenAutoResetTest extends ZKTestCase {
- protected static final Logger LOG = LoggerFactory
- .getLogger(WatchEventWhenAutoResetTest.class);
+
+ protected static final Logger LOG = LoggerFactory.getLogger(WatchEventWhenAutoResetTest.class);
// waiting time for expected condition
private static final int TIMEOUT = 30000;
@@ -49,7 +49,8 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
private EventsWatcher watcher;
private ZooKeeper zk1, zk2;
- static public class EventsWatcher extends CountdownWatcher {
+ public static class EventsWatcher extends CountdownWatcher {
+
private LinkedBlockingQueue<WatchedEvent> dataEvents = new LinkedBlockingQueue<WatchedEvent>();
@Override
@@ -66,18 +67,17 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
public void assertEvent(long timeout, EventType eventType) {
try {
- WatchedEvent event = dataEvents.poll(timeout,
- TimeUnit.MILLISECONDS);
- Assert.assertNotNull("do not receive a " + eventType, event);
- Assert.assertEquals(eventType, event.getType());
+ WatchedEvent event = dataEvents.poll(timeout, TimeUnit.MILLISECONDS);
+ assertNotNull("do not receive a " + eventType, event);
+ assertEquals(eventType, event.getType());
} catch (InterruptedException e) {
LOG.warn("ignoring interrupt during EventsWatcher assertEvent");
}
}
+
}
- private ZooKeeper createClient(QuorumUtil qu, int id, EventsWatcher watcher)
- throws IOException {
+ private ZooKeeper createClient(QuorumUtil qu, int id, EventsWatcher watcher) throws IOException {
String hostPort = "127.0.0.1:" + qu.getPeer(id).clientPort;
ZooKeeper zk = new ZooKeeper(hostPort, TIMEOUT, watcher);
try {
@@ -85,7 +85,7 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
} catch (InterruptedException e) {
// ignoring the interrupt
} catch (TimeoutException e) {
- Assert.fail("can not connect to " + hostPort);
+ fail("can not connect to " + hostPort);
}
return zk;
}
@@ -128,8 +128,7 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
@Test
public void testNodeDataChanged() throws Exception {
String path = "/test-changed";
- zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
+ zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Stat stat1 = zk1.exists(path, watcher);
qu.shutdown(1);
zk2.setData(path, new byte[2], stat1.getVersion());
@@ -144,8 +143,7 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
zk1.exists(path, watcher);
qu.shutdown(1);
- zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
+ zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
qu.start(1);
watcher.waitForConnected(TIMEOUT * 1000L);
watcher.assertEvent(TIMEOUT, EventType.NodeCreated);
@@ -155,8 +153,7 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
public void testNodeDeleted() throws Exception {
String path = "/test-deleted";
- zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
+ zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk1.getData(path, watcher, null);
qu.shutdown(1);
zk2.delete(path, -1);
@@ -164,8 +161,7 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
watcher.waitForConnected(TIMEOUT * 1000L);
watcher.assertEvent(TIMEOUT, EventType.NodeDeleted);
- zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
+ zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk1.exists(path, watcher);
qu.shutdown(1);
zk2.delete(path, -1);
@@ -173,8 +169,7 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
watcher.waitForConnected(TIMEOUT * 1000L);
watcher.assertEvent(TIMEOUT, EventType.NodeDeleted);
- zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
+ zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk1.getChildren(path, watcher);
qu.shutdown(1);
zk2.delete(path, -1);
@@ -187,15 +182,14 @@ public class WatchEventWhenAutoResetTest extends ZKTestCase {
public void testNodeChildrenChanged() throws Exception {
String path = "/test-children-changed";
- zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
- CreateMode.PERSISTENT);
+ zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk1.getChildren(path, watcher);
qu.shutdown(1);
- zk2.create(path + "/children-1", new byte[2],
- ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+ zk2.create(path + "/children-1", new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
qu.start(1);
watcher.waitForConnected(TIMEOUT * 1000L);
watcher.assertEvent(TIMEOUT, EventType.NodeChildrenChanged);
}
+
}