You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by ru...@apache.org on 2020/12/28 01:13:08 UTC

[incubator-ratis] branch master updated: RATIS-1271. Bump mockito version. (#381)

This is an automated email from the ASF dual-hosted git repository.

runzhiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 07fa7a3  RATIS-1271. Bump mockito version. (#381)
07fa7a3 is described below

commit 07fa7a3a69f18df5bc92cb6dd784d3001b6cf7d1
Author: Tsz-Wo Nicholas Sze <sz...@apache.org>
AuthorDate: Mon Dec 28 09:13:00 2020 +0800

    RATIS-1271. Bump mockito version. (#381)
    
    * RATIS-1271. Bump mockito version.
---
 pom.xml                                                    |  6 +++---
 ratis-common/pom.xml                                       |  6 ------
 ratis-examples/pom.xml                                     |  5 -----
 ratis-grpc/pom.xml                                         |  2 +-
 ratis-hadoop/pom.xml                                       |  5 -----
 ratis-logservice/pom.xml                                   |  6 +-----
 ratis-metrics/pom.xml                                      |  2 +-
 ratis-replicated-map/pom.xml                               |  5 -----
 ratis-server/pom.xml                                       |  2 +-
 .../apache/ratis/server/raftlog/segmented/LogSegment.java  |  8 +-------
 .../src/test/java/org/apache/ratis/RaftTestUtil.java       | 13 ++++++++++++-
 .../org/apache/ratis/server/impl/RaftServerTestUtil.java   |  4 ++--
 ratis-test/pom.xml                                         |  2 +-
 .../org/apache/ratis/server/storage/TestRaftStorage.java   |  4 ++--
 .../mockito-extensions/org.mockito.plugins.MockMaker       | 14 ++++++++++++++
 15 files changed, 39 insertions(+), 45 deletions(-)

diff --git a/pom.xml b/pom.xml
index d7bc110..9828d3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -199,7 +199,7 @@
     <!--
       ! Can be removed if changing to ASF parent version 19
     -->
-    <apache-rat-plugin.version>0.12</apache-rat-plugin.version>
+    <apache-rat-plugin.version>0.13</apache-rat-plugin.version>
     <build-helper-maven-plugin.version>1.9</build-helper-maven-plugin.version>
     <exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
     <findbugs.version>3.0.0</findbugs.version>
@@ -483,8 +483,8 @@
       </dependency>
       <dependency>
         <groupId>org.mockito</groupId>
-        <artifactId>mockito-all</artifactId>
-        <version>1.8.5</version>
+        <artifactId>mockito-core</artifactId>
+        <version>3.5.15</version>
       </dependency>
 	    <dependency>
 	      <groupId>org.jline</groupId>
diff --git a/ratis-common/pom.xml b/ratis-common/pom.xml
index b1921d7..0f75c49 100644
--- a/ratis-common/pom.xml
+++ b/ratis-common/pom.xml
@@ -47,11 +47,5 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <scope>test</scope>
-    </dependency>
-
   </dependencies>
 </project>
diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml
index bd4b116..da6b88d 100644
--- a/ratis-examples/pom.xml
+++ b/ratis-examples/pom.xml
@@ -139,11 +139,6 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
   <build>
     <plugins>
diff --git a/ratis-grpc/pom.xml b/ratis-grpc/pom.xml
index 2b291e8..312c79a 100644
--- a/ratis-grpc/pom.xml
+++ b/ratis-grpc/pom.xml
@@ -79,7 +79,7 @@
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>
diff --git a/ratis-hadoop/pom.xml b/ratis-hadoop/pom.xml
index ab19cdd..ba47fdf 100644
--- a/ratis-hadoop/pom.xml
+++ b/ratis-hadoop/pom.xml
@@ -78,11 +78,6 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <scope>test</scope>
-    </dependency>
 
     <dependency>
       <groupId>org.apache.hadoop</groupId>
diff --git a/ratis-logservice/pom.xml b/ratis-logservice/pom.xml
index ce74b4e..87bbadc 100644
--- a/ratis-logservice/pom.xml
+++ b/ratis-logservice/pom.xml
@@ -261,11 +261,7 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <scope>test</scope>
-    </dependency>
+
 
     <!-- Needed for Archive log reader and writer testing-->
     <dependency>
diff --git a/ratis-metrics/pom.xml b/ratis-metrics/pom.xml
index a25a3fa..c9a29a6 100644
--- a/ratis-metrics/pom.xml
+++ b/ratis-metrics/pom.xml
@@ -44,7 +44,7 @@
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/ratis-replicated-map/pom.xml b/ratis-replicated-map/pom.xml
index 5688625..8c08e4b 100644
--- a/ratis-replicated-map/pom.xml
+++ b/ratis-replicated-map/pom.xml
@@ -109,10 +109,5 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 </project>
diff --git a/ratis-server/pom.xml b/ratis-server/pom.xml
index 3959e40..4f17a2d 100644
--- a/ratis-server/pom.xml
+++ b/ratis-server/pom.xml
@@ -81,7 +81,7 @@
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java
index 672d304..c14d309 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java
@@ -52,13 +52,7 @@ import java.util.function.Consumer;
  *
  * This class will be protected by the {@link SegmentedRaftLog}'s read-write lock.
  */
-@SuppressWarnings("checkstyle:FinalClass")
-public class LogSegment implements Comparable<Long> {
-
-  //TODO: This class needs to be made final to address checkstyle issue. However, TestCacheEviction fails as Mockito
-  // cannot spy final class. This problem can be fixed when stable version of Mockito 2.x is available which provides
-  // a feature to mock final class/method.
-
+public final class LogSegment implements Comparable<Long> {
   static final Logger LOG = LoggerFactory.getLogger(LogSegment.class);
 
   enum Op {
diff --git a/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java b/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
index 6987d0a..7279c1d 100644
--- a/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
+++ b/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
@@ -48,6 +48,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.EnumMap;
@@ -67,10 +68,20 @@ import java.util.function.Predicate;
 import java.util.function.Supplier;
 import java.util.stream.StreamSupport;
 
-
 public interface RaftTestUtil {
   Logger LOG = LoggerFactory.getLogger(RaftTestUtil.class);
 
+  static Object getDeclaredField(Object obj, String fieldName) {
+    final Class<?> clazz = obj.getClass();
+    try {
+      final Field f = clazz.getDeclaredField(fieldName);
+      f.setAccessible(true);
+      return f.get(obj);
+    } catch (Exception e) {
+      throw new RuntimeException("Failed to get '" + fieldName + "' from " + clazz, e);
+    }
+  }
+
   static RaftServer.Division waitForLeader(MiniRaftCluster cluster)
       throws InterruptedException {
     return waitForLeader(cluster, null);
diff --git a/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftServerTestUtil.java b/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftServerTestUtil.java
index 88238ca..f7303f9 100644
--- a/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftServerTestUtil.java
+++ b/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftServerTestUtil.java
@@ -18,6 +18,7 @@
 package org.apache.ratis.server.impl;
 
 import org.apache.log4j.Level;
+import org.apache.ratis.RaftTestUtil;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.protocol.RaftGroupMemberId;
@@ -37,7 +38,6 @@ import org.apache.ratis.util.Log4jUtils;
 import org.apache.ratis.util.TimeDuration;
 import org.junit.Assert;
 import org.mockito.Mockito;
-import org.mockito.internal.util.reflection.Whitebox;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -119,7 +119,7 @@ public class RaftServerTestUtil {
   }
 
   public static ConfigurationManager getConfigurationManager(RaftServer.Division server) {
-    return (ConfigurationManager) Whitebox.getInternalState(getState(server), "configurationManager");
+    return (ConfigurationManager) RaftTestUtil.getDeclaredField(getState(server), "configurationManager");
   }
 
   public static RaftConfiguration newRaftConfiguration(Collection<RaftPeer> peers) {
diff --git a/ratis-test/pom.xml b/ratis-test/pom.xml
index 9efe6a2..29d197d 100644
--- a/ratis-test/pom.xml
+++ b/ratis-test/pom.xml
@@ -94,7 +94,7 @@
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
 
diff --git a/ratis-test/src/test/java/org/apache/ratis/server/storage/TestRaftStorage.java b/ratis-test/src/test/java/org/apache/ratis/server/storage/TestRaftStorage.java
index 8cc2eea..0dc85d8 100644
--- a/ratis-test/src/test/java/org/apache/ratis/server/storage/TestRaftStorage.java
+++ b/ratis-test/src/test/java/org/apache/ratis/server/storage/TestRaftStorage.java
@@ -20,6 +20,7 @@ package org.apache.ratis.server.storage;
 import static org.apache.ratis.statemachine.impl.SimpleStateMachineStorage.SNAPSHOT_REGEX;
 
 import org.apache.ratis.BaseTest;
+import org.apache.ratis.RaftTestUtil;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.server.protocol.TermIndex;
 import org.apache.ratis.server.storage.RaftStorageDirectoryImpl.StorageState;
@@ -30,7 +31,6 @@ import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.internal.util.reflection.Whitebox;
 
 import java.io.File;
 import java.io.IOException;
@@ -136,7 +136,7 @@ public class TestRaftStorage extends BaseTest {
     Assert.assertEquals(metadata, metaFile.getMetadata());
 
     final RaftStorageMetadataFile metaFile2 = new RaftStorageMetadataFileImpl(m);
-    Assert.assertNull(((AtomicReference<?>) Whitebox.getInternalState(metaFile2, "metadata")).get());
+    Assert.assertNull(((AtomicReference<?>) RaftTestUtil.getDeclaredField(metaFile2, "metadata")).get());
     Assert.assertEquals(metadata, metaFile2.getMetadata());
   }
 
diff --git a/ratis-test/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/ratis-test/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 0000000..7196fbd
--- /dev/null
+++ b/ratis-test/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1,14 @@
+#   Licensed 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.
+# log4j configuration used during build and unit tests
+
+mock-maker-inline