Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ servicecomb:
enabled: true
allowedHeaders: xxx
rest:
address: 0.0.0.0:18080
address: 0.0.0.0:18090
server:
# for test case run in one core machine
verticle-count: 1
Expand Down
4 changes: 2 additions & 2 deletions demo/docker-run-config-edge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@
-->
<tcp>
<ports>
<port>18080</port>
<port>18090</port>
</ports>
</tcp>
<time>120000</time>
</wait>
<ports>
<port>18080:18080</port>
<port>18090:18090</port>
</ports>
<dependsOn>
<container>service-center</container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ private void setInstances(List<MicroserviceInstance> pulledInstances, String rev
// clear cache
versions.forEach((key, value) -> value.setInstances(new ArrayList<>()));
for (Entry<String, List<MicroserviceInstance>> entry : mergedInstances.microserviceIdMap.entrySet()) {
// ensure microserviceVersion exists
versions.computeIfAbsent(entry.getKey(),
microserviceId -> createMicroserviceVersion(microserviceId, entry.getValue()))
.setInstances(entry.getValue());
// always update microservice versions, because we allow microservice info override, like schema info
MicroserviceVersion newVersion = createMicroserviceVersion(entry.getKey(), entry.getValue());
newVersion.setInstances(entry.getValue());
versions.put(entry.getKey(), newVersion);
}

for (MicroserviceVersionRule microserviceVersionRule : versionRules.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ public int getResendHeartBeatTimes() {
return times < 0 ? ServiceRegistryConfig.DEFAULT_CHECK_TIMES : times;
}

// 配置项供开发测试使用,减少接口频繁变更情况下,需要修改版本号的工作量。
// 生产环境不能打开这个配置项,否则会导致网关、consumer等在provider之前启动的场景下,访问不到新增、更新的接口。
// Setting override schema to true, must also set OperationInstancesDiscoveryFilter false.
// Or when new version add some services, the gateway will not update its route and can not
// route to the target service.
public boolean isAlwaysOverrideSchema() {
DynamicBooleanProperty property =
DynamicPropertyFactory.getInstance()
.getBooleanProperty("servicecomb.service.registry.instance.alwaysOverrideSchema",
false);
true);
return property.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

import mockit.Expectations;
import mockit.Mocked;
import org.junit.jupiter.api.Assertions;

public class TestMicroserviceRegisterTask {
private EventBus eventBus;
Expand Down Expand Up @@ -225,7 +225,8 @@ public void testAlreadyRegisteredSchemaIdSetMatch(@Mocked ServiceRegistryClient
}

@Test(expected = IllegalStateException.class)
public void testAlreadyRegisteredSchemaIdSetNotMatch(@Mocked ServiceRegistryClient srClient) {
public void testAlreadyRegisteredSchemaIdSetNotMatch(@Mocked ServiceRegistryClient srClient,
@Mocked ServiceRegistryConfig config) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
Expand All @@ -240,6 +241,8 @@ public void testAlreadyRegisteredSchemaIdSetNotMatch(@Mocked ServiceRegistryClie
schemaResponse.setSchemaId("s1");
new Expectations() {
{
config.isAlwaysOverrideSchema();
result = false;
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
Expand Down Expand Up @@ -366,7 +369,7 @@ public void testFirstRegisterForProd(@Mocked ServiceRegistryClient srClient) {
* There is schema in service center which is different from local schema.
*/
@Test(expected = IllegalStateException.class)
public void testReRegisteredSetForProd(@Mocked ServiceRegistryClient srClient) {
public void testReRegisteredSetForProd(@Mocked ServiceRegistryClient srClient, @Mocked ServiceRegistryConfig config) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
Expand All @@ -382,6 +385,8 @@ public void testReRegisteredSetForProd(@Mocked ServiceRegistryClient srClient) {

new Expectations() {
{
config.isAlwaysOverrideSchema();
result = false;
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
Expand All @@ -401,7 +406,8 @@ public void testReRegisteredSetForProd(@Mocked ServiceRegistryClient srClient) {
* env = production and there are schemas only existing in service center
*/
@Test(expected = IllegalStateException.class)
public void testReRegisterForProductAndLocalSchemasAreLess(@Mocked ServiceRegistryClient srClient) {
public void testReRegisterForProductAndLocalSchemasAreLess(@Mocked ServiceRegistryClient srClient,
@Mocked ServiceRegistryConfig config) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
Expand All @@ -420,6 +426,8 @@ public void testReRegisterForProductAndLocalSchemasAreLess(@Mocked ServiceRegist

new Expectations() {
{
config.isAlwaysOverrideSchema();
result = false;
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
Expand Down Expand Up @@ -489,8 +497,8 @@ public void testReRegisterForDevAndLocalSchemasAreLess(@Mocked ServiceRegistryCl
* There is schema in service center which is different from local schema.
*/
@Test
public void testLocalSchemaAndServiceCenterSchemaDiff(@Mocked ServiceRegistryClient srClient) {

public void testLocalSchemaAndServiceCenterSchemaDiff(@Mocked ServiceRegistryClient srClient,
@Mocked ServiceRegistryConfig config) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
Expand All @@ -506,6 +514,8 @@ public void testLocalSchemaAndServiceCenterSchemaDiff(@Mocked ServiceRegistryCli

new Expectations() {
{
config.isAlwaysOverrideSchema();
result = false;
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
Expand Down Expand Up @@ -602,7 +612,8 @@ public void testLocalSchemaAndServiceCenterSchemaDiff(@Mocked ServiceRegistryCli
registerTask.run();
} catch (IllegalStateException exception) {
isIllegalException = true;
List<LoggingEvent> events = collector.getEvents().stream().filter(e -> MicroserviceRegisterTask.class.getName().equals(e.getLoggerName())).collect(Collectors.toList());
List<LoggingEvent> events = collector.getEvents().stream()
.filter(e -> MicroserviceRegisterTask.class.getName().equals(e.getLoggerName())).collect(Collectors.toList());

Assertions.assertEquals("service center schema and local schema both are different:\n" +
" service center schema:\n" +
Expand Down