Repository: incubator-ratis
Updated Branches:
  refs/heads/master 6a755e66f -> f1716ac43


http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
index c31665f..e625363 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/storage/SegmentedRaftLog.java
@@ -17,8 +17,6 @@
  */
 package org.apache.ratis.server.storage;
 
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import org.apache.commons.io.Charsets;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.protocol.RaftPeerId;
@@ -30,6 +28,7 @@ import 
org.apache.ratis.server.storage.RaftStorageDirectory.LogPathAndIndex;
 import org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto;
 import org.apache.ratis.util.AutoCloseableLock;
 import org.apache.ratis.util.CodeInjectionForTesting;
+import org.apache.ratis.util.RaftUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -214,7 +213,7 @@ public class SegmentedRaftLog extends RaftLog {
         // the term changes
         final long currentTerm = currentOpenSegment.getLastRecord().entry
             .getTerm();
-        Preconditions.checkState(currentTerm < entry.getTerm(),
+        RaftUtils.assertTrue(currentTerm < entry.getTerm(),
             "open segment's term %s is larger than the new entry's term %s",
             currentTerm, entry.getTerm());
         cache.rollOpenSegment(true);
@@ -250,7 +249,7 @@ public class SegmentedRaftLog extends RaftLog {
       long truncateIndex = -1;
       for (; iter.hasNext() && index < entries.length; index++) {
         LogEntryProto storedEntry = iter.next();
-        Preconditions.checkState(
+        RaftUtils.assertTrue(
             storedEntry.getIndex() == entries[index].getIndex(),
             "The stored entry's index %s is not consistent with" +
                 " the received entries[%s]'s index %s", storedEntry.getIndex(),
@@ -320,7 +319,6 @@ public class SegmentedRaftLog extends RaftLog {
     storage.close();
   }
 
-  @VisibleForTesting
   RaftLogCache getRaftLogCache() {
     return cache;
   }

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java
index ca5525b..0b4e8fa 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java
@@ -34,8 +34,6 @@ import org.apache.ratis.util.RaftUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-
 /**
  * Manage snapshots of a raft peer.
  * TODO: snapshot should be treated as compaction log thus can be merged into
@@ -91,7 +89,7 @@ public class SnapshotManager {
           // create the temp snapshot file and put padding inside
           out = new FileOutputStream(tmpSnapshotFile);
         } else {
-          Preconditions.checkState(tmpSnapshotFile.exists());
+          RaftUtils.assertTrue(tmpSnapshotFile.exists());
           out = new FileOutputStream(tmpSnapshotFile, true);
           FileChannel fc = out.getChannel();
           fc.position(chunk.getOffset());

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/main/java/org/apache/ratis/statemachine/SimpleStateMachineStorage.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/main/java/org/apache/ratis/statemachine/SimpleStateMachineStorage.java
 
b/ratis-server/src/main/java/org/apache/ratis/statemachine/SimpleStateMachineStorage.java
index d417db7..5a34271 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/statemachine/SimpleStateMachineStorage.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/statemachine/SimpleStateMachineStorage.java
@@ -17,9 +17,6 @@
  */
 package org.apache.ratis.statemachine;
 
-
-import com.google.common.annotations.VisibleForTesting;
-
 import org.apache.ratis.io.MD5Hash;
 import org.apache.ratis.server.protocol.TermIndex;
 import org.apache.ratis.server.storage.FileInfo;
@@ -66,7 +63,6 @@ public class SimpleStateMachineStorage implements 
StateMachineStorage {
     // TODO
   }
 
-  @VisibleForTesting
   public static TermIndex getTermIndexFromSnapshotFile(File file) {
     final String name = file.getName();
     final Matcher m = SNAPSHOT_REGEX.matcher(name);

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java 
b/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java
index 0944b87..2a5f314 100644
--- a/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java
+++ b/ratis-server/src/test/java/org/apache/ratis/MiniRaftCluster.java
@@ -17,7 +17,6 @@
  */
 package org.apache.ratis;
 
-import com.google.common.base.Preconditions;
 import org.apache.ratis.client.ClientFactory;
 import org.apache.ratis.client.RaftClient;
 import org.apache.ratis.conf.Parameters;
@@ -118,7 +117,7 @@ public abstract class MiniRaftCluster {
 
   private static void formatDir(String dirStr) {
     final File serverDir = new File(dirStr);
-    Preconditions.checkState(FileUtils.fullyDelete(serverDir),
+    RaftUtils.assertTrue(FileUtils.fullyDelete(serverDir),
         "Failed to format directory %s", dirStr);
     LOG.info("Formatted directory {}", dirStr);
   }
@@ -160,7 +159,7 @@ public abstract class MiniRaftCluster {
 
   private RaftServerImpl putNewServer(RaftPeerId id, boolean format) {
     final RaftServerImpl s = newRaftServer(id, format);
-    Preconditions.checkState(servers.put(id, s) == null);
+    RaftUtils.assertTrue(servers.put(id, s) == null);
     return s;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
----------------------------------------------------------------------
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 5166249..0a8bfd5 100644
--- a/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
+++ b/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
@@ -17,7 +17,6 @@
  */
 package org.apache.ratis;
 
-import com.google.common.base.Preconditions;
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.ratis.protocol.Message;
 import org.apache.ratis.protocol.RaftPeerId;
@@ -39,6 +38,7 @@ import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Objects;
 import java.util.function.BooleanSupplier;
 import java.util.function.IntSupplier;
 
@@ -183,8 +183,7 @@ public class RaftTestUtil {
     private final String op;
 
     public SimpleOperation(String op) {
-      Preconditions.checkArgument(op != null);
-      this.op = op;
+      this.op = Objects.requireNonNull(op);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/test/java/org/apache/ratis/server/simulation/RaftServerReply.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/test/java/org/apache/ratis/server/simulation/RaftServerReply.java
 
b/ratis-server/src/test/java/org/apache/ratis/server/simulation/RaftServerReply.java
index a399f5f..7882fcc 100644
--- 
a/ratis-server/src/test/java/org/apache/ratis/server/simulation/RaftServerReply.java
+++ 
b/ratis-server/src/test/java/org/apache/ratis/server/simulation/RaftServerReply.java
@@ -22,7 +22,7 @@ import 
org.apache.ratis.shaded.proto.RaftProtos.AppendEntriesReplyProto;
 import org.apache.ratis.shaded.proto.RaftProtos.InstallSnapshotReplyProto;
 import org.apache.ratis.shaded.proto.RaftProtos.RequestVoteReplyProto;
 
-import com.google.common.base.Preconditions;
+import java.util.Objects;
 
 public class RaftServerReply implements RaftRpcMessage {
   private final AppendEntriesReplyProto appendEntries;
@@ -30,21 +30,21 @@ public class RaftServerReply implements RaftRpcMessage {
   private final InstallSnapshotReplyProto installSnapshot;
 
   RaftServerReply(AppendEntriesReplyProto a) {
-    appendEntries = Preconditions.checkNotNull(a);
+    appendEntries = Objects.requireNonNull(a);
     requestVote = null;
     installSnapshot = null;
   }
 
   RaftServerReply(RequestVoteReplyProto r) {
     appendEntries = null;
-    requestVote = Preconditions.checkNotNull(r);
+    requestVote = Objects.requireNonNull(r);
     installSnapshot = null;
   }
 
   RaftServerReply(InstallSnapshotReplyProto i) {
     appendEntries = null;
     requestVote = null;
-    installSnapshot = Preconditions.checkNotNull(i);
+    installSnapshot = Objects.requireNonNull(i);
   }
 
   boolean isAppendEntries() {

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRequestReply.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRequestReply.java
 
b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRequestReply.java
index 7fb2c2c..48c9d55 100644
--- 
a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRequestReply.java
+++ 
b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedRequestReply.java
@@ -17,9 +17,7 @@
  */
 package org.apache.ratis.server.simulation;
 
-import com.google.common.base.Preconditions;
 import org.apache.ratis.RaftTestUtil;
-import org.apache.ratis.protocol.RaftPeer;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.protocol.RaftRpcMessage;
 import org.apache.ratis.server.RaftServerConfigKeys;
@@ -27,7 +25,6 @@ import org.apache.ratis.util.RaftUtils;
 import org.apache.ratis.util.Timestamp;
 
 import java.io.IOException;
-import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -46,7 +43,7 @@ class SimulatedRequestReply<REQUEST extends RaftRpcMessage,
     private final IOException ioe;
 
     ReplyOrException(REPLY reply, IOException ioe) {
-      Preconditions.checkArgument(reply == null ^ ioe == null);
+      RaftUtils.assertTrue(reply == null ^ ioe == null);
       this.reply = reply;
       this.ioe = ioe;
     }
@@ -139,7 +136,7 @@ class SimulatedRequestReply<REQUEST extends RaftRpcMessage,
       RaftTestUtil.delay(q.delayTakeRequestTo::get);
 
       request = q.takeRequest();
-      Preconditions.checkState(qid.equals(request.getReplierId()));
+      RaftUtils.assertTrue(qid.equals(request.getReplierId()));
 
       // block request for testing
       final EventQueue<REQUEST, REPLY> reqQ = 
queues.get(request.getRequestorId());
@@ -156,9 +153,9 @@ class SimulatedRequestReply<REQUEST extends RaftRpcMessage,
   public void sendReply(REQUEST request, REPLY reply, IOException ioe)
       throws IOException {
     if (reply != null) {
-      Preconditions.checkArgument(
+      RaftUtils.assertTrue(
           request.getRequestorId().equals(reply.getRequestorId()));
-      Preconditions.checkArgument(
+      RaftUtils.assertTrue(
           request.getReplierId().equals(reply.getReplierId()));
     }
     simulateLatency();

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java
 
b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java
index 8344453..562dba5 100644
--- 
a/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java
+++ 
b/ratis-server/src/test/java/org/apache/ratis/server/simulation/SimulatedServerRpc.java
@@ -17,16 +17,14 @@
  */
 package org.apache.ratis.server.simulation;
 
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import org.apache.ratis.protocol.RaftClientReply;
 import org.apache.ratis.protocol.RaftClientRequest;
 import org.apache.ratis.protocol.RaftPeer;
 import org.apache.ratis.protocol.SetConfigurationRequest;
-import org.apache.ratis.rpc.SupportedRpcType;
-import org.apache.ratis.rpc.RpcType;
 import org.apache.ratis.server.RaftServerRpc;
 import org.apache.ratis.server.impl.RaftServerImpl;
 import org.apache.ratis.shaded.proto.RaftProtos.*;
+import org.apache.ratis.util.Daemon;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,8 +41,7 @@ class SimulatedServerRpc implements RaftServerRpc {
   private final RaftServerImpl server;
   private final RequestHandler<RaftServerRequest, RaftServerReply> 
serverHandler;
   private final RequestHandler<RaftClientRequest, RaftClientReply> 
clientHandler;
-  private final ExecutorService executor = Executors.newFixedThreadPool(3,
-      new ThreadFactoryBuilder().setDaemon(true).build());
+  private final ExecutorService executor = Executors.newFixedThreadPool(3, 
Daemon::new);
 
   SimulatedServerRpc(RaftServerImpl server,
       SimulatedRequestReply<RaftServerRequest, RaftServerReply> 
serverRequestReply,

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/test/java/org/apache/ratis/server/storage/TestRaftLogSegment.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/test/java/org/apache/ratis/server/storage/TestRaftLogSegment.java
 
b/ratis-server/src/test/java/org/apache/ratis/server/storage/TestRaftLogSegment.java
index f538421..89f4c08 100644
--- 
a/ratis-server/src/test/java/org/apache/ratis/server/storage/TestRaftLogSegment.java
+++ 
b/ratis-server/src/test/java/org/apache/ratis/server/storage/TestRaftLogSegment.java
@@ -153,8 +153,8 @@ public class TestRaftLogSegment {
       LogEntryProto entry = ProtoUtils.toLogEntryProto(m, 0, 1001, clientId, 
callId);
       segment.appendToOpenSegment(entry);
       Assert.fail("should fail since the entry's index needs to be 1000");
-    } catch (Exception e) {
-      Assert.assertTrue(e instanceof IllegalArgumentException);
+    } catch (IllegalStateException e) {
+      // the exception is expected.
     }
 
     LogEntryProto entry = ProtoUtils.toLogEntryProto(m, 0, 1000, clientId, 
callId);
@@ -164,8 +164,8 @@ public class TestRaftLogSegment {
       entry = ProtoUtils.toLogEntryProto(m, 0, 1002, clientId, callId);
       segment.appendToOpenSegment(entry);
       Assert.fail("should fail since the entry's index needs to be 1001");
-    } catch (Exception e) {
-      Assert.assertTrue(e instanceof IllegalArgumentException);
+    } catch (IllegalStateException e) {
+      // the exception is expected.
     }
 
     LogEntryProto[] entries = new LogEntryProto[2];
@@ -175,8 +175,8 @@ public class TestRaftLogSegment {
     try {
       segment.appendToOpenSegment(entries);
       Assert.fail("should fail since there is gap between entries");
-    } catch (Exception e) {
-      Assert.assertTrue(e instanceof IllegalArgumentException);
+    } catch (IllegalStateException e) {
+      // the exception is expected.
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
 
b/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
index f8c22b7..44c420c 100644
--- 
a/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
+++ 
b/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
@@ -17,14 +17,6 @@
  */
 package org.apache.ratis.statemachine;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-
 import org.apache.ratis.RaftTestUtil.SimpleMessage;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.io.MD5Hash;
@@ -44,10 +36,14 @@ import 
org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto;
 import org.apache.ratis.util.Daemon;
 import org.apache.ratis.util.LifeCycle;
 import org.apache.ratis.util.MD5FileUtil;
+import org.apache.ratis.util.RaftUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
 
 /**
  * A {@link StateMachine} implementation example that simply stores all the log
@@ -127,8 +123,7 @@ public class SimpleStateMachine4Testing extends 
BaseStateMachine {
 
   @Override
   public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
-    LogEntryProto entry = trx.getLogEntry().get();
-    Preconditions.checkNotNull(entry);
+    LogEntryProto entry = Objects.requireNonNull(trx.getLogEntry().get());
     list.add(entry);
     termIndexTracker.update(ServerProtoUtils.toTermIndex(entry));
     return CompletableFuture.completedFuture(
@@ -202,7 +197,7 @@ public class SimpleStateMachine4Testing extends 
BaseStateMachine {
           termIndexTracker.update(ServerProtoUtils.toTermIndex(entry));
         }
       }
-      Preconditions.checkState(
+      RaftUtils.assertTrue(
           !list.isEmpty() && endIndex == list.get(list.size() - 1).getIndex(),
           "endIndex=%s, list=%s", endIndex, list);
       this.endIndexLastCkpt = endIndex;

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/f1716ac4/ratis-server/src/test/java/org/apache/ratis/statemachine/TermIndexTracker.java
----------------------------------------------------------------------
diff --git 
a/ratis-server/src/test/java/org/apache/ratis/statemachine/TermIndexTracker.java
 
b/ratis-server/src/test/java/org/apache/ratis/statemachine/TermIndexTracker.java
index 31768e8..a282d97 100644
--- 
a/ratis-server/src/test/java/org/apache/ratis/statemachine/TermIndexTracker.java
+++ 
b/ratis-server/src/test/java/org/apache/ratis/statemachine/TermIndexTracker.java
@@ -17,11 +17,12 @@
  */
 package org.apache.ratis.statemachine;
 
-import static 
org.apache.ratis.server.impl.RaftServerConstants.INVALID_LOG_INDEX;
-
 import org.apache.ratis.server.protocol.TermIndex;
+import org.apache.ratis.util.RaftUtils;
 
-import com.google.common.base.Preconditions;
+import java.util.Objects;
+
+import static 
org.apache.ratis.server.impl.RaftServerConstants.INVALID_LOG_INDEX;
 
 /**
  * Tracks the term index that is applied to the StateMachine for simple state 
machines with
@@ -51,8 +52,8 @@ class TermIndexTracker {
    * this index in memory.
    */
   public synchronized void update(TermIndex termIndex) {
-    Preconditions.checkArgument(termIndex != null &&
-        termIndex.compareTo(current) >= 0);
+    Objects.requireNonNull(termIndex);
+    RaftUtils.assertTrue(termIndex.compareTo(current) >= 0);
     this.current = termIndex;
   }
 

Reply via email to