You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ma...@apache.org on 2010/03/31 06:26:30 UTC
svn commit: r929377 [4/4] - in /hadoop/zookeeper/trunk: ./
src/java/test/org/apache/zookeeper/server/
src/java/test/org/apache/zookeeper/server/quorum/
src/java/test/org/apache/zookeeper/test/
Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java Wed Mar 31 04:26:29 2010
@@ -33,6 +33,8 @@ import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooDefs.Ids;
+import org.junit.Assert;
+import org.junit.Test;
public class WatcherFuncTest extends ClientBase {
private static class SimpleWatcher implements Watcher {
@@ -57,7 +59,7 @@ public class WatcherFuncTest extends Cli
try {
events.put(event);
} catch (InterruptedException e) {
- assertTrue("interruption unexpected", false);
+ Assert.assertTrue("interruption unexpected", false);
}
}
public void verify(List<EventType> expected) throws InterruptedException{
@@ -66,10 +68,10 @@ public class WatcherFuncTest extends Cli
while (count < expected.size()
&& (event = events.poll(30, TimeUnit.SECONDS)) != null)
{
- assertEquals(expected.get(count), event.getType());
+ Assert.assertEquals(expected.get(count), event.getType());
count++;
}
- assertEquals(expected.size(), count);
+ Assert.assertEquals(expected.size(), count);
events.clear();
}
}
@@ -83,8 +85,7 @@ public class WatcherFuncTest extends Cli
private List<EventType> expected;
@Override
- protected void setUp() throws Exception {
- LOG.info("STARTING " + getName());
+ public void setUp() throws Exception {
super.setUp();
client_latch = new CountDownLatch(1);
@@ -97,12 +98,12 @@ public class WatcherFuncTest extends Cli
expected = new ArrayList<EventType>();
}
+
@Override
- protected void tearDown() throws Exception {
+ public void tearDown() throws Exception {
client.close();
lsnr.close();
super.tearDown();
- LOG.info("FINISHED " + getName());
}
protected ZooKeeper createClient(Watcher watcher, CountDownLatch latch)
@@ -110,7 +111,7 @@ public class WatcherFuncTest extends Cli
{
ZooKeeper zk = new ZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
if(!latch.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)){
- fail("Unable to connect to server");
+ Assert.fail("Unable to connect to server");
}
return zk;
}
@@ -119,11 +120,13 @@ public class WatcherFuncTest extends Cli
lsnr_dwatch.verify(expected);
expected.clear();
}
+
+ @Test
public void testExistsSync()
throws IOException, InterruptedException, KeeperException
{
- assertNull(lsnr.exists("/foo", true));
- assertNull(lsnr.exists("/foo/bar", true));
+ Assert.assertNull(lsnr.exists("/foo", true));
+ Assert.assertNull(lsnr.exists("/foo/bar", true));
client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
expected.add(EventType.NodeCreated);
@@ -132,25 +135,25 @@ public class WatcherFuncTest extends Cli
verify();
- assertNotNull(lsnr.exists("/foo", true));
- assertNotNull(lsnr.exists("/foo/bar", true));
+ Assert.assertNotNull(lsnr.exists("/foo", true));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", true));
try {
- assertNull(lsnr.exists("/car", true));
+ Assert.assertNull(lsnr.exists("/car", true));
client.setData("/car", "missing".getBytes(), -1);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/car", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/car", e.getPath());
}
try {
- assertNull(lsnr.exists("/foo/car", true));
+ Assert.assertNull(lsnr.exists("/foo/car", true));
client.setData("/foo/car", "missing".getBytes(), -1);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo/car", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo/car", e.getPath());
}
client.setData("/foo", "parent".getBytes(), -1);
@@ -160,8 +163,8 @@ public class WatcherFuncTest extends Cli
verify();
- assertNotNull(lsnr.exists("/foo", true));
- assertNotNull(lsnr.exists("/foo/bar", true));
+ Assert.assertNotNull(lsnr.exists("/foo", true));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", true));
client.delete("/foo/bar", -1);
expected.add(EventType.NodeDeleted);
@@ -171,28 +174,29 @@ public class WatcherFuncTest extends Cli
verify();
}
+ @Test
public void testGetDataSync()
throws IOException, InterruptedException, KeeperException
{
try {
lsnr.getData("/foo", true, null);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo", e.getPath());
}
try {
lsnr.getData("/foo/bar", true, null);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo/bar", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo/bar", e.getPath());
}
client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- assertNotNull(lsnr.getData("/foo", true, null));
+ Assert.assertNotNull(lsnr.getData("/foo", true, null));
client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- assertNotNull(lsnr.getData("/foo/bar", true, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", true, null));
client.setData("/foo", "parent".getBytes(), -1);
expected.add(EventType.NodeDataChanged);
@@ -201,8 +205,8 @@ public class WatcherFuncTest extends Cli
verify();
- assertNotNull(lsnr.getData("/foo", true, null));
- assertNotNull(lsnr.getData("/foo/bar", true, null));
+ Assert.assertNotNull(lsnr.getData("/foo", true, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", true, null));
client.delete("/foo/bar", -1);
expected.add(EventType.NodeDeleted);
@@ -212,40 +216,41 @@ public class WatcherFuncTest extends Cli
verify();
}
+ @Test
public void testGetChildrenSync()
throws IOException, InterruptedException, KeeperException
{
try {
lsnr.getChildren("/foo", true);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo", e.getPath());
}
try {
lsnr.getChildren("/foo/bar", true);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo/bar", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo/bar", e.getPath());
}
client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- assertNotNull(lsnr.getChildren("/foo", true));
+ Assert.assertNotNull(lsnr.getChildren("/foo", true));
client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
expected.add(EventType.NodeChildrenChanged); // /foo
- assertNotNull(lsnr.getChildren("/foo/bar", true));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", true));
client.setData("/foo", "parent".getBytes(), -1);
client.setData("/foo/bar", "child".getBytes(), -1);
- assertNotNull(lsnr.exists("/foo", true));
+ Assert.assertNotNull(lsnr.exists("/foo", true));
- assertNotNull(lsnr.getChildren("/foo", true));
- assertNotNull(lsnr.getChildren("/foo/bar", true));
+ Assert.assertNotNull(lsnr.getChildren("/foo", true));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", true));
client.delete("/foo/bar", -1);
expected.add(EventType.NodeDeleted); // /foo/bar childwatch
@@ -256,6 +261,7 @@ public class WatcherFuncTest extends Cli
verify();
}
+ @Test
public void testExistsSyncWObj()
throws IOException, InterruptedException, KeeperException
{
@@ -266,13 +272,13 @@ public class WatcherFuncTest extends Cli
List<EventType> e2 = new ArrayList<EventType>();
- assertNull(lsnr.exists("/foo", true));
- assertNull(lsnr.exists("/foo", w1));
+ Assert.assertNull(lsnr.exists("/foo", true));
+ Assert.assertNull(lsnr.exists("/foo", w1));
- assertNull(lsnr.exists("/foo/bar", w2));
- assertNull(lsnr.exists("/foo/bar", w3));
- assertNull(lsnr.exists("/foo/bar", w3));
- assertNull(lsnr.exists("/foo/bar", w4));
+ Assert.assertNull(lsnr.exists("/foo/bar", w2));
+ Assert.assertNull(lsnr.exists("/foo/bar", w3));
+ Assert.assertNull(lsnr.exists("/foo/bar", w3));
+ Assert.assertNull(lsnr.exists("/foo/bar", w4));
client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
expected.add(EventType.NodeCreated);
@@ -288,12 +294,12 @@ public class WatcherFuncTest extends Cli
e2.clear();
// default not registered
- assertNotNull(lsnr.exists("/foo", w1));
+ Assert.assertNotNull(lsnr.exists("/foo", w1));
- assertNotNull(lsnr.exists("/foo/bar", w2));
- assertNotNull(lsnr.exists("/foo/bar", w3));
- assertNotNull(lsnr.exists("/foo/bar", w4));
- assertNotNull(lsnr.exists("/foo/bar", w4));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", w3));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
client.setData("/foo", "parent".getBytes(), -1);
expected.add(EventType.NodeDataChanged);
@@ -308,14 +314,14 @@ public class WatcherFuncTest extends Cli
expected.clear();
e2.clear();
- assertNotNull(lsnr.exists("/foo", true));
- assertNotNull(lsnr.exists("/foo", w1));
- assertNotNull(lsnr.exists("/foo", w1));
-
- assertNotNull(lsnr.exists("/foo/bar", w2));
- assertNotNull(lsnr.exists("/foo/bar", w2));
- assertNotNull(lsnr.exists("/foo/bar", w3));
- assertNotNull(lsnr.exists("/foo/bar", w4));
+ Assert.assertNotNull(lsnr.exists("/foo", true));
+ Assert.assertNotNull(lsnr.exists("/foo", w1));
+ Assert.assertNotNull(lsnr.exists("/foo", w1));
+
+ Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", w2));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", w3));
+ Assert.assertNotNull(lsnr.exists("/foo/bar", w4));
client.delete("/foo/bar", -1);
expected.add(EventType.NodeDeleted);
@@ -332,6 +338,7 @@ public class WatcherFuncTest extends Cli
}
+ @Test
public void testGetDataSyncWObj()
throws IOException, InterruptedException, KeeperException
{
@@ -344,27 +351,27 @@ public class WatcherFuncTest extends Cli
try {
lsnr.getData("/foo", w1, null);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo", e.getPath());
}
try {
lsnr.getData("/foo/bar", w2, null);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo/bar", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo/bar", e.getPath());
}
client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- assertNotNull(lsnr.getData("/foo", true, null));
- assertNotNull(lsnr.getData("/foo", w1, null));
+ Assert.assertNotNull(lsnr.getData("/foo", true, null));
+ Assert.assertNotNull(lsnr.getData("/foo", w1, null));
client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- assertNotNull(lsnr.getData("/foo/bar", w2, null));
- assertNotNull(lsnr.getData("/foo/bar", w3, null));
- assertNotNull(lsnr.getData("/foo/bar", w4, null));
- assertNotNull(lsnr.getData("/foo/bar", w4, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
client.setData("/foo", "parent".getBytes(), -1);
expected.add(EventType.NodeDataChanged);
@@ -379,12 +386,12 @@ public class WatcherFuncTest extends Cli
expected.clear();
e2.clear();
- assertNotNull(lsnr.getData("/foo", true, null));
- assertNotNull(lsnr.getData("/foo", w1, null));
- assertNotNull(lsnr.getData("/foo/bar", w2, null));
- assertNotNull(lsnr.getData("/foo/bar", w3, null));
- assertNotNull(lsnr.getData("/foo/bar", w3, null));
- assertNotNull(lsnr.getData("/foo/bar", w4, null));
+ Assert.assertNotNull(lsnr.getData("/foo", true, null));
+ Assert.assertNotNull(lsnr.getData("/foo", w1, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
+ Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
client.delete("/foo/bar", -1);
expected.add(EventType.NodeDeleted);
@@ -400,6 +407,7 @@ public class WatcherFuncTest extends Cli
e2.clear();
}
+ @Test
public void testGetChildrenSyncWObj()
throws IOException, InterruptedException, KeeperException
{
@@ -412,46 +420,46 @@ public class WatcherFuncTest extends Cli
try {
lsnr.getChildren("/foo", true);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo", e.getPath());
}
try {
lsnr.getChildren("/foo/bar", true);
- fail();
+ Assert.fail();
} catch (KeeperException e) {
- assertEquals(KeeperException.Code.NONODE, e.code());
- assertEquals("/foo/bar", e.getPath());
+ Assert.assertEquals(KeeperException.Code.NONODE, e.code());
+ Assert.assertEquals("/foo/bar", e.getPath());
}
client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- assertNotNull(lsnr.getChildren("/foo", true));
- assertNotNull(lsnr.getChildren("/foo", w1));
+ Assert.assertNotNull(lsnr.getChildren("/foo", true));
+ Assert.assertNotNull(lsnr.getChildren("/foo", w1));
client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
expected.add(EventType.NodeChildrenChanged); // /foo
- assertNotNull(lsnr.getChildren("/foo/bar", w2));
- assertNotNull(lsnr.getChildren("/foo/bar", w2));
- assertNotNull(lsnr.getChildren("/foo/bar", w3));
- assertNotNull(lsnr.getChildren("/foo/bar", w4));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", w3));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
client.setData("/foo", "parent".getBytes(), -1);
client.setData("/foo/bar", "child".getBytes(), -1);
- assertNotNull(lsnr.exists("/foo", true));
- assertNotNull(lsnr.exists("/foo", w1));
- assertNotNull(lsnr.exists("/foo", true));
- assertNotNull(lsnr.exists("/foo", w1));
-
- assertNotNull(lsnr.getChildren("/foo", true));
- assertNotNull(lsnr.getChildren("/foo", w1));
- assertNotNull(lsnr.getChildren("/foo/bar", w2));
- assertNotNull(lsnr.getChildren("/foo/bar", w3));
- assertNotNull(lsnr.getChildren("/foo/bar", w4));
- assertNotNull(lsnr.getChildren("/foo/bar", w4));
+ Assert.assertNotNull(lsnr.exists("/foo", true));
+ Assert.assertNotNull(lsnr.exists("/foo", w1));
+ Assert.assertNotNull(lsnr.exists("/foo", true));
+ Assert.assertNotNull(lsnr.exists("/foo", w1));
+
+ Assert.assertNotNull(lsnr.getChildren("/foo", true));
+ Assert.assertNotNull(lsnr.getChildren("/foo", w1));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", w2));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", w3));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
+ Assert.assertNotNull(lsnr.getChildren("/foo/bar", w4));
client.delete("/foo/bar", -1);
e2.add(EventType.NodeDeleted); // /foo/bar childwatch
Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java Wed Mar 31 04:26:29 2010
@@ -36,6 +36,7 @@ import org.apache.zookeeper.Watcher.Even
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
import org.junit.Test;
public class WatcherTest extends ClientBase {
@@ -112,13 +113,13 @@ public class WatcherTest extends ClientB
for (int i = 0; i < names.length; i++) {
String name = names[i];
WatchedEvent event = watcher.events.poll(10, TimeUnit.SECONDS);
- assertEquals(name, event.getPath());
- assertEquals(Event.EventType.NodeDataChanged, event.getType());
- assertEquals(Event.KeeperState.SyncConnected, event.getState());
+ Assert.assertEquals(name, event.getPath());
+ Assert.assertEquals(Event.EventType.NodeDataChanged, event.getType());
+ Assert.assertEquals(Event.KeeperState.SyncConnected, event.getState());
event = watcher.events.poll(10, TimeUnit.SECONDS);
- assertEquals(name, event.getPath());
- assertEquals(Event.EventType.NodeDeleted, event.getType());
- assertEquals(Event.KeeperState.SyncConnected, event.getState());
+ Assert.assertEquals(name, event.getPath());
+ Assert.assertEquals(Event.EventType.NodeDeleted, event.getType());
+ Assert.assertEquals(Event.KeeperState.SyncConnected, event.getState());
}
} finally {
if (zk != null) {
@@ -162,19 +163,19 @@ public class WatcherTest extends ClientB
}
startServer();
watches[COUNT/2-1].waitForConnected(60000);
- assertEquals(null, zk.exists("/test", false));
+ Assert.assertEquals(null, zk.exists("/test", false));
Thread.sleep(10);
for(int i = 0; i < COUNT/2; i++) {
- assertEquals("For " + i, 1, watches[i].events.size());
+ Assert.assertEquals("For " + i, 1, watches[i].events.size());
}
for(int i = COUNT/2; i < COUNT; i++) {
if (cbs[i].rc == 0) {
- assertEquals("For " +i, 1, watches[i].events.size());
+ Assert.assertEquals("For " +i, 1, watches[i].events.size());
} else {
- assertEquals("For " +i, 0, watches[i].events.size());
+ Assert.assertEquals("For " +i, 0, watches[i].events.size());
}
}
- assertEquals(COUNT, count[0]);
+ Assert.assertEquals(COUNT, count[0]);
zk.close();
}
@@ -228,7 +229,7 @@ public class WatcherTest extends ClientB
zk.exists("/watchtest/child2", localWatcher);
}
- assertTrue(localWatcher.events.isEmpty());
+ Assert.assertTrue(localWatcher.events.isEmpty());
stopServer();
globalWatcher.waitForDisconnected(3000);
@@ -239,7 +240,7 @@ public class WatcherTest extends ClientB
localWatcher.waitForConnected(500);
}
- assertTrue(localWatcher.events.isEmpty());
+ Assert.assertTrue(localWatcher.events.isEmpty());
zk.setData("/watchtest/child", new byte[1], -1);
zk.create("/watchtest/child2", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
@@ -247,8 +248,8 @@ public class WatcherTest extends ClientB
WatchedEvent e;
if (!ClientCnxn.getDisableAutoResetWatch()) {
e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType());
- assertEquals("/watchtest/child", e.getPath());
+ Assert.assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType());
+ Assert.assertEquals("/watchtest/child", e.getPath());
} else {
// we'll catch this later if it does happen after timeout, so
// why waste the time on poll
@@ -258,8 +259,8 @@ public class WatcherTest extends ClientB
e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
// The create will trigger the get children and the exist
// watches
- assertEquals(EventType.NodeCreated, e.getType());
- assertEquals("/watchtest/child2", e.getPath());
+ Assert.assertEquals(EventType.NodeCreated, e.getType());
+ Assert.assertEquals("/watchtest/child2", e.getPath());
} else {
// we'll catch this later if it does happen after timeout, so
// why waste the time on poll
@@ -267,25 +268,25 @@ public class WatcherTest extends ClientB
if (!ClientCnxn.getDisableAutoResetWatch()) {
e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- assertEquals(EventType.NodeChildrenChanged, e.getType());
- assertEquals("/watchtest", e.getPath());
+ Assert.assertEquals(EventType.NodeChildrenChanged, e.getType());
+ Assert.assertEquals("/watchtest", e.getPath());
} else {
// we'll catch this later if it does happen after timeout, so
// why waste the time on poll
}
- assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals
+ Assert.assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals
stopServer();
globalWatcher.waitForDisconnected(TIMEOUT);
try {
try {
localWatcher.waitForDisconnected(500);
if (!isGlobal && !ClientCnxn.getDisableAutoResetWatch()) {
- fail("Got an event when I shouldn't have");
+ Assert.fail("Got an event when I shouldn't have");
}
} catch(TimeoutException toe) {
if (ClientCnxn.getDisableAutoResetWatch()) {
- fail("Didn't get an event when I should have");
+ Assert.fail("Didn't get an event when I should have");
}
// Else what we are expecting since there are no outstanding watches
}
@@ -311,14 +312,14 @@ public class WatcherTest extends ClientB
zk.delete("/watchtest/child2", -1);
e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- assertEquals(EventType.NodeDeleted, e.getType());
- assertEquals("/watchtest/child2", e.getPath());
+ Assert.assertEquals(EventType.NodeDeleted, e.getType());
+ Assert.assertEquals("/watchtest/child2", e.getPath());
e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- assertEquals(EventType.NodeChildrenChanged, e.getType());
- assertEquals("/watchtest", e.getPath());
+ Assert.assertEquals(EventType.NodeChildrenChanged, e.getType());
+ Assert.assertEquals("/watchtest", e.getPath());
- assertTrue(localWatcher.events.isEmpty());
+ Assert.assertTrue(localWatcher.events.isEmpty());
stopServer();
globalWatcher.waitForDisconnected(TIMEOUT);
@@ -334,8 +335,8 @@ public class WatcherTest extends ClientB
if (!ClientCnxn.getDisableAutoResetWatch()) {
e = localWatcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
- assertEquals(EventType.NodeDeleted, e.getType());
- assertEquals("/watchtest/child", e.getPath());
+ Assert.assertEquals(EventType.NodeDeleted, e.getType());
+ Assert.assertEquals("/watchtest/child", e.getPath());
} else {
// we'll catch this later if it does happen after timeout, so
// why waste the time on poll
@@ -343,7 +344,7 @@ public class WatcherTest extends ClientB
// Make sure nothing is straggling!
Thread.sleep(1000);
- assertTrue(localWatcher.events.isEmpty());
+ Assert.assertTrue(localWatcher.events.isEmpty());
}
Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZkDatabaseCorruptionTest.java Wed Mar 31 04:26:29 2010
@@ -32,32 +32,36 @@ import org.apache.zookeeper.server.SyncR
import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
import org.apache.zookeeper.server.quorum.QuorumPeer;
import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
+import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
-
+import org.junit.Test;
public class ZkDatabaseCorruptionTest extends QuorumBase {
protected static final Logger LOG = Logger.getLogger(ZkDatabaseCorruptionTest.class);
public static final long CONNECTION_TIMEOUT = ClientTest.CONNECTION_TIMEOUT;
-
+
private final QuorumBase qb = new QuorumBase();
-
+
@Before
@Override
- protected void setUp() throws Exception {
- LOG.info("STARTING " + getClass().getName());
+ public void setUp() throws Exception {
+ LOG.info("STARTING quorum " + getClass().getName());
qb.setUp();
}
-
- protected void tearDown() throws Exception {
- LOG.info("STOPPING " + getClass().getName());
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ LOG.info("STOPPING quorum " + getClass().getName());
}
-
+
private void corruptFile(File f) throws IOException {
RandomAccessFile outFile = new RandomAccessFile(f, "rw");
outFile.write("fail servers".getBytes());
outFile.close();
}
-
+
private void corruptAllSnapshots(File snapDir) throws IOException {
File[] listFiles = snapDir.listFiles();
for (File f: listFiles) {
@@ -66,7 +70,8 @@ public class ZkDatabaseCorruptionTest ex
}
}
}
-
+
+ @Test
public void testCorruption() throws Exception {
ClientBase.waitForServerUp(qb.hostPort, 10000);
ClientBase.waitForServerUp(qb.hostPort, 10000);
@@ -97,7 +102,7 @@ public class ZkDatabaseCorruptionTest ex
qb.s4.start();
try {
qb.s5.start();
- assertTrue(false);
+ Assert.assertTrue(false);
} catch(RuntimeException re) {
LOG.info("Got an error: expected", re);
}
@@ -105,12 +110,12 @@ public class ZkDatabaseCorruptionTest ex
String[] list = qb.hostPort.split(",");
for (int i =0; i < 4; i++) {
String hp = list[i];
- assertTrue("waiting for server up",
+ Assert.assertTrue("waiting for server up",
ClientBase.waitForServerUp(hp,
CONNECTION_TIMEOUT));
LOG.info(hp + " is accepting client connections");
}
-
+
zk = qb.createClient();
SyncRequestProcessor.setSnapCount(100);
for (int i = 2000; i < 4000; i++) {
@@ -121,7 +126,7 @@ public class ZkDatabaseCorruptionTest ex
QuorumBase.shutdown(qb.s2);
QuorumBase.shutdown(qb.s3);
QuorumBase.shutdown(qb.s4);
- }
+ }
+
-
}
\ No newline at end of file
Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperQuotaTest.java Wed Mar 31 04:26:29 2010
@@ -29,28 +29,14 @@ import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeperMain;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
+import org.junit.Test;
-/**
- * this class tests quota on a single
- * zookeeper server.
- *
- */
public class ZooKeeperQuotaTest extends ClientBase {
private static final Logger LOG = Logger.getLogger(
ZooKeeperQuotaTest.class);
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- LOG.info("STARTING " + getClass().getName());
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- LOG.info("STOPPING " + getClass().getName());
- }
-
+ @Test
public void testQuota() throws IOException,
InterruptedException, KeeperException {
final ZooKeeper zk = createClient();
@@ -73,13 +59,13 @@ public class ZooKeeperQuotaTest extends
String absolutePath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode;
byte[] data = zk.getData(absolutePath, false, new Stat());
StatsTrack st = new StatsTrack(new String(data));
- assertTrue("bytes are set", st.getBytes() == 1000L);
- assertTrue("num count is set", st.getCount() == 1000);
+ Assert.assertTrue("bytes are set", st.getBytes() == 1000L);
+ Assert.assertTrue("num count is set", st.getCount() == 1000);
String statPath = Quotas.quotaZookeeper + path + "/" + Quotas.statNode;
byte[] qdata = zk.getData(statPath, false, new Stat());
StatsTrack qst = new StatsTrack(new String(qdata));
- assertTrue("bytes are set", qst.getBytes() == 8L);
- assertTrue("cound is set", qst.getCount() == 2);
+ Assert.assertTrue("bytes are set", qst.getBytes() == 8L);
+ Assert.assertTrue("cound is set", qst.getCount() == 2);
}
}
Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java?rev=929377&r1=929376&r2=929377&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java Wed Mar 31 04:26:29 2010
@@ -23,19 +23,19 @@ import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import junit.framework.TestCase;
-
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZKTestCase;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.KeeperException.Code;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.data.Stat;
+import org.junit.Assert;
-public class ZooKeeperTestClient extends TestCase implements Watcher {
+public class ZooKeeperTestClient extends ZKTestCase implements Watcher {
protected String hostPort = "127.0.0.1:22801";
protected static final String dirOnZK = "/test_dir";
@@ -70,11 +70,11 @@ public class ZooKeeperTestClient extends
List<String> c2 = zk.getChildren(nodeName, false, stat);
if (!children1.equals(c2)) {
- fail("children lists from getChildren()/getChildren2() do not match");
+ Assert.fail("children lists from getChildren()/getChildren2() do not match");
}
if (!stat.equals(stat)) {
- fail("stats from exists()/getChildren2() do not match");
+ Assert.fail("stats from exists()/getChildren2() do not match");
}
if (children1.size() == 0) {
@@ -95,7 +95,7 @@ public class ZooKeeperTestClient extends
} catch (KeeperException.NodeExistsException ke) {
// expected, sort of
} catch (KeeperException ke) {
- fail("Unexpected exception code for create " + dirOnZK + ": "
+ Assert.fail("Unexpected exception code for create " + dirOnZK + ": "
+ ke.getMessage());
}
@@ -104,7 +104,7 @@ public class ZooKeeperTestClient extends
} catch (KeeperException.NodeExistsException ke) {
// expected, sort of
} catch (KeeperException ke) {
- fail("Unexpected exception code for create " + testDirOnZK + ": "
+ Assert.fail("Unexpected exception code for create " + testDirOnZK + ": "
+ ke.getMessage());
}
@@ -123,7 +123,7 @@ public class ZooKeeperTestClient extends
try {
zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException ke) {
- fail("Creating node " + parentName + ke.getMessage());
+ Assert.fail("Creating node " + parentName + ke.getMessage());
}
}
@@ -133,13 +133,13 @@ public class ZooKeeperTestClient extends
Code code = ke.code();
boolean valid = code == KeeperException.Code.NODEEXISTS;
if (!valid) {
- fail("Unexpected exception code for createin: " + ke.getMessage());
+ Assert.fail("Unexpected exception code for createin: " + ke.getMessage());
}
}
stat = zk.exists(nodeName, false);
if (stat == null) {
- fail("node " + nodeName + " should exist");
+ Assert.fail("node " + nodeName + " should exist");
}
System.out.println("Closing client with sessionid: 0x"
+ Long.toHexString(zk.getSessionId()));
@@ -177,7 +177,7 @@ public class ZooKeeperTestClient extends
try {
zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException ke) {
- fail("Creating node " + parentName + ke.getMessage());
+ Assert.fail("Creating node " + parentName + ke.getMessage());
}
}
@@ -191,7 +191,7 @@ public class ZooKeeperTestClient extends
boolean valid = code == KeeperException.Code.NONODE
|| code == KeeperException.Code.NOTEMPTY;
if (!valid) {
- fail("Unexpected exception code for delete: " + ke.getMessage());
+ Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
}
}
}
@@ -201,11 +201,11 @@ public class ZooKeeperTestClient extends
List<String> firstGen2 = zk_1.getChildren(parentName, true, stat);
if (!firstGen1.equals(firstGen2)) {
- fail("children lists from getChildren()/getChildren2() do not match");
+ Assert.fail("children lists from getChildren()/getChildren2() do not match");
}
if (!stat_parent.equals(stat)) {
- fail("stat from exists()/getChildren() do not match");
+ Assert.fail("stat from exists()/getChildren() do not match");
}
try {
@@ -214,7 +214,7 @@ public class ZooKeeperTestClient extends
Code code = ke.code();
boolean valid = code == KeeperException.Code.NODEEXISTS;
if (!valid) {
- fail("Unexpected exception code for createin: " + ke.getMessage());
+ Assert.fail("Unexpected exception code for createin: " + ke.getMessage());
}
}
@@ -225,33 +225,33 @@ public class ZooKeeperTestClient extends
}
if (event.getType() != EventType.NodeChildrenChanged
|| !event.getPath().equalsIgnoreCase(parentName)) {
- fail("Unexpected event was delivered: " + event.toString());
+ Assert.fail("Unexpected event was delivered: " + event.toString());
}
stat_node = zk_1.exists(nodeName, false);
if (stat_node == null) {
- fail("node " + nodeName + " should exist");
+ Assert.fail("node " + nodeName + " should exist");
}
try {
zk.delete(parentName, -1);
- fail("Should be impossible to delete a non-empty node " + parentName);
+ Assert.fail("Should be impossible to delete a non-empty node " + parentName);
} catch (KeeperException ke) {
Code code = ke.code();
boolean valid = code == KeeperException.Code.NOTEMPTY;
if (!valid) {
- fail("Unexpected exception code for delete: " + code);
+ Assert.fail("Unexpected exception code for delete: " + code);
}
}
try {
zk.create(nodeName + "/def", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
- fail("Should be impossible to create child off Ephemeral node " + nodeName);
+ Assert.fail("Should be impossible to create child off Ephemeral node " + nodeName);
} catch (KeeperException ke) {
Code code = ke.code();
boolean valid = code == KeeperException.Code.NOCHILDRENFOREPHEMERALS;
if (!valid) {
- fail("Unexpected exception code for createin: " + code);
+ Assert.fail("Unexpected exception code for createin: " + code);
}
}
@@ -260,29 +260,29 @@ public class ZooKeeperTestClient extends
List<String> children2 = zk.getChildren(nodeName, false, null);
if (!children1.equals(children2)) {
- fail("children lists from getChildren()/getChildren2() does not match");
+ Assert.fail("children lists from getChildren()/getChildren2() does not match");
}
if (children1.size() > 0) {
- fail("ephemeral node " + nodeName + " should not have children");
+ Assert.fail("ephemeral node " + nodeName + " should not have children");
}
} catch (KeeperException ke) {
Code code = ke.code();
boolean valid = code == KeeperException.Code.NONODE;
if (!valid) {
- fail("Unexpected exception code for createin: " + code);
+ Assert.fail("Unexpected exception code for createin: " + code);
}
}
firstGen1 = zk_1.getChildren(parentName, true);
firstGen2 = zk_1.getChildren(parentName, true, null);
if (!firstGen1.equals(firstGen2)) {
- fail("children list from getChildren()/getChildren2() does not match");
+ Assert.fail("children list from getChildren()/getChildren2() does not match");
}
stat_node = zk_1.exists(nodeName, true);
if (stat_node == null) {
- fail("node " + nodeName + " should exist");
+ Assert.fail("node " + nodeName + " should exist");
}
System.out.println("session id of zk: " + zk.getSessionId());
System.out.println("session id of zk_1: " + zk_1.getSessionId());
@@ -300,7 +300,7 @@ public class ZooKeeperTestClient extends
event.getPath().equalsIgnoreCase(nodeName)))) {
System.out.print(parentName + " "
+ EventType.NodeChildrenChanged + " " + nodeName + " " + EventType.NodeDeleted);
- fail("Unexpected first event was delivered: " + event.toString());
+ Assert.fail("Unexpected first event was delivered: " + event.toString());
}
event = this.getEvent(10);
@@ -314,16 +314,16 @@ public class ZooKeeperTestClient extends
event.getPath().equalsIgnoreCase(nodeName)))) {
System.out.print(parentName + " "
+ EventType.NodeChildrenChanged + " " + nodeName + " " + EventType.NodeDeleted);
- fail("Unexpected second event was delivered: " + event.toString());
+ Assert.fail("Unexpected second event was delivered: " + event.toString());
}
firstGen1 = zk_1.getChildren(parentName, false);
stat_node = zk_1.exists(nodeName, false);
if (stat_node != null) {
- fail("node " + nodeName + " should have been deleted");
+ Assert.fail("node " + nodeName + " should have been deleted");
}
if (firstGen1.contains(nodeName)) {
- fail("node " + nodeName + " should not be a children");
+ Assert.fail("node " + nodeName + " should not be a children");
}
deleteZKDir(zk_1, nodeName);
zk_1.close();
@@ -342,7 +342,7 @@ public class ZooKeeperTestClient extends
boolean valid = code == KeeperException.Code.NONODE
|| code == KeeperException.Code.NOTEMPTY;
if (!valid) {
- fail("Unexpected exception code for delete: " + ke.getMessage());
+ Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
}
}
try {
@@ -351,15 +351,15 @@ public class ZooKeeperTestClient extends
Code code = ke.code();
boolean valid = code == KeeperException.Code.NODEEXISTS;
if (!valid) {
- fail("Unexpected exception code for create: " + ke.getMessage());
+ Assert.fail("Unexpected exception code for create: " + ke.getMessage());
}
}
try {
zk.setData(nodeName, "hi".getBytes(), 5700);
- fail("Should have gotten BadVersion exception");
+ Assert.fail("Should have gotten BadVersion exception");
} catch (KeeperException ke) {
if (ke.code() != Code.BADVERSION) {
- fail("Should have gotten BadVersion exception");
+ Assert.fail("Should have gotten BadVersion exception");
}
}
zk.setData(nodeName, "hi".getBytes(), -1);
@@ -367,18 +367,18 @@ public class ZooKeeperTestClient extends
byte[] bytes = zk.getData(nodeName, false, st);
String retrieved = new String(bytes);
if (!"hi".equals(retrieved)) {
- fail("The retrieved data [" + retrieved
+ Assert.fail("The retrieved data [" + retrieved
+ "] is differented than the expected [hi]");
}
try {
zk.delete(nodeName, 6800);
- fail("Should have gotten BadVersion exception");
+ Assert.fail("Should have gotten BadVersion exception");
} catch (KeeperException ke) {
Code code = ke.code();
boolean valid = code == KeeperException.Code.NOTEMPTY
|| code == KeeperException.Code.BADVERSION;
if (!valid) {
- fail("Unexpected exception code for delete: " + ke.getMessage());
+ Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
}
}
try {
@@ -387,7 +387,7 @@ public class ZooKeeperTestClient extends
Code code = ke.code();
boolean valid = code == KeeperException.Code.NOTEMPTY;
if (!valid) {
- fail("Unexpected exception code for delete: " + code);
+ Assert.fail("Unexpected exception code for delete: " + code);
}
}
deleteZKDir(zk, nodeName);