Skip to content

Commit

Permalink
update version & fix & add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
huanglongchao committed Mar 14, 2024
1 parent 48ec2f2 commit ad8001e
Show file tree
Hide file tree
Showing 37 changed files with 152 additions and 38 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.0
6.5.0
2 changes: 1 addition & 1 deletion client/all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-all</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>

<name>${project.groupId}:${project.artifactId}</name>
<url>http://github.com/alipay/sofa-registry</url>
Expand Down
2 changes: 1 addition & 1 deletion client/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion client/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ private boolean connect() {
for (int i = 0; i < serverNodes.size(); i++) {
try {
// Power of Two Choices
if(serverNodes.size() > 1){
choosed = serverNodes.get(i).getWeight() > serverNodes.get(i+1).getWeight() ? i + 1 : i;
if (serverNodes.size() > 1) {
choosed = serverNodes.get(i).getWeight() > serverNodes.get(i + 1).getWeight() ? i + 1 : i;
}
connection = connect(serverNodes.get(choosed));
if (null != connection && connection.isFine()) {
Expand Down
2 changes: 1 addition & 1 deletion client/log/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>

<packaging>pom</packaging>

Expand Down
2 changes: 1 addition & 1 deletion server/common/model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-common</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-server-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/common/util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-common</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/distribution/all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-distribution</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-server-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion server/remoting/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-remoting</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/remoting/bolt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-remoting</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/remoting/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-remoting</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/remoting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-server-parent</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/server/data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-server</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/server/integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-server</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/server/meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-server</artifactId>
<version>6.4.0</version>
<version>6.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public void start() {
LOG.info("InterfaceAppsIndexCleaner started");
}

protected AppRevision revisionConvert(AppRevision revision) {
return revision;
}

public void renew() {
if (!metaLeaderService.amILeader()) {
return;
Expand Down Expand Up @@ -134,7 +138,9 @@ public void renew() {
}
}
LOG.info("renew interface apps index succeed");
consecutiveSuccess.success();
} catch (Throwable e) {
consecutiveSuccess.fail();
LOG.error("renew interface apps index failed:", e);
}
}
Expand Down Expand Up @@ -165,10 +171,10 @@ void cleanup() {
}
int count =
interfaceAppsRepository.cleanDeleted(
dateBeforeNow(metadataConfig.getRevisionRenewIntervalMinutes() * 15),
dateBeforeNow(metadataConfig.getInterfaceAppsIndexRenewIntervalMinutes() * 15),
metaServerConfig.getInterfaceMaxRemove());
if (count > 0) {
LOG.info("clean up {} revisions", count);
LOG.info("clean up {} interface app", count);
}
}

Expand Down Expand Up @@ -214,7 +220,7 @@ public void runUnthrowable() {
final class Cleaner extends WakeUpLoopRunnable {
@Override
public int getWaitingMillis() {
int base = metadataConfig.getRevisionRenewIntervalMinutes() * 1000 * 60;
int base = metadataConfig.getInterfaceAppsIndexRenewIntervalMinutes() * 1000 * 60;
return (int) (base + Math.random() * base);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@

import static org.mockito.Mockito.*;

import com.alipay.sofa.registry.cache.ConsecutiveSuccess;
import com.alipay.sofa.registry.common.model.console.PersistenceDataBuilder;
import com.alipay.sofa.registry.common.model.constants.ValueConstants;
import com.alipay.sofa.registry.jdbc.config.MetadataConfig;
import com.alipay.sofa.registry.jdbc.domain.AppRevisionDomain;
import com.alipay.sofa.registry.jdbc.domain.InterfaceAppsIndexDomain;
import com.alipay.sofa.registry.jdbc.repository.impl.DateNowJdbcRepository;
import com.alipay.sofa.registry.server.meta.AbstractMetaServerTestBase;
import com.alipay.sofa.registry.server.meta.bootstrap.config.MetaServerConfigBean;
import com.alipay.sofa.registry.server.meta.provide.data.DefaultProvideDataService;
import com.alipay.sofa.registry.store.api.DBResponse;
import com.alipay.sofa.registry.store.api.OperationStatus;
import com.alipay.sofa.registry.store.api.repository.AppRevisionRepository;
import com.alipay.sofa.registry.store.api.repository.InterfaceAppsRepository;
import java.util.Date;
import org.assertj.core.util.Lists;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -35,11 +45,32 @@ public class InterfaceAppsIndexCleanerTest extends AbstractMetaServerTestBase {
public void beforeTest() throws Exception {
makeMetaLeader();
interfaceAppsIndexCleaner = new InterfaceAppsIndexCleaner(metaLeaderService);
interfaceAppsIndexCleaner.dateNowRepository = mock(DateNowJdbcRepository.class);
interfaceAppsIndexCleaner.appRevisionRepository = mock(AppRevisionRepository.class);
interfaceAppsIndexCleaner.interfaceAppsRepository = mock(InterfaceAppsRepository.class);
interfaceAppsIndexCleaner.metadataConfig = mock(MetadataConfig.class);
interfaceAppsIndexCleaner.consecutiveSuccess = new ConsecutiveSuccess(2, 10000);
interfaceAppsIndexCleaner.provideDataService = mock(DefaultProvideDataService.class);

when(interfaceAppsIndexCleaner.metadataConfig.getInterfaceAppsIndexRenewIntervalMinutes())
.thenReturn(10000);
interfaceAppsIndexCleaner.metaServerConfig = new MetaServerConfigBean(commonConfig);

doReturn(
new DBResponse<>(
PersistenceDataBuilder.createPersistenceData(
ValueConstants.INTERFACE_APP_CLEANER_ENABLED_DATA_ID, "true"),
OperationStatus.SUCCESS))
.when(interfaceAppsIndexCleaner.provideDataService)
.queryProvideData(anyString());

doReturn(true).when(interfaceAppsIndexCleaner.provideDataService).saveProvideData(any());
}

@After
public void afterTest() {
interfaceAppsIndexCleaner.cleaner.close();
interfaceAppsIndexCleaner.renewer.close();
}

@Test
Expand Down Expand Up @@ -72,4 +103,33 @@ public void testClean() {
mocked.renew();
mocked.renew();
}

@Test
public void testCleanInterface() throws Exception {
InterfaceAppsIndexCleaner mocked = spy(interfaceAppsIndexCleaner);
doReturn(1).when(mocked.interfaceAppsRepository).cleanDeleted(any(), anyInt());
doReturn(new Date()).when(mocked.dateNowRepository).getNow();
mocked.renew();
mocked.renew();
mocked.cleanup();
makeMetaNonLeader();
mocked.cleanup();
}

@Test
public void testEnable() throws Exception {
InterfaceAppsIndexCleaner mocked = spy(interfaceAppsIndexCleaner);
doReturn(1).when(mocked.interfaceAppsRepository).cleanDeleted(any(), anyInt());
doReturn(new Date()).when(mocked.dateNowRepository).getNow();
mocked.setEnabled(true);
mocked.startRenew();
mocked.cleaner.getWaitingMillis();
mocked.cleaner.runUnthrowable();
}

@Test(expected = RuntimeException.class)
public void testEnableThrowEx() {
doThrow(new RuntimeException()).when(interfaceAppsIndexCleaner.provideDataService).saveProvideData(any());
interfaceAppsIndexCleaner.setEnabled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.mockito.Mockito.when;

import com.alipay.sofa.registry.common.model.ProcessId;
import com.alipay.sofa.registry.common.model.metaserver.Lease;
import com.alipay.sofa.registry.common.model.metaserver.inter.heartbeat.HeartbeatRequest;
import com.alipay.sofa.registry.common.model.metaserver.nodes.SessionNode;
import com.alipay.sofa.registry.common.model.slot.SlotConfig;
Expand Down Expand Up @@ -160,4 +161,20 @@ public void testOnHeartbeat() {
.setSlotTable(slotTable));
Assert.assertNotEquals(SlotTable.INIT, slotManager.getSlotTable());
}

@Test
public void testWeightChange() {
List<SessionNode> sessionNodes = randomSessionNodes(10);
for (SessionNode sessionNode : sessionNodes) {
sessionManager.register(new Lease<>(sessionNode, 10000));
}
SessionNode sessionNode =
new SessionNode(
sessionNodes.get(0).getNodeUrl(),
sessionNodes.get(0).getRegionId(),
sessionNodes.get(0).getProcessId(),
1);
sessionManager.renew(sessionNode, 1000);
Assert.assertEquals(10, sessionManager.getSessionServerMetaInfo().getClusterMembers().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
import static org.mockito.Mockito.when;

import com.alipay.sofa.registry.common.model.CommonResponse;
import com.alipay.sofa.registry.common.model.ProcessId;
import com.alipay.sofa.registry.common.model.constants.ValueConstants;
import com.alipay.sofa.registry.common.model.metaserver.Lease;
import com.alipay.sofa.registry.common.model.metaserver.nodes.DataNode;
import com.alipay.sofa.registry.common.model.metaserver.nodes.MetaNode;
import com.alipay.sofa.registry.common.model.metaserver.nodes.SessionNode;
import com.alipay.sofa.registry.common.model.store.URL;
import com.alipay.sofa.registry.exception.SofaRegistryRuntimeException;
import com.alipay.sofa.registry.server.meta.AbstractMetaServerTestBase;
import com.alipay.sofa.registry.server.meta.lease.filter.DefaultForbiddenServerManager;
Expand Down Expand Up @@ -119,4 +124,21 @@ public void testRejoinServerGroup() {
Assert.assertTrue(
registryForbiddenServerManager.allowSelect(new Lease<>(new SimpleNode("127.0.0.1"), 100)));
}

@Test
public void testDistinguishServerGroup() {
ProcessId processId1 = new ProcessId("test", 1, 2, 3);
CommonResponse response = resource.kickoffServer("testCell", "DATA", "127.0.0.1");
Assert.assertTrue(response.isSuccess());
Assert.assertTrue(
registryForbiddenServerManager.allowSelect(
new Lease<>(
new SessionNode(new URL("127.0.0.1", 8888), "regionId", processId1, 0), 100)));
Assert.assertFalse(
registryForbiddenServerManager.allowSelect(
new Lease<>(new DataNode(new URL("127.0.0.1", 8888), "regionId"), 100)));
Assert.assertTrue(
registryForbiddenServerManager.allowSelect(
new Lease<>(new MetaNode(new URL("127.0.0.1", 8888), "regionId"), 100)));
}
}
Loading

0 comments on commit ad8001e

Please sign in to comment.