You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ti...@apache.org on 2023/10/11 12:02:01 UTC
[curator] branch master updated: CURATOR-692. Get rid of mockito (#485)
This is an automated email from the ASF dual-hosted git repository.
tison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git
The following commit(s) were added to refs/heads/master by this push:
new 2a94b2d7 CURATOR-692. Get rid of mockito (#485)
2a94b2d7 is described below
commit 2a94b2d7971bf47c2c12554bcd4c2e95581f607a
Author: tison <wa...@gmail.com>
AuthorDate: Wed Oct 11 20:01:55 2023 +0800
CURATOR-692. Get rid of mockito (#485)
Signed-off-by: tison <wa...@gmail.com>
---
curator-client/pom.xml | 6 --
.../test/java/org/apache/curator/BasicTests.java | 12 ++-
.../java/org/apache/curator/TestEnsurePath.java | 115 ---------------------
.../java/org/apache/curator/TestRetryLoop.java | 8 +-
curator-framework/pom.xml | 12 ---
.../curator/framework/api/CuratorWatcher.java | 2 +-
.../curator/framework/imps/TestFramework.java | 16 +--
.../framework/imps/TestWatcherIdentity.java | 63 +++++++----
curator-recipes/pom.xml | 6 --
.../recipes/queue/TestDistributedDelayQueue.java | 20 ++--
.../recipes/queue/TestDistributedIdQueue.java | 6 +-
.../queue/TestDistributedPriorityQueue.java | 20 ++--
.../recipes/queue/TestDistributedQueue.java | 15 ++-
.../state/DummyConnectionStateListener.java | 22 ++--
curator-test-zk35/pom.xml | 12 ---
curator-test-zk36/pom.xml | 12 ---
pom.xml | 13 ---
17 files changed, 89 insertions(+), 271 deletions(-)
diff --git a/curator-client/pom.xml b/curator-client/pom.xml
index 43fd507d..f3192be9 100644
--- a/curator-client/pom.xml
+++ b/curator-client/pom.xml
@@ -62,12 +62,6 @@
<artifactId>slf4j-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
diff --git a/curator-client/src/test/java/org/apache/curator/BasicTests.java b/curator-client/src/test/java/org/apache/curator/BasicTests.java
index 58946934..02cff2be 100644
--- a/curator-client/src/test/java/org/apache/curator/BasicTests.java
+++ b/curator-client/src/test/java/org/apache/curator/BasicTests.java
@@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
@@ -40,13 +41,16 @@ import org.apache.zookeeper.ZooKeeper;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
public class BasicTests extends BaseClassForTests {
@Test
public void testFactory() throws Exception {
- final ZooKeeper mockZookeeper = Mockito.mock(ZooKeeper.class);
- ZookeeperFactory zookeeperFactory = (connectString, sessionTimeout, watcher, canBeReadOnly) -> mockZookeeper;
+ final AtomicReference<ZooKeeper> expectedZooKeeper = new AtomicReference<>();
+ ZookeeperFactory zookeeperFactory = (connectString, sessionTimeout, watcher, canBeReadOnly) -> {
+ final ZooKeeper zooKeeper = new ZooKeeper(connectString, sessionTimeout, watcher, canBeReadOnly);
+ expectedZooKeeper.set(zooKeeper);
+ return zooKeeper;
+ };
CuratorZookeeperClient client = new CuratorZookeeperClient(
zookeeperFactory,
new FixedEnsembleProvider(server.getConnectString()),
@@ -56,7 +60,7 @@ public class BasicTests extends BaseClassForTests {
new RetryOneTime(1),
false);
client.start();
- assertEquals(client.getZooKeeper(), mockZookeeper);
+ assertEquals(client.getZooKeeper(), expectedZooKeeper.get());
}
@Test
diff --git a/curator-client/src/test/java/org/apache/curator/TestEnsurePath.java b/curator-client/src/test/java/org/apache/curator/TestEnsurePath.java
deleted file mode 100644
index 11e7de7b..00000000
--- a/curator-client/src/test/java/org/apache/curator/TestEnsurePath.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.curator;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import org.apache.curator.retry.RetryOneTime;
-import org.apache.curator.utils.EnsurePath;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.Stat;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-public class TestEnsurePath {
- @Test
- public void testBasic() throws Exception {
- ZooKeeper client = mock(ZooKeeper.class, Mockito.RETURNS_MOCKS);
- CuratorZookeeperClient curator = mock(CuratorZookeeperClient.class);
- RetryPolicy retryPolicy = new RetryOneTime(1);
- RetryLoop retryLoop = new RetryLoopImpl(retryPolicy, null);
- when(curator.getZooKeeper()).thenReturn(client);
- when(curator.getRetryPolicy()).thenReturn(retryPolicy);
- when(curator.newRetryLoop()).thenReturn(retryLoop);
-
- Stat fakeStat = mock(Stat.class);
- when(client.exists(Mockito.<String>any(), anyBoolean())).thenReturn(fakeStat);
-
- EnsurePath ensurePath = new EnsurePath("/one/two/three");
- ensurePath.ensure(curator);
-
- verify(client, times(3)).exists(Mockito.<String>any(), anyBoolean());
-
- ensurePath.ensure(curator);
- verifyNoMoreInteractions(client);
- ensurePath.ensure(curator);
- verifyNoMoreInteractions(client);
- }
-
- @Test
- public void testSimultaneous() throws Exception {
- ZooKeeper client = mock(ZooKeeper.class, Mockito.RETURNS_MOCKS);
- RetryPolicy retryPolicy = new RetryOneTime(1);
- RetryLoop retryLoop = new RetryLoopImpl(retryPolicy, null);
- final CuratorZookeeperClient curator = mock(CuratorZookeeperClient.class);
- when(curator.getZooKeeper()).thenReturn(client);
- when(curator.getRetryPolicy()).thenReturn(retryPolicy);
- when(curator.newRetryLoop()).thenReturn(retryLoop);
-
- final Stat fakeStat = mock(Stat.class);
- final CountDownLatch startedLatch = new CountDownLatch(2);
- final CountDownLatch finishedLatch = new CountDownLatch(2);
- final Semaphore semaphore = new Semaphore(0);
- when(client.exists(Mockito.<String>any(), anyBoolean())).thenAnswer(new Answer<Stat>() {
- @Override
- public Stat answer(InvocationOnMock invocation) throws Throwable {
- semaphore.acquire();
- return fakeStat;
- }
- });
-
- final EnsurePath ensurePath = new EnsurePath("/one/two/three");
- ExecutorService service = Executors.newCachedThreadPool();
- for (int i = 0; i < 2; ++i) {
- service.submit(new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- startedLatch.countDown();
- ensurePath.ensure(curator);
- finishedLatch.countDown();
- return null;
- }
- });
- }
-
- assertTrue(startedLatch.await(10, TimeUnit.SECONDS));
- semaphore.release(3);
- assertTrue(finishedLatch.await(10, TimeUnit.SECONDS));
- verify(client, times(3)).exists(Mockito.<String>any(), anyBoolean());
-
- ensurePath.ensure(curator);
- verifyNoMoreInteractions(client);
- ensurePath.ensure(curator);
- verifyNoMoreInteractions(client);
- }
-}
diff --git a/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java b/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
index ff2491b4..749accd4 100644
--- a/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
+++ b/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
@@ -23,8 +23,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-import static org.mockito.Mockito.times;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryForever;
import org.apache.curator.retry.RetryOneTime;
@@ -34,7 +34,6 @@ import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
public class TestRetryLoop extends BaseClassForTests {
@Test
@@ -133,13 +132,14 @@ public class TestRetryLoop extends BaseClassForTests {
@Test
public void testRetryForever() throws Exception {
int retryIntervalMs = 1;
- RetrySleeper sleeper = Mockito.mock(RetrySleeper.class);
+ AtomicLong retryTimes = new AtomicLong();
+ RetrySleeper sleeper = (time, unit) -> retryTimes.incrementAndGet();
RetryForever retryForever = new RetryForever(retryIntervalMs);
for (int i = 0; i < 10; i++) {
boolean allowed = retryForever.allowRetry(i, 0, sleeper);
assertTrue(allowed);
- Mockito.verify(sleeper, times(i + 1)).sleepFor(retryIntervalMs, TimeUnit.MILLISECONDS);
+ assertEquals(i + 1, retryTimes.get());
}
}
diff --git a/curator-framework/pom.xml b/curator-framework/pom.xml
index 69b8d1d3..779b0d18 100644
--- a/curator-framework/pom.xml
+++ b/curator-framework/pom.xml
@@ -94,18 +94,6 @@
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-inline</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.awaitility</groupId>
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorWatcher.java b/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorWatcher.java
index 80272f88..5b99d01e 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorWatcher.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorWatcher.java
@@ -33,5 +33,5 @@ public interface CuratorWatcher {
* @param event the event
* @throws Exception any exceptions to log
*/
- public void process(WatchedEvent event) throws Exception;
+ void process(WatchedEvent event) throws Exception;
}
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
index d28b814e..3973e5aa 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
@@ -85,8 +85,6 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedConstruction;
-import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -115,6 +113,7 @@ public class TestFramework extends BaseClassForTests {
super.teardown();
}
+ @Test
public void testWaitForShutdownTimeoutMs() throws Exception {
final BlockingQueue<Integer> timeoutQueue = new ArrayBlockingQueue<>(1);
ZookeeperFactory zookeeperFactory = new ZookeeperFactory() {
@@ -755,19 +754,6 @@ public class TestFramework extends BaseClassForTests {
CloseableUtils.closeQuietly(client);
}
- @Test
- public void testNoPartialConstruction() {
- try (MockedConstruction<CuratorFrameworkImpl> construction =
- Mockito.mockConstruction(CuratorFrameworkImpl.class)) {
- CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
- .connectString(server.getConnectString())
- .retryPolicy(new RetryOneTime(1));
- // Invoke constructor directly to make the construction more visible.
- CuratorFramework client = new CuratorFrameworkImpl(builder);
- assertEquals(Collections.singletonList(client), construction.constructed());
- }
- }
-
@Test
public void testCustomCallback() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java
index 382b96b9..f7377f75 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWatcherIdentity.java
@@ -20,11 +20,14 @@
package org.apache.curator.framework.imps;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.Sets;
import java.util.Set;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -37,11 +40,9 @@ import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
public class TestWatcherIdentity extends BaseClassForTests {
private static final String PATH = "/foo";
- private static final int TIMEOUT_MS = 100000;
private static class CountZKWatcher implements Watcher {
private final AtomicInteger count = new AtomicInteger(0);
@@ -52,6 +53,34 @@ public class TestWatcherIdentity extends BaseClassForTests {
}
}
+ private static class TestEventWatcher implements CuratorWatcher {
+ private final Timing timing;
+ private final BlockingQueue<WatchedEvent> events = new LinkedBlockingQueue<>();
+
+ private TestEventWatcher(Timing timing) {
+ this.timing = timing;
+ }
+
+ @Override
+ public void process(WatchedEvent event) {
+ events.add(event);
+ }
+
+ private void assertEvent(Watcher.Event.EventType type, String path) throws InterruptedException {
+ WatchedEvent event = events.poll(timing.forWaiting().seconds(), TimeUnit.SECONDS);
+ assertNotNull(event);
+ assertEquals(type, event.getType());
+ assertEquals(path, event.getPath());
+ }
+
+ private void assertNoMoreEvents() throws InterruptedException {
+ timing.sleepABit();
+ assertTrue(
+ events.isEmpty(),
+ String.format("Expected no events, found %d; first event: %s", events.size(), events.peek()));
+ }
+ }
+
@Test
public void testSameWatcherPerZKDocs() throws Exception {
CountZKWatcher actualWatcher = new CountZKWatcher();
@@ -81,10 +110,8 @@ public class TestWatcherIdentity extends BaseClassForTests {
@Test
public void testSameCuratorWatcherPerZKDocs() throws Exception {
- // Construct mock object
- CuratorWatcher actualWatcher = mock(CuratorWatcher.class);
-
Timing timing = new Timing();
+ TestEventWatcher actualWatcher = new TestEventWatcher(timing);
CuratorFramework client = CuratorFrameworkFactory.newClient(
server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try {
@@ -97,12 +124,13 @@ public class TestWatcherIdentity extends BaseClassForTests {
client.setData().forPath("/test", "foo".getBytes());
client.delete().forPath("/test");
- Mockito.verify(actualWatcher, Mockito.timeout(TIMEOUT_MS).times(1)).process(any(WatchedEvent.class));
+ actualWatcher.assertEvent(Watcher.Event.EventType.NodeDataChanged, "/test");
client.create().forPath("/test");
client.checkExists().usingWatcher(actualWatcher).forPath("/test");
client.delete().forPath("/test");
- Mockito.verify(actualWatcher, Mockito.timeout(TIMEOUT_MS).times(2)).process(any(WatchedEvent.class));
+ actualWatcher.assertEvent(Watcher.Event.EventType.NodeDeleted, "/test");
+ actualWatcher.assertNoMoreEvents();
} finally {
CloseableUtils.closeQuietly(client);
}
@@ -110,15 +138,12 @@ public class TestWatcherIdentity extends BaseClassForTests {
@Test
public void testSetAddition() {
- Watcher watcher = new Watcher() {
- @Override
- public void process(WatchedEvent event) {}
- };
+ Watcher watcher = event -> {};
NamespaceWatcher namespaceWatcher1 = new NamespaceWatcher(null, watcher, "/foo");
NamespaceWatcher namespaceWatcher2 = new NamespaceWatcher(null, watcher, "/foo");
assertEquals(namespaceWatcher1, namespaceWatcher2);
- assertFalse(namespaceWatcher1.equals(watcher));
- assertFalse(watcher.equals(namespaceWatcher1));
+ assertNotEquals(namespaceWatcher1, watcher);
+ assertNotEquals(watcher, namespaceWatcher1);
Set<Watcher> set = Sets.newHashSet();
set.add(namespaceWatcher1);
set.add(namespaceWatcher2);
@@ -128,8 +153,7 @@ public class TestWatcherIdentity extends BaseClassForTests {
@Test
public void testCuratorWatcher() throws Exception {
Timing timing = new Timing();
- // Construct mock object
- CuratorWatcher watcher = mock(CuratorWatcher.class);
+ TestEventWatcher watcher = new TestEventWatcher(timing);
CuratorFramework client = CuratorFrameworkFactory.newClient(
server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try {
@@ -140,7 +164,8 @@ public class TestWatcherIdentity extends BaseClassForTests {
client.getData().usingWatcher(watcher).forPath(PATH);
// Ok, let's test it
client.setData().forPath(PATH, new byte[] {});
- Mockito.verify(watcher, Mockito.timeout(TIMEOUT_MS).times(1)).process(any(WatchedEvent.class));
+ watcher.assertEvent(Watcher.Event.EventType.NodeDataChanged, PATH);
+ watcher.assertNoMoreEvents();
} finally {
CloseableUtils.closeQuietly(client);
}
diff --git a/curator-recipes/pom.xml b/curator-recipes/pom.xml
index a04850db..60a86227 100644
--- a/curator-recipes/pom.xml
+++ b/curator-recipes/pom.xml
@@ -65,12 +65,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java
index a633192e..f69ee01b 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java
@@ -32,13 +32,12 @@ import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.framework.state.ConnectionStateListener;
+import org.apache.curator.framework.state.DummyConnectionStateListener;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.Timing;
import org.apache.curator.utils.CloseableUtils;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
public class TestDistributedDelayQueue extends BaseClassForTests {
@Test
@@ -49,8 +48,7 @@ public class TestDistributedDelayQueue extends BaseClassForTests {
server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try {
- BlockingQueueConsumer<Long> consumer =
- new BlockingQueueConsumer<Long>(Mockito.mock(ConnectionStateListener.class));
+ BlockingQueueConsumer<Long> consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test")
.buildDelayQueue();
queue.start();
@@ -79,8 +77,7 @@ public class TestDistributedDelayQueue extends BaseClassForTests {
server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try {
- BlockingQueueConsumer<Long> consumer =
- new BlockingQueueConsumer<Long>(Mockito.mock(ConnectionStateListener.class));
+ BlockingQueueConsumer<Long> consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test")
.buildDelayQueue();
queue.start();
@@ -107,8 +104,7 @@ public class TestDistributedDelayQueue extends BaseClassForTests {
server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try {
- BlockingQueueConsumer<Long> consumer =
- new BlockingQueueConsumer<Long>(Mockito.mock(ConnectionStateListener.class));
+ BlockingQueueConsumer<Long> consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test")
.buildDelayQueue();
queue.start();
@@ -176,8 +172,7 @@ public class TestDistributedDelayQueue extends BaseClassForTests {
putQueue.put(data.get(key), key);
}
- BlockingQueueConsumer<Long> consumer =
- new BlockingQueueConsumer<Long>(Mockito.mock(ConnectionStateListener.class));
+ BlockingQueueConsumer<Long> consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener());
getQueue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test2")
.putInBackground(false)
.buildDelayQueue();
@@ -185,9 +180,8 @@ public class TestDistributedDelayQueue extends BaseClassForTests {
long lastValue = -1;
for (int i = 0; i < QTY; ++i) {
- Long value = consumer.take(DELAY_MS * 2, TimeUnit.MILLISECONDS);
- assertNotNull(value);
- assertEquals(value, new Long(lastValue + 1));
+ long value = consumer.take(DELAY_MS * 2, TimeUnit.MILLISECONDS);
+ assertEquals(value, lastValue + 1);
lastValue = value;
}
} finally {
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java
index f43134cd..82ba8b18 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java
@@ -28,14 +28,12 @@ import java.util.concurrent.TimeUnit;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.state.ConnectionState;
-import org.apache.curator.framework.state.ConnectionStateListener;
+import org.apache.curator.framework.state.DummyConnectionStateListener;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.utils.CloseableUtils;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"})
public class TestDistributedIdQueue extends BaseClassForTests {
private static final String QUEUE_PATH = "/a/queue";
@@ -86,7 +84,7 @@ public class TestDistributedIdQueue extends BaseClassForTests {
client.start();
try {
BlockingQueueConsumer<TestQueueItem> consumer =
- new BlockingQueueConsumer<TestQueueItem>(Mockito.mock(ConnectionStateListener.class));
+ new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH)
.buildIdQueue();
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedPriorityQueue.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedPriorityQueue.java
index 04786db9..34784066 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedPriorityQueue.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedPriorityQueue.java
@@ -33,13 +33,12 @@ import java.util.concurrent.TimeUnit;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.state.ConnectionState;
-import org.apache.curator.framework.state.ConnectionStateListener;
+import org.apache.curator.framework.state.DummyConnectionStateListener;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.test.Timing;
import org.apache.curator.utils.CloseableUtils;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
public class TestDistributedPriorityQueue extends BaseClassForTests {
@Test
@@ -50,8 +49,7 @@ public class TestDistributedPriorityQueue extends BaseClassForTests {
try {
final int minItemsBeforeRefresh = 3;
- BlockingQueueConsumer<Integer> consumer =
- new BlockingQueueConsumer<Integer>(Mockito.mock(ConnectionStateListener.class));
+ BlockingQueueConsumer<Integer> consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, new IntSerializer(), "/test")
.buildPriorityQueue(minItemsBeforeRefresh);
queue.start();
@@ -60,7 +58,7 @@ public class TestDistributedPriorityQueue extends BaseClassForTests {
queue.put(i, 10 + i);
}
- assertEquals(consumer.take(1, TimeUnit.SECONDS), new Integer(0));
+ assertEquals(consumer.take(1, TimeUnit.SECONDS), 0);
queue.put(1000, 1); // lower priority
int count = 0;
@@ -106,13 +104,12 @@ public class TestDistributedPriorityQueue extends BaseClassForTests {
queue.put(i, 10);
}
- assertEquals(blockingQueue.poll(timing.seconds(), TimeUnit.SECONDS), new Integer(0));
+ assertEquals(blockingQueue.poll(timing.seconds(), TimeUnit.SECONDS), 0);
timing.sleepABit();
queue.put(1000, 1); // lower priority
timing.sleepABit();
- assertEquals(
- blockingQueue.poll(timing.seconds(), TimeUnit.SECONDS), new Integer(1)); // is in consumer already
- assertEquals(blockingQueue.poll(timing.seconds(), TimeUnit.SECONDS), new Integer(1000));
+ assertEquals(blockingQueue.poll(timing.seconds(), TimeUnit.SECONDS), 1); // is in consumer already
+ assertEquals(blockingQueue.poll(timing.seconds(), TimeUnit.SECONDS), 1000);
} finally {
CloseableUtils.closeQuietly(queue);
CloseableUtils.closeQuietly(client);
@@ -138,8 +135,7 @@ public class TestDistributedPriorityQueue extends BaseClassForTests {
return super.deserialize(bytes);
}
};
- BlockingQueueConsumer<Integer> consumer =
- new BlockingQueueConsumer<Integer>(Mockito.mock(ConnectionStateListener.class));
+ BlockingQueueConsumer<Integer> consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, serializer, "/test").buildPriorityQueue(1);
queue.start();
@@ -171,7 +167,7 @@ public class TestDistributedPriorityQueue extends BaseClassForTests {
final CountDownLatch hasConsumedLatch = new CountDownLatch(1);
final CountDownLatch okToConsumeLatch = new CountDownLatch(1);
BlockingQueueConsumer<Integer> consumer =
- new BlockingQueueConsumer<Integer>(Mockito.mock(ConnectionStateListener.class)) {
+ new BlockingQueueConsumer<Integer>(new DummyConnectionStateListener()) {
@Override
public void consumeMessage(Integer message) throws Exception {
hasConsumedLatch.countDown();
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java
index 43f08840..abbdc4e5 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java
@@ -44,7 +44,7 @@ import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.imps.CuratorFrameworkState;
import org.apache.curator.framework.state.ConnectionState;
-import org.apache.curator.framework.state.ConnectionStateListener;
+import org.apache.curator.framework.state.DummyConnectionStateListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.BaseClassForTests;
@@ -52,7 +52,6 @@ import org.apache.curator.test.Timing;
import org.apache.curator.utils.CloseableUtils;
import org.apache.zookeeper.CreateMode;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"})
public class TestDistributedQueue extends BaseClassForTests {
@@ -65,7 +64,7 @@ public class TestDistributedQueue extends BaseClassForTests {
/*
https://issues.apache.org/jira/browse/CURATOR-56
- This tests against ever growing node name bug
+ This tests against ever-growing node name bug
*/
DistributedQueue<TestQueueItem> queue = null;
@@ -205,7 +204,7 @@ public class TestDistributedQueue extends BaseClassForTests {
client.start();
try {
BlockingQueueConsumer<TestQueueItem> consumer =
- new BlockingQueueConsumer<TestQueueItem>(Mockito.mock(ConnectionStateListener.class));
+ new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH)
.buildQueue();
@@ -505,7 +504,7 @@ public class TestDistributedQueue extends BaseClassForTests {
client.start();
try {
final BlockingQueueConsumer<TestQueueItem> consumer =
- new BlockingQueueConsumer<TestQueueItem>(Mockito.mock(ConnectionStateListener.class));
+ new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH)
.lockPath("/a/locks")
.buildQueue();
@@ -544,7 +543,7 @@ public class TestDistributedQueue extends BaseClassForTests {
client.start();
try {
BlockingQueueConsumer<TestQueueItem> consumer =
- new BlockingQueueConsumer<TestQueueItem>(Mockito.mock(ConnectionStateListener.class));
+ new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH)
.buildQueue();
@@ -583,7 +582,7 @@ public class TestDistributedQueue extends BaseClassForTests {
client.start();
try {
BlockingQueueConsumer<TestQueueItem> consumer =
- new BlockingQueueConsumer<TestQueueItem>(Mockito.mock(ConnectionStateListener.class));
+ new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH)
.buildQueue();
@@ -686,7 +685,7 @@ public class TestDistributedQueue extends BaseClassForTests {
client.start();
try {
BlockingQueueConsumer<TestQueueItem> consumer =
- new BlockingQueueConsumer<TestQueueItem>(Mockito.mock(ConnectionStateListener.class));
+ new BlockingQueueConsumer<>(new DummyConnectionStateListener());
queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH)
.buildQueue();
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorWatcher.java b/curator-recipes/src/test/java/org/apache/curator/framework/state/DummyConnectionStateListener.java
similarity index 62%
copy from curator-framework/src/main/java/org/apache/curator/framework/api/CuratorWatcher.java
copy to curator-recipes/src/test/java/org/apache/curator/framework/state/DummyConnectionStateListener.java
index 80272f88..64d5ecc5 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorWatcher.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/state/DummyConnectionStateListener.java
@@ -17,21 +17,13 @@
* under the License.
*/
-package org.apache.curator.framework.api;
+package org.apache.curator.framework.state;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
+import org.apache.curator.framework.CuratorFramework;
-/**
- * A version of {@link Watcher} that can throw an exception
- */
-public interface CuratorWatcher {
- /**
- * Same as {@link Watcher#process(WatchedEvent)}. If an exception
- * is thrown, Curator will log it
- *
- * @param event the event
- * @throws Exception any exceptions to log
- */
- public void process(WatchedEvent event) throws Exception;
+public class DummyConnectionStateListener implements ConnectionStateListener {
+ @Override
+ public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
+ // do nothing
+ }
}
diff --git a/curator-test-zk35/pom.xml b/curator-test-zk35/pom.xml
index 9761dd28..84cf0df0 100644
--- a/curator-test-zk35/pom.xml
+++ b/curator-test-zk35/pom.xml
@@ -171,18 +171,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-inline</artifactId>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
diff --git a/curator-test-zk36/pom.xml b/curator-test-zk36/pom.xml
index 84f655e5..23f5fd0e 100644
--- a/curator-test-zk36/pom.xml
+++ b/curator-test-zk36/pom.xml
@@ -184,18 +184,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-inline</artifactId>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
diff --git a/pom.xml b/pom.xml
index 0ea09938..82f4447a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -109,7 +109,6 @@
<snappy-version>1.1.10.4</snappy-version>
<build-helper-maven-plugin-version>3.3.0</build-helper-maven-plugin-version>
<awaitility-version>4.1.1</awaitility-version>
- <mockito-version>4.11.0</mockito-version>
<!-- OSGi Properties -->
<osgi.export.package />
@@ -369,18 +368,6 @@
<version>${slf4j-version}</version>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>${mockito-version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-inline</artifactId>
- <version>${mockito-version}</version>
- </dependency>
-
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>