This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.1 by this push:
new f882cbdd80 Use random id (#12663)
f882cbdd80 is described below
commit f882cbdd80df0d92bdbe74ff70035b224e13172c
Author: Albumen Kevin <[email protected]>
AuthorDate: Thu Jul 6 17:54:47 2023 +0800
Use random id (#12663)
* Use random id
* Fix uts
---
.../src/main/java/org/apache/dubbo/remoting/exchange/Request.java | 3 ++-
.../src/test/java/org/apache/dubbo/remoting/exchange/RequestTest.java | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java
index d75a21a323..c243258a24 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.remoting.exchange;
import org.apache.dubbo.common.utils.StringUtils;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;
import static
org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT;
@@ -27,7 +28,7 @@ import static
org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT;
*/
public class Request {
- private static final AtomicLong INVOKE_ID = new AtomicLong(0);
+ private static final AtomicLong INVOKE_ID = new
AtomicLong(ThreadLocalRandom.current().nextLong());
private final long mId;
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/RequestTest.java
b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/RequestTest.java
index f0a8988ee7..d358ffaa4c 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/RequestTest.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/RequestTest.java
@@ -23,6 +23,8 @@ class RequestTest {
@Test
void test() {
+ Request requestStart = new Request();
+
Request request = new Request();
request.setTwoWay(true);
request.setBroken(true);
@@ -35,7 +37,7 @@ class RequestTest {
Assertions.assertTrue(request.isEvent());
Assertions.assertEquals(request.getVersion(), "1.0.0");
Assertions.assertEquals(request.getData(), "data");
- Assertions.assertTrue(request.getId() >= 0);
+ Assertions.assertEquals(requestStart.getId() + 1, request.getId());
request.setHeartbeat(true);
Assertions.assertTrue(request.isHeartbeat());