Use random id (#12663)

* Use random id

* Fix uts
This commit is contained in:
Albumen Kevin 2023-07-06 17:54:47 +08:00 committed by GitHub
parent 9ae97ea053
commit f882cbdd80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package org.apache.dubbo.remoting.exchange;
import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.StringUtils;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT; 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 { 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; private final long mId;

View File

@ -23,6 +23,8 @@ class RequestTest {
@Test @Test
void test() { void test() {
Request requestStart = new Request();
Request request = new Request(); Request request = new Request();
request.setTwoWay(true); request.setTwoWay(true);
request.setBroken(true); request.setBroken(true);
@ -35,7 +37,7 @@ class RequestTest {
Assertions.assertTrue(request.isEvent()); Assertions.assertTrue(request.isEvent());
Assertions.assertEquals(request.getVersion(), "1.0.0"); Assertions.assertEquals(request.getVersion(), "1.0.0");
Assertions.assertEquals(request.getData(), "data"); Assertions.assertEquals(request.getData(), "data");
Assertions.assertTrue(request.getId() >= 0); Assertions.assertEquals(requestStart.getId() + 1, request.getId());
request.setHeartbeat(true); request.setHeartbeat(true);
Assertions.assertTrue(request.isHeartbeat()); Assertions.assertTrue(request.isHeartbeat());