From 573c9a986b2295eab0c008b60898b901127cb9d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:20:06 +0800 Subject: [PATCH 1/2] CURATOR-679: Bump snappy-java from 1.1.10.1 to 1.1.10.4 (#483) Bumps [org.xerial.snappy:snappy-java](https://github.com/xerial/snappy-java) from 1.1.10.1 to 1.1.10.4. - [Release notes](https://github.com/xerial/snappy-java/releases) - [Commits](https://github.com/xerial/snappy-java/compare/v1.1.10.1...v1.1.10.4) --- updated-dependencies: - dependency-name: org.xerial.snappy:snappy-java dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4771c4677..0ea099385 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,7 @@ 1.7.25 2.8 3.2.5 - 1.1.10.1 + 1.1.10.4 3.3.0 4.1.1 4.11.0 From 2a94b2d7971bf47c2c12554bcd4c2e95581f607a Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 11 Oct 2023 20:01:55 +0800 Subject: [PATCH 2/2] CURATOR-692. Get rid of mockito (#485) Signed-off-by: tison --- curator-client/pom.xml | 6 - .../java/org/apache/curator/BasicTests.java | 12 +- .../org/apache/curator/TestEnsurePath.java | 115 ------------------ .../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 - .../queue/TestDistributedDelayQueue.java | 20 ++- .../recipes/queue/TestDistributedIdQueue.java | 6 +- .../queue/TestDistributedPriorityQueue.java | 20 ++- .../recipes/queue/TestDistributedQueue.java | 15 ++- .../state/DummyConnectionStateListener.java | 29 +++++ curator-test-zk35/pom.xml | 12 -- curator-test-zk36/pom.xml | 12 -- pom.xml | 13 -- 17 files changed, 111 insertions(+), 256 deletions(-) delete mode 100644 curator-client/src/test/java/org/apache/curator/TestEnsurePath.java create mode 100644 curator-recipes/src/test/java/org/apache/curator/framework/state/DummyConnectionStateListener.java diff --git a/curator-client/pom.xml b/curator-client/pom.xml index 43fd507df..f3192be95 100644 --- a/curator-client/pom.xml +++ b/curator-client/pom.xml @@ -62,12 +62,6 @@ slf4j-api - - org.mockito - mockito-core - test - - org.apache.curator curator-test 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 58946934d..02cff2bed 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 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.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 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 void testFactory() throws Exception { 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 11e7de7b6..000000000 --- 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.any(), anyBoolean())).thenReturn(fakeStat); - - EnsurePath ensurePath = new EnsurePath("/one/two/three"); - ensurePath.ensure(curator); - - verify(client, times(3)).exists(Mockito.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.any(), anyBoolean())).thenAnswer(new Answer() { - @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() { - @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.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 ff2491b4f..749accd47 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.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.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 void testRetryLoop() throws Exception { @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 69b8d1d33..779b0d180 100644 --- a/curator-framework/pom.xml +++ b/curator-framework/pom.xml @@ -94,18 +94,6 @@ slf4j-log4j12 test - - - org.mockito - mockito-core - test - - - - org.mockito - mockito-inline - test - org.awaitility 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 80272f88b..5b99d01ec 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 d28b814e2..3973e5aae 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.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 void teardown() throws Exception { super.teardown(); } + @Test public void testWaitForShutdownTimeoutMs() throws Exception { final BlockingQueue timeoutQueue = new ArrayBlockingQueue<>(1); ZookeeperFactory zookeeperFactory = new ZookeeperFactory() { @@ -755,19 +754,6 @@ public void testNullNamespace() { CloseableUtils.closeQuietly(client); } - @Test - public void testNoPartialConstruction() { - try (MockedConstruction 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 382b96b9d..f7377f75c 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.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 void process(WatchedEvent event) { } } + private static class TestEventWatcher implements CuratorWatcher { + private final Timing timing; + private final BlockingQueue 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 void testSameWatcherPerZKDocs() throws Exception { @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 void testSameCuratorWatcherPerZKDocs() throws Exception { 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 void testSameCuratorWatcherPerZKDocs() throws Exception { @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 set = Sets.newHashSet(); set.add(namespaceWatcher1); set.add(namespaceWatcher2); @@ -128,8 +153,7 @@ public void process(WatchedEvent event) {} @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 void testCuratorWatcher() throws Exception { 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 a04850db8..60a862277 100644 --- a/curator-recipes/pom.xml +++ b/curator-recipes/pom.xml @@ -65,12 +65,6 @@ test - - org.mockito - mockito-core - test - - org.junit.jupiter junit-jupiter-api 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 a633192eb..f69ee01bb 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.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 void testLateAddition() throws Exception { server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start(); try { - BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + BlockingQueueConsumer consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test") .buildDelayQueue(); queue.start(); @@ -79,8 +77,7 @@ public void testBasic() throws Exception { server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start(); try { - BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + BlockingQueueConsumer consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test") .buildDelayQueue(); queue.start(); @@ -107,8 +104,7 @@ public void testSimple() throws Exception { server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start(); try { - BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + BlockingQueueConsumer consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test") .buildDelayQueue(); queue.start(); @@ -176,8 +172,7 @@ public void testSorting() throws Exception { putQueue.put(data.get(key), key); } - BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + BlockingQueueConsumer consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener()); getQueue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test2") .putInBackground(false) .buildDelayQueue(); @@ -185,9 +180,8 @@ public void testSorting() throws Exception { 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 f43134cd4..82ba8b187 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 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 void testOrdering() throws Exception { client.start(); try { BlockingQueueConsumer consumer = - new BlockingQueueConsumer(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 04786db97..347840668 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 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 void testMinItemsBeforeRefresh() throws Exception { try { final int minItemsBeforeRefresh = 3; - BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + BlockingQueueConsumer consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, new IntSerializer(), "/test") .buildPriorityQueue(minItemsBeforeRefresh); queue.start(); @@ -60,7 +58,7 @@ public void testMinItemsBeforeRefresh() throws Exception { 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 void stateChanged(CuratorFramework client, ConnectionState newState) {} 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 Integer deserialize(byte[] bytes) { return super.deserialize(bytes); } }; - BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + BlockingQueueConsumer consumer = new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, serializer, "/test").buildPriorityQueue(1); queue.start(); @@ -171,7 +167,7 @@ public void testSimple() throws Exception { final CountDownLatch hasConsumedLatch = new CountDownLatch(1); final CountDownLatch okToConsumeLatch = new CountDownLatch(1); BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)) { + new BlockingQueueConsumer(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 43f088407..abbdc4e5c 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.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.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 void testRetryAfterFailure_Curator56() throws Exception { /* 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 queue = null; @@ -205,7 +204,7 @@ public void testPutListener() throws Exception { client.start(); try { BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH) .buildQueue(); @@ -505,7 +504,7 @@ public void testSafetyBasic() throws Exception { client.start(); try { final BlockingQueueConsumer consumer = - new BlockingQueueConsumer(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 void testPutMulti() throws Exception { client.start(); try { BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH) .buildQueue(); @@ -583,7 +582,7 @@ public void testMultiPutterSingleGetter() throws Exception { client.start(); try { BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH) .buildQueue(); @@ -686,7 +685,7 @@ public void testSimple() throws Exception { client.start(); try { BlockingQueueConsumer consumer = - new BlockingQueueConsumer(Mockito.mock(ConnectionStateListener.class)); + new BlockingQueueConsumer<>(new DummyConnectionStateListener()); queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH) .buildQueue(); diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/state/DummyConnectionStateListener.java b/curator-recipes/src/test/java/org/apache/curator/framework/state/DummyConnectionStateListener.java new file mode 100644 index 000000000..64d5ecc5e --- /dev/null +++ b/curator-recipes/src/test/java/org/apache/curator/framework/state/DummyConnectionStateListener.java @@ -0,0 +1,29 @@ +/* + * 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.framework.state; + +import org.apache.curator.framework.CuratorFramework; + +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 9761dd284..84cf0df0e 100644 --- a/curator-test-zk35/pom.xml +++ b/curator-test-zk35/pom.xml @@ -171,18 +171,6 @@ test - - org.mockito - mockito-core - test - - - - org.mockito - mockito-inline - test - - org.slf4j slf4j-log4j12 diff --git a/curator-test-zk36/pom.xml b/curator-test-zk36/pom.xml index 84f655e57..23f5fd0e4 100644 --- a/curator-test-zk36/pom.xml +++ b/curator-test-zk36/pom.xml @@ -184,18 +184,6 @@ test - - org.mockito - mockito-core - test - - - - org.mockito - mockito-inline - test - - org.awaitility awaitility diff --git a/pom.xml b/pom.xml index 0ea099385..82f4447ab 100644 --- a/pom.xml +++ b/pom.xml @@ -109,7 +109,6 @@ 1.1.10.4 3.3.0 4.1.1 - 4.11.0 @@ -369,18 +368,6 @@ ${slf4j-version} - - org.mockito - mockito-core - ${mockito-version} - - - - org.mockito - mockito-inline - ${mockito-version} - - org.assertj assertj-core