[ISSUE#9210] ConnectionBasedClient support add revision (#9239)
* ConnectionBasedClient support add revision * getRevision when get verifydata.
This commit is contained in:
parent
af22d35d6f
commit
f272c36df7
@ -288,7 +288,7 @@ public class DistroClientDataProcessor extends SmartSubscriber implements Distro
|
||||
}
|
||||
if (clientManager.isResponsibleClient(client)) {
|
||||
DistroClientVerifyInfo verifyData = new DistroClientVerifyInfo(client.getClientId(),
|
||||
client.recalculateRevision());
|
||||
client.getRevision());
|
||||
DistroKey distroKey = new DistroKey(client.getClientId(), TYPE);
|
||||
DistroData data = new DistroData(distroKey,
|
||||
ApplicationUtils.getBean(Serializer.class).serialize(verifyData));
|
||||
|
@ -49,7 +49,7 @@ public abstract class AbstractClient implements Client {
|
||||
|
||||
protected volatile long lastUpdatedTime;
|
||||
|
||||
private final AtomicLong revision;
|
||||
protected final AtomicLong revision;
|
||||
|
||||
public AbstractClient(Long revision) {
|
||||
lastUpdatedTime = System.currentTimeMillis();
|
||||
|
@ -74,4 +74,9 @@ public class ConnectionBasedClient extends AbstractClient {
|
||||
public boolean isExpire(long currentTime) {
|
||||
return !isNative() && currentTime - getLastRenewTime() > ClientConfig.getInstance().getClientExpiredTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long recalculateRevision() {
|
||||
return revision.addAndGet(1);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import java.util.Objects;
|
||||
* @author : ChenHao26
|
||||
* @ClassName: BatchInstancePublishInfo
|
||||
* @Date: 2022/4/21 16:19
|
||||
* @Description: TODO
|
||||
*/
|
||||
public class BatchInstancePublishInfo extends InstancePublishInfo {
|
||||
|
||||
|
@ -27,13 +27,6 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* AbstractClient test.
|
||||
* @ClassName: AbstractClientTest
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/3 16:22
|
||||
* @Description: TODO
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AbstractClientTest {
|
||||
|
||||
|
@ -16,13 +16,6 @@
|
||||
|
||||
package com.alibaba.nacos.naming.core.v2.client;
|
||||
|
||||
/**
|
||||
* Mock AbstractClient.
|
||||
* @ClassName: MockAbstractClient
|
||||
* @Author: ChenHao26
|
||||
* @Date: 2022/8/3 16:25
|
||||
* @Description: TODO
|
||||
*/
|
||||
public class MockAbstractClient extends AbstractClient {
|
||||
|
||||
public MockAbstractClient(Long revision) {
|
||||
|
@ -20,6 +20,9 @@ import com.alibaba.nacos.naming.misc.ClientConfig;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConnectionBasedClientTest {
|
||||
@ -47,4 +50,26 @@ public class ConnectionBasedClientTest {
|
||||
connectionBasedClient.getLastRenewTime() + 2 * ClientConfig.getInstance().getClientExpiredTime();
|
||||
assertTrue(connectionBasedClient.isExpire(mustExpireTime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecalculateRevision() {
|
||||
assertEquals(0, connectionBasedClient.getRevision());
|
||||
connectionBasedClient.recalculateRevision();
|
||||
assertEquals(1, connectionBasedClient.getRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecalculateRevisionAsync() throws InterruptedException {
|
||||
assertEquals(0, connectionBasedClient.getRevision());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Thread thread = new Thread(() -> {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
connectionBasedClient.recalculateRevision();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
assertEquals(100, connectionBasedClient.getRevision());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user