You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2019/12/28 15:18:03 UTC
[zookeeper] branch master updated: ZOOKEEPER-3582: refactor the
async api call to lambda style
This is an automated email from the ASF dual-hosted git repository.
andor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/master by this push:
new d784e4d ZOOKEEPER-3582: refactor the async api call to lambda style
d784e4d is described below
commit d784e4dc8e042bd622500f861163bb315fa856fe
Author: ZWShuai91 <17...@163.com>
AuthorDate: Sat Dec 28 16:17:54 2019 +0100
ZOOKEEPER-3582: refactor the async api call to lambda style
Author: ZWShuai91 <17...@163.com>
Reviewers: eolivelli@apache.org, andor@apache.org
Closes #1142 from ZWShuai91/ZOOKEEPER-3582
---
.../java/org/apache/zookeeper/cli/LsCommand.java | 8 +-
.../org/apache/zookeeper/cli/SetAclCommand.java | 14 +--
.../org/apache/zookeeper/cli/SetQuotaCommand.java | 37 +++----
.../java/org/apache/zookeeper/cli/SyncCommand.java | 7 +-
.../apache/zookeeper/GetAllChildrenNumberTest.java | 13 +--
.../org/apache/zookeeper/GetEphemeralsTest.java | 69 ++++++------
.../zookeeper/server/CreateContainerTest.java | 9 +-
.../org/apache/zookeeper/server/CreateTTLTest.java | 14 +--
.../server/quorum/CloseSessionTxnTest.java | 8 +-
.../server/quorum/QuorumPeerMainTest.java | 6 +-
.../java/org/apache/zookeeper/test/ClientTest.java | 10 +-
.../test/FollowerResyncConcurrencyTest.java | 120 +++++++++------------
.../apache/zookeeper/test/ObserverMasterTest.java | 16 ++-
.../java/org/apache/zookeeper/test/QuorumTest.java | 32 +++---
.../org/apache/zookeeper/test/SessionTest.java | 10 +-
15 files changed, 140 insertions(+), 233 deletions(-)
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/LsCommand.java b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/LsCommand.java
index a66821c..9ac942c 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/LsCommand.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/LsCommand.java
@@ -25,7 +25,6 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.Parser;
import org.apache.commons.cli.PosixParser;
-import org.apache.zookeeper.AsyncCallback.StringCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZKUtil;
import org.apache.zookeeper.data.Stat;
@@ -102,12 +101,7 @@ public class LsCommand extends CliCommand {
boolean recursive = cl.hasOption("R");
try {
if (recursive) {
- ZKUtil.visitSubTreeDFS(zk, path, watch, new StringCallback() {
- @Override
- public void processResult(int rc, String path, Object ctx, String name) {
- out.println(path);
- }
- });
+ ZKUtil.visitSubTreeDFS(zk, path, watch, (rc, path1, ctx, name) -> out.println(path1));
} else {
Stat stat = withStat ? new Stat() : null;
List<String> children = zk.getChildren(path, watch, stat);
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SetAclCommand.java b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SetAclCommand.java
index ba94790..25aa3dd 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SetAclCommand.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SetAclCommand.java
@@ -24,7 +24,6 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.Parser;
import org.apache.commons.cli.PosixParser;
-import org.apache.zookeeper.AsyncCallback.StringCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZKUtil;
import org.apache.zookeeper.data.ACL;
@@ -81,14 +80,11 @@ public class SetAclCommand extends CliCommand {
}
try {
if (cl.hasOption("R")) {
- ZKUtil.visitSubTreeDFS(zk, path, false, new StringCallback() {
- @Override
- public void processResult(int rc, String p, Object ctx, String name) {
- try {
- zk.setACL(p, acl, version);
- } catch (KeeperException | InterruptedException e) {
- out.print(e.getMessage());
- }
+ ZKUtil.visitSubTreeDFS(zk, path, false, (rc, p, ctx, name) -> {
+ try {
+ zk.setACL(p, acl, version);
+ } catch (KeeperException | InterruptedException e) {
+ out.print(e.getMessage());
}
});
} else {
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SetQuotaCommand.java b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SetQuotaCommand.java
index 613d509..d9717ec 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SetQuotaCommand.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SetQuotaCommand.java
@@ -27,7 +27,6 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.Parser;
import org.apache.commons.cli.PosixParser;
-import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.Quotas;
@@ -194,27 +193,23 @@ public class SetQuotaCommand extends CliCommand {
String realPath = Quotas.quotaZookeeper + path;
try {
- ZKUtil.visitSubTreeDFS(zk, realPath, false, new AsyncCallback.StringCallback() {
-
- @Override
- public void processResult(int rc, String quotaPath, Object ctx, String name) {
- List<String> children = new ArrayList<>();
- try {
- children = zk.getChildren(quotaPath, false);
- } catch (KeeperException.NoNodeException ne) {
- LOG.debug("child removed during quota check", ne);
- return;
- } catch (InterruptedException | KeeperException e) {
- e.printStackTrace();
- }
+ ZKUtil.visitSubTreeDFS(zk, realPath, false, (rc, quotaPath, ctx, name) -> {
+ List<String> children = new ArrayList<>();
+ try {
+ children = zk.getChildren(quotaPath, false);
+ } catch (KeeperException.NoNodeException ne) {
+ LOG.debug("child removed during quota check", ne);
+ return;
+ } catch (InterruptedException | KeeperException e) {
+ e.printStackTrace();
+ }
- if (children.size() == 0) {
- return;
- }
- for (String child : children) {
- if (!quotaPath.equals(Quotas.quotaZookeeper + path) && Quotas.limitNode.equals(child)) {
- throw new IllegalArgumentException(path + " has a child " + quotaPath.substring(Quotas.quotaZookeeper.length()) + " which has a quota");
- }
+ if (children.size() == 0) {
+ return;
+ }
+ for (String child : children) {
+ if (!quotaPath.equals(Quotas.quotaZookeeper + path) && Quotas.limitNode.equals(child)) {
+ throw new IllegalArgumentException(path + " has a child " + quotaPath.substring(Quotas.quotaZookeeper.length()) + " which has a quota");
}
}
});
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SyncCommand.java b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SyncCommand.java
index 1c04575..f37e642 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SyncCommand.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/cli/SyncCommand.java
@@ -26,7 +26,6 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.Parser;
import org.apache.commons.cli.PosixParser;
-import org.apache.zookeeper.AsyncCallback;
/**
* sync command for cli
@@ -64,11 +63,7 @@ public class SyncCommand extends CliCommand {
CompletableFuture<Integer> cf = new CompletableFuture<>();
try {
- zk.sync(path, new AsyncCallback.VoidCallback() {
- public void processResult(int rc, String path, Object ctx) {
- cf.complete(rc);
- }
- }, null);
+ zk.sync(path, (rc, path1, ctx) -> cf.complete(rc), null);
int resultCode = cf.get(SYNC_TIMEOUT, TimeUnit.MILLISECONDS);
if (resultCode == 0) {
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/GetAllChildrenNumberTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/GetAllChildrenNumberTest.java
index b13ceaf..db69252 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/GetAllChildrenNumberTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/GetAllChildrenNumberTest.java
@@ -74,15 +74,12 @@ public class GetAllChildrenNumberTest extends ClientBase {
final CountDownLatch doneProcessing = new CountDownLatch(1);
- zk.getAllChildrenNumber("/", new AsyncCallback.AllChildrenNumberCallback() {
- @Override
- public void processResult(int rc, String path, Object ctx, int number) {
- if (path == null) {
- fail((String.format("the path of getAllChildrenNumber was null.")));
- }
- assertEquals(13, number);
- doneProcessing.countDown();
+ zk.getAllChildrenNumber("/", (rc, path, ctx, number) -> {
+ if (path == null) {
+ fail((String.format("the path of getAllChildrenNumber was null.")));
}
+ assertEquals(13, number);
+ doneProcessing.countDown();
}, null);
long waitForCallbackSecs = 2L;
if (!doneProcessing.await(waitForCallbackSecs, TimeUnit.SECONDS)) {
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/GetEphemeralsTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/GetEphemeralsTest.java
index 6d4dea1..efc66ff 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/GetEphemeralsTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/GetEphemeralsTest.java
@@ -80,23 +80,20 @@ public class GetEphemeralsTest extends ClientBase {
final CountDownLatch doneProcessing = new CountDownLatch(1);
final List<String> unexpectedBehavior = new ArrayList<String>();
- zk.getEphemerals(new AsyncCallback.EphemeralsCallback() {
- @Override
- public void processResult(int rc, Object ctx, List<String> paths) {
- if (paths == null) {
- unexpectedBehavior.add(String.format("Expected ephemeral count for"
- + " allPaths to be %d but was null", expected.length));
- } else if (paths.size() != expected.length) {
- unexpectedBehavior.add(String.format("Expected ephemeral count for allPaths to be %d but was %d", expected.length, paths.size()));
- }
- for (int i = 0; i < expected.length; i++) {
- String path = expected[i];
- if (!paths.contains(path)) {
- unexpectedBehavior.add(String.format("Path=%s exists in getEphemerals list ", path));
- }
+ zk.getEphemerals((rc, ctx, paths) -> {
+ if (paths == null) {
+ unexpectedBehavior.add(String.format("Expected ephemeral count for"
+ + " allPaths to be %d but was null", expected.length));
+ } else if (paths.size() != expected.length) {
+ unexpectedBehavior.add(String.format("Expected ephemeral count for allPaths to be %d but was %d", expected.length, paths.size()));
+ }
+ for (int i = 0; i < expected.length; i++) {
+ String path = expected[i];
+ if (!paths.contains(path)) {
+ unexpectedBehavior.add(String.format("Path=%s exists in getEphemerals list ", path));
}
- doneProcessing.countDown();
}
+ doneProcessing.countDown();
}, null);
long waitForCallbackSecs = 2L;
if (!doneProcessing.await(waitForCallbackSecs, TimeUnit.SECONDS)) {
@@ -112,23 +109,20 @@ public class GetEphemeralsTest extends ClientBase {
final CountDownLatch doneProcessing = new CountDownLatch(1);
final String checkPath = BASE + "0";
final List<String> unexpectedBehavior = new ArrayList<String>();
- zk.getEphemerals(checkPath, new AsyncCallback.EphemeralsCallback() {
- @Override
- public void processResult(int rc, Object ctx, List<String> paths) {
- if (paths == null) {
- unexpectedBehavior.add(String.format("Expected ephemeral count for %s to be %d but was null", checkPath, expected.length));
- } else if (paths.size() != EPHEMERAL_CNT) {
- unexpectedBehavior.add(String.format("Expected ephemeral count for %s to be %d but was %d", checkPath, EPHEMERAL_CNT, paths.size()));
- }
- for (int i = 0; i < EPHEMERAL_CNT; i++) {
- String path = expected[i];
- if (!paths.contains(path)) {
- unexpectedBehavior.add(String.format("Expected path=%s didn't exist "
- + "in getEphemerals list.", path));
- }
+ zk.getEphemerals(checkPath, (rc, ctx, paths) -> {
+ if (paths == null) {
+ unexpectedBehavior.add(String.format("Expected ephemeral count for %s to be %d but was null", checkPath, expected.length));
+ } else if (paths.size() != EPHEMERAL_CNT) {
+ unexpectedBehavior.add(String.format("Expected ephemeral count for %s to be %d but was %d", checkPath, EPHEMERAL_CNT, paths.size()));
+ }
+ for (int i = 0; i < EPHEMERAL_CNT; i++) {
+ String path = expected[i];
+ if (!paths.contains(path)) {
+ unexpectedBehavior.add(String.format("Expected path=%s didn't exist "
+ + "in getEphemerals list.", path));
}
- doneProcessing.countDown();
}
+ doneProcessing.countDown();
}, null);
long waitForCallbackSecs = 2L;
if (!doneProcessing.await(waitForCallbackSecs, TimeUnit.SECONDS)) {
@@ -144,16 +138,13 @@ public class GetEphemeralsTest extends ClientBase {
final String checkPath = "/unknownPath";
final int expectedSize = 0;
final List<String> unexpectedBehavior = new ArrayList<String>();
- zk.getEphemerals(checkPath, new AsyncCallback.EphemeralsCallback() {
- @Override
- public void processResult(int rc, Object ctx, List<String> paths) {
- if (paths == null) {
- unexpectedBehavior.add(String.format("Expected ephemeral count for %s to be %d but was null", checkPath, expectedSize));
- } else if (paths.size() != expectedSize) {
- unexpectedBehavior.add(String.format("Expected ephemeral count for %s to be %d but was %d", checkPath, expectedSize, paths.size()));
- }
- doneProcessing.countDown();
+ zk.getEphemerals(checkPath, (rc, ctx, paths) -> {
+ if (paths == null) {
+ unexpectedBehavior.add(String.format("Expected ephemeral count for %s to be %d but was null", checkPath, expectedSize));
+ } else if (paths.size() != expectedSize) {
+ unexpectedBehavior.add(String.format("Expected ephemeral count for %s to be %d but was %d", checkPath, expectedSize, paths.size()));
}
+ doneProcessing.countDown();
}, null);
long waitForCallbackSecs = 2L;
if (!doneProcessing.await(waitForCallbackSecs, TimeUnit.SECONDS)) {
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateContainerTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateContainerTest.java
index 03f9bcc..b1aa709 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateContainerTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateContainerTest.java
@@ -155,12 +155,9 @@ public class CreateContainerTest extends ClientBase {
@Test(timeout = 30000)
public void testSimpleDeletionAsync() throws KeeperException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
- AsyncCallback.Create2Callback cb = new AsyncCallback.Create2Callback() {
- @Override
- public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
- assertEquals(ctx, "context");
- latch.countDown();
- }
+ AsyncCallback.Create2Callback cb = (rc, path, ctx, name, stat) -> {
+ assertEquals(ctx, "context");
+ latch.countDown();
};
zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, cb, "context");
assertTrue(latch.await(5, TimeUnit.SECONDS));
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateTTLTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateTTLTest.java
index b4c8fa0..d48f713 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateTTLTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/CreateTTLTest.java
@@ -131,11 +131,8 @@ public class CreateTTLTest extends ClientBase {
@Test
public void testCreateAsync() throws KeeperException, InterruptedException {
- AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback() {
- @Override
- public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
- // NOP
- }
+ AsyncCallback.Create2Callback callback = (rc, path, ctx, name, stat) -> {
+ // NOP
};
zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, callback, null, 100);
@@ -212,11 +209,8 @@ public class CreateTTLTest extends ClientBase {
}
for (CreateMode createMode : CreateMode.values()) {
- AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback() {
- @Override
- public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
- // NOP
- }
+ AsyncCallback.Create2Callback callback = (rc, path, ctx, name, stat) -> {
+ // NOP
};
try {
zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode, callback, null, createMode.isTTL() ? 0 : 100);
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/CloseSessionTxnTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/CloseSessionTxnTest.java
index ac9665b..6727d00 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/CloseSessionTxnTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/CloseSessionTxnTest.java
@@ -20,7 +20,6 @@ package org.apache.zookeeper.server.quorum;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper.States;
@@ -89,12 +88,7 @@ public class CloseSessionTxnTest extends QuorumPeerTestBase {
// 4. verify the ephemeral node is gone
for (int i = 0; i < numServers; i++) {
final CountDownLatch syncedLatch = new CountDownLatch(1);
- servers.zk[i].sync(path, new AsyncCallback.VoidCallback() {
- @Override
- public void processResult(int rc, String path, Object ctx) {
- syncedLatch.countDown();
- }
- }, null);
+ servers.zk[i].sync(path, (rc, path1, ctx) -> syncedLatch.countDown(), null);
Assert.assertTrue(syncedLatch.await(3, TimeUnit.SECONDS));
Assert.assertNull(servers.zk[i].exists(path, false));
}
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
index c9beb09..d9666e1 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
@@ -51,7 +51,6 @@ import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.WriterAppender;
-import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.PortAssignment;
@@ -61,7 +60,6 @@ import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeper.States;
import org.apache.zookeeper.common.Time;
import org.apache.zookeeper.common.X509Exception;
-import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.metrics.BaseTestMetricsProvider;
import org.apache.zookeeper.metrics.impl.NullMetricsProvider;
import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
@@ -1146,9 +1144,7 @@ public class QuorumPeerMainTest extends QuorumPeerTestBase {
// use async, otherwise it will block the logLock in
// ZKDatabase and the setData request will timeout
try {
- leaderZk.setData(nodePath, value.getBytes(), -1, new AsyncCallback.StatCallback() {
- public void processResult(int rc, String path, Object ctx, Stat stat) {
- }
+ leaderZk.setData(nodePath, value.getBytes(), -1, (rc, path, ctx, stat) -> {
}, null);
// wait for the setData txn being populated
Thread.sleep(1000);
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientTest.java
index 43cc5b0..6bd483b 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientTest.java
@@ -32,7 +32,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;
@@ -832,12 +831,9 @@ public class ClientTest extends ClientBase {
for (int i = 0; i < 20; ++i) {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger rc = new AtomicInteger(0);
- zk.setData("/testnode", "".getBytes(), -1, new AsyncCallback.StatCallback() {
- @Override
- public void processResult(int retcode, String path, Object ctx, Stat stat) {
- rc.set(retcode);
- latch.countDown();
- }
+ zk.setData("/testnode", "".getBytes(), -1, (retcode, path, ctx, stat) -> {
+ rc.set(retcode);
+ latch.countDown();
}, null);
assertTrue("setData should complete within 5s", latch.await(zk.getSessionTimeout(), TimeUnit.MILLISECONDS));
assertEquals("setData should have succeeded", Code.OK.intValue(), rc.get());
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/FollowerResyncConcurrencyTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/FollowerResyncConcurrencyTest.java
index 9463b22..47a274d 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/FollowerResyncConcurrencyTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/FollowerResyncConcurrencyTest.java
@@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.TestableZooKeeper;
@@ -242,18 +241,14 @@ public class FollowerResyncConcurrencyTest extends ZKTestCase {
public void run() {
for (int i = 0; i < 3000; i++) {
// Here we create 3000 znodes
- zk3.create("/mytestfoo", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() {
-
- @Override
- public void processResult(int rc, String path, Object ctx, String name) {
- pending.decrementAndGet();
- counter.incrementAndGet();
- if (rc != 0) {
- errors.incrementAndGet();
- }
- if (counter.get() == 16200) {
- sem.release();
- }
+ zk3.create("/mytestfoo", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, (rc, path, ctx, name) -> {
+ pending.decrementAndGet();
+ counter.incrementAndGet();
+ if (rc != 0) {
+ errors.incrementAndGet();
+ }
+ if (counter.get() == 16200) {
+ sem.release();
}
}, null);
pending.incrementAndGet();
@@ -273,18 +268,14 @@ public class FollowerResyncConcurrencyTest extends ZKTestCase {
// initial data is written.
for (int i = 0; i < 13000; i++) {
// Here we create 13000 znodes
- zk3.create("/mybar", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() {
-
- @Override
- public void processResult(int rc, String path, Object ctx, String name) {
- pending.decrementAndGet();
- counter.incrementAndGet();
- if (rc != 0) {
- errors.incrementAndGet();
- }
- if (counter.get() == 16200) {
- sem.release();
- }
+ zk3.create("/mybar", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, (rc, path, ctx, name) -> {
+ pending.decrementAndGet();
+ counter.incrementAndGet();
+ if (rc != 0) {
+ errors.incrementAndGet();
+ }
+ if (counter.get() == 16200) {
+ sem.release();
}
}, null);
pending.incrementAndGet();
@@ -314,17 +305,14 @@ public class FollowerResyncConcurrencyTest extends ZKTestCase {
}
if (i % 50 == 0) {
- zk2.create("/newbaz", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() {
- @Override
- public void processResult(int rc, String path, Object ctx, String name) {
- pending.decrementAndGet();
- counter.incrementAndGet();
- if (rc != 0) {
- errors.incrementAndGet();
- }
- if (counter.get() == 16200) {
- sem.release();
- }
+ zk2.create("/newbaz", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, (rc, path, ctx, name) -> {
+ pending.decrementAndGet();
+ counter.incrementAndGet();
+ if (rc != 0) {
+ errors.incrementAndGet();
+ }
+ if (counter.get() == 16200) {
+ sem.release();
}
}, null);
pending.incrementAndGet();
@@ -417,18 +405,14 @@ public class FollowerResyncConcurrencyTest extends ZKTestCase {
int inSyncCounter = 0;
while (inSyncCounter < 400) {
if (runNow.get()) {
- zk3.create("/mytestfoo", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() {
-
- @Override
- public void processResult(int rc, String path, Object ctx, String name) {
- pending.decrementAndGet();
- counter.incrementAndGet();
- if (rc != 0) {
- errors.incrementAndGet();
- }
- if (counter.get() > 7300) {
- sem.release();
- }
+ zk3.create("/mytestfoo", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, (rc, path, ctx, name) -> {
+ pending.decrementAndGet();
+ counter.incrementAndGet();
+ if (rc != 0) {
+ errors.incrementAndGet();
+ }
+ if (counter.get() > 7300) {
+ sem.release();
}
}, null);
pending.incrementAndGet();
@@ -447,18 +431,14 @@ public class FollowerResyncConcurrencyTest extends ZKTestCase {
mytestfooThread.start();
for (int i = 0; i < 5000; i++) {
- zk2.create("/mybar", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() {
-
- @Override
- public void processResult(int rc, String path, Object ctx, String name) {
- pending.decrementAndGet();
- counter.incrementAndGet();
- if (rc != 0) {
- errors.incrementAndGet();
- }
- if (counter.get() > 7300) {
- sem.release();
- }
+ zk2.create("/mybar", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, (rc, path, ctx, name) -> {
+ pending.decrementAndGet();
+ counter.incrementAndGet();
+ if (rc != 0) {
+ errors.incrementAndGet();
+ }
+ if (counter.get() > 7300) {
+ sem.release();
}
}, null);
pending.incrementAndGet();
@@ -479,18 +459,14 @@ public class FollowerResyncConcurrencyTest extends ZKTestCase {
}
if (i >= 1000 && i % 2 == 0) {
- zk3.create("/newbaz", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, new AsyncCallback.StringCallback() {
-
- @Override
- public void processResult(int rc, String path, Object ctx, String name) {
- pending.decrementAndGet();
- counter.incrementAndGet();
- if (rc != 0) {
- errors.incrementAndGet();
- }
- if (counter.get() > 7300) {
- sem.release();
- }
+ zk3.create("/newbaz", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL, (rc, path, ctx, name) -> {
+ pending.decrementAndGet();
+ counter.incrementAndGet();
+ if (rc != 0) {
+ errors.incrementAndGet();
+ }
+ if (counter.get() > 7300) {
+ sem.release();
}
}, null);
pending.incrementAndGet();
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/ObserverMasterTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/ObserverMasterTest.java
index ee54a7a..620953a 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/ObserverMasterTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/ObserverMasterTest.java
@@ -45,7 +45,6 @@ import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeMBeanException;
-import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.DummyWatcher;
import org.apache.zookeeper.KeeperException;
@@ -721,15 +720,12 @@ public class ObserverMasterTest extends QuorumPeerTestBase implements Watcher {
for (int i = 0; i < numTransactions; i++) {
final boolean pleaseLog = i % 100 == 0;
client.create(root
- + i, "inner thread".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, new AsyncCallback.StringCallback() {
- @Override
- public void processResult(int rc, String path, Object ctx, String name) {
- writerLatch.countDown();
- if (pleaseLog) {
- LOG.info("wrote {}", path);
- }
- }
- }, null);
+ + i, "inner thread".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, (rc, path, ctx, name) -> {
+ writerLatch.countDown();
+ if (pleaseLog) {
+ LOG.info("wrote {}", path);
+ }
+ }, null);
if (pleaseLog) {
LOG.info("async wrote {}{}", root, i);
if (issueSync) {
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/QuorumTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/QuorumTest.java
index 7a3a5f0..c609c5c 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/QuorumTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/QuorumTest.java
@@ -27,7 +27,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.TimeoutException;
-import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.DummyWatcher;
import org.apache.zookeeper.KeeperException;
@@ -39,7 +38,6 @@ import org.apache.zookeeper.ZKTestCase;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.server.quorum.Leader;
import org.apache.zookeeper.server.quorum.LearnerHandler;
import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
@@ -151,12 +149,10 @@ public class QuorumTest extends ZKTestCase {
}
assertNotNull(leader);
for (int i = 0; i < 5000; i++) {
- zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() {
- public void processResult(int rc, String path, Object ctx, Stat stat) {
- counter++;
- if (rc != 0) {
- errors++;
- }
+ zk.setData("/blah/blah", new byte[0], -1, (rc, path, ctx, stat) -> {
+ counter++;
+ if (rc != 0) {
+ errors++;
}
}, null);
}
@@ -164,12 +160,10 @@ public class QuorumTest extends ZKTestCase {
f.getSocket().shutdownInput();
}
for (int i = 0; i < 5000; i++) {
- zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() {
- public void processResult(int rc, String path, Object ctx, Stat stat) {
- counter++;
- if (rc != 0) {
- errors++;
- }
+ zk.setData("/blah/blah", new byte[0], -1, (rc, path, ctx, stat) -> {
+ counter++;
+ if (rc != 0) {
+ errors++;
}
}, null);
}
@@ -216,12 +210,10 @@ public class QuorumTest extends ZKTestCase {
zknew.setData("/", new byte[1], -1);
final int[] result = new int[1];
result[0] = Integer.MAX_VALUE;
- zknew.sync("/", new AsyncCallback.VoidCallback() {
- public void processResult(int rc, String path, Object ctx) {
- synchronized (result) {
- result[0] = rc;
- result.notify();
- }
+ zknew.sync("/", (rc, path, ctx) -> {
+ synchronized (result) {
+ result[0] = rc;
+ result.notify();
}
}, null);
synchronized (result) {
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/SessionTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/SessionTest.java
index 9a5376b..d2ab579 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/SessionTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/SessionTest.java
@@ -245,12 +245,10 @@ public class SessionTest extends ZKTestCase {
+ 1)), zk.getSessionId(), zk.getSessionPasswd());
final int[] result = new int[1];
result[0] = Integer.MAX_VALUE;
- zknew.sync("/", new AsyncCallback.VoidCallback() {
- public void processResult(int rc, String path, Object ctx) {
- synchronized (result) {
- result[0] = rc;
- result.notify();
- }
+ zknew.sync("/", (rc, path, ctx) -> {
+ synchronized (result) {
+ result[0] = rc;
+ result.notify();
}
}, null);
synchronized (result) {