You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2021/08/13 02:05:28 UTC

[incubator-eventmesh] branch develop updated: use RandomStringGenerator instead deprecated class RandomStringUtils (#495)

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

mikexue pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/develop by this push:
     new c365fa0  use RandomStringGenerator instead deprecated class RandomStringUtils (#495)
c365fa0 is described below

commit c365fa00e4baae0fa79973747106007e274fe397
Author: YuDong Tang <58...@qq.com>
AuthorDate: Fri Aug 13 10:05:23 2021 +0800

    use RandomStringGenerator instead deprecated class RandomStringUtils (#495)
---
 .../eventmesh/runtime/util/EventMeshUtil.java      |  7 +++--
 .../eventmesh/runtime/util/EventMeshUtilTest.java  | 33 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java
index 1d0cd9c..11542a2 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java
@@ -40,9 +40,8 @@ import com.fasterxml.jackson.databind.SerializationFeature;
 
 import io.openmessaging.api.Message;
 
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.text.RandomStringGenerator;
 import org.apache.eventmesh.common.Constants;
 import org.apache.eventmesh.common.ThreadUtil;
 import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage;
@@ -56,8 +55,10 @@ public class EventMeshUtil {
 
     public static Logger logger = LoggerFactory.getLogger(EventMeshUtil.class);
 
+    private static final RandomStringGenerator RANDOM_GENERATOR = new RandomStringGenerator.Builder().withinRange('0', '9').build();
+
     public static String buildPushMsgSeqNo() {
-        return StringUtils.rightPad(String.valueOf(System.currentTimeMillis()), 6) + String.valueOf(RandomStringUtils.randomNumeric(4));
+        return StringUtils.rightPad(String.valueOf(System.currentTimeMillis()), 6) + RANDOM_GENERATOR.generate(4);
     }
 
     public static String buildMeshClientID(String clientGroup, String meshCluster) {
diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/EventMeshUtilTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/EventMeshUtilTest.java
new file mode 100644
index 0000000..6f55615
--- /dev/null
+++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/EventMeshUtilTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.eventmesh.runtime.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.regex.Pattern;
+
+public class EventMeshUtilTest {
+
+    @Test
+    public void testBuildPushMsgSeqNo() {
+        String seq = EventMeshUtil.buildPushMsgSeqNo();
+        Assert.assertTrue(Pattern.compile("\\d{17}").matcher(seq).matches());
+        Assert.assertEquals(17, seq.length());
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org