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

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


The following commit(s) were added to refs/heads/master by this push:
     new a136a62  RATIS-1423. Remove commons.lang3 dependency from 
ratis-examples and ratis-test. (#526)
a136a62 is described below

commit a136a626451c44c592397ebdcb28d9c634b4ef55
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Thu Nov 11 16:32:43 2021 +0800

    RATIS-1423. Remove commons.lang3 dependency from ratis-examples and 
ratis-test. (#526)
---
 pom.xml                                            |  3 ---
 ratis-examples/pom.xml                             |  5 ----
 .../test/java/org/apache/ratis/RaftTestUtil.java   |  6 ++++-
 ratis-test/pom.xml                                 |  6 -----
 .../apache/ratis/grpc/TestRaftServerWithGrpc.java  | 27 +++++++++++++++++-----
 5 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/pom.xml b/pom.xml
index 437add6..9d180a0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -226,9 +226,6 @@
     <!--metrics-->
     <dropwizard.version>3.2.5</dropwizard.version>
 
-    <!-- commons lang version -->
-    <commons.lang.version>3.8.1</commons.lang.version>
-
     <!-- LOG4J version -->
     <log4j.version>1.2.17</log4j.version>
 
diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml
index 627a348..3df32a1 100644
--- a/ratis-examples/pom.xml
+++ b/ratis-examples/pom.xml
@@ -58,11 +58,6 @@
       <groupId>org.apache.ratis</groupId>
     </dependency>
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-      <version>3.5</version>
-    </dependency>
-    <dependency>
       <artifactId>ratis-server</artifactId>
       <groupId>org.apache.ratis</groupId>
       <scope>test</scope>
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 6314677..f54e7db 100644
--- a/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
+++ b/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
@@ -324,8 +324,12 @@ public interface RaftTestUtil {
     final ByteString bytes;
 
     public SimpleMessage(final String messageId) {
+      this(messageId, ProtoUtils.toByteString(messageId));
+    }
+
+    public SimpleMessage(final String messageId, ByteString bytes) {
       this.messageId = messageId;
-      this.bytes = ProtoUtils.toByteString(messageId);
+      this.bytes = bytes;
     }
 
     @Override
diff --git a/ratis-test/pom.xml b/ratis-test/pom.xml
index a9937f0..58b8d3c 100644
--- a/ratis-test/pom.xml
+++ b/ratis-test/pom.xml
@@ -105,11 +105,5 @@
       <artifactId>metrics-jvm</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-      <version>${commons.lang.version}</version>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 </project>
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java 
b/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java
index 71783e8..230c488 100644
--- a/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java
+++ b/ratis-test/src/test/java/org/apache/ratis/grpc/TestRaftServerWithGrpc.java
@@ -27,7 +27,6 @@ import static 
org.apache.ratis.server.metrics.RaftServerMetricsImpl.REQUEST_BYTE
 import static 
org.apache.ratis.server.metrics.RaftServerMetricsImpl.RESOURCE_LIMIT_HIT_COUNTER;
 
 import com.codahale.metrics.Gauge;
-import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.log4j.Level;
 import org.apache.ratis.BaseTest;
 import org.apache.ratis.protocol.RaftGroup;
@@ -56,6 +55,7 @@ import org.apache.ratis.server.impl.RaftServerTestUtil;
 import org.apache.ratis.server.metrics.RaftServerMetricsImpl;
 import org.apache.ratis.statemachine.SimpleStateMachine4Testing;
 import org.apache.ratis.statemachine.StateMachine;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
 import org.apache.ratis.util.Log4jUtils;
 import org.apache.ratis.util.ProtoUtils;
 import org.apache.ratis.util.SizeInBytes;
@@ -72,6 +72,7 @@ import java.util.List;
 import java.util.SortedMap;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -230,7 +231,6 @@ public class TestRaftServerWithGrpc extends BaseTest 
implements MiniRaftClusterW
     SimpleStateMachine4Testing stateMachine = 
SimpleStateMachine4Testing.get(cluster.getLeader());
     stateMachine.blockFlushStateMachineData();
 
-    String message = "2nd Message";
     // Block stateMachine flush data, so that 2nd request will not be
     // completed, and so it will not be removed from pending request map.
     List<RaftClient> clients = new ArrayList<>();
@@ -238,7 +238,7 @@ public class TestRaftServerWithGrpc extends BaseTest 
implements MiniRaftClusterW
     try {
       RaftClient client = cluster.createClient(cluster.getLeader().getId(), 
RetryPolicies.noRetry());
       clients.add(client);
-      client.async().send(new SimpleMessage(message));
+      client.async().send(new SimpleMessage("2nd Message"));
 
 
       final SortedMap<String, Gauge> gaugeMap = 
getRaftServerMetrics(cluster.getLeader())
@@ -249,7 +249,7 @@ public class TestRaftServerWithGrpc extends BaseTest 
implements MiniRaftClusterW
       for (int i = 0; i < 10; i++) {
         client = cluster.createClient(cluster.getLeader().getId(), 
RetryPolicies.noRetry());
         clients.add(client);
-        client.async().send(new SimpleMessage(message));
+        client.async().send(new SimpleMessage("message " + i));
       }
 
       // Because we have passed 11 requests, and the element queue size is 10.
@@ -262,8 +262,10 @@ public class TestRaftServerWithGrpc extends BaseTest 
implements MiniRaftClusterW
       // and byte size counter limit will be hit.
 
       client = cluster.createClient(cluster.getLeader().getId(), 
RetryPolicies.noRetry());
-      client.async().send(new SimpleMessage(RandomStringUtils
-          .random(SizeInBytes.valueOf("1025kb").getSizeInt(), true, false)));
+      final SizeInBytes size = SizeInBytes.valueOf("1025kb");
+      final ByteString bytes = randomByteString(size.getSizeInt());
+      Assert.assertEquals(size.getSizeInt(), bytes.size());
+      client.async().send(new SimpleMessage(size + "-message", bytes));
       clients.add(client);
 
       RaftTestUtil.waitFor(() -> getRaftServerMetrics(cluster.getLeader())
@@ -277,6 +279,19 @@ public class TestRaftServerWithGrpc extends BaseTest 
implements MiniRaftClusterW
       }
     }
   }
+  
+  static ByteString randomByteString(int size) {
+    final ByteString.Output out = ByteString.newOutput(size);
+    final ThreadLocalRandom random = ThreadLocalRandom.current();
+    final byte[] buffer = new byte[4096];
+    for(; size > 0; ) {
+      random.nextBytes(buffer);
+      final int n = Math.min(size, buffer.length);
+      out.write(buffer, 0, n);
+      size -= n;
+    }
+    return out.toByteString();
+  }
 
   static RaftServerMetricsImpl getRaftServerMetrics(RaftServer.Division 
division) {
     return (RaftServerMetricsImpl) division.getRaftServerMetrics();

Reply via email to