Skip to content
Permalink
Browse files
Add Configuration Override Support Check for 3.0 (#345)
  • Loading branch information
AlbumenJ committed Jul 16, 2021
1 parent 7d763bd commit 8193343b5f3adbcd7add36c6cd4b0f4651ea01ba
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 16 deletions.
@@ -20,5 +20,5 @@
# Supported component versions of the test case

# Spring app
dubbo.version=2.7*, 3.*
dubbo.version=3.*
spring.version=4.*, 5.*
@@ -31,7 +31,7 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<dubbo.version>2.7.7</dubbo.version>
<dubbo.version>3.0.1</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.samples.governance;

import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.rpc.model.ApplicationModel;

public class UpgradeUtil {
private static final String DUBBO_SERVICEDISCOVERY_MIGRATION = "DUBBO_SERVICEDISCOVERY_MIGRATION";

public static void writeApplicationFirstRule(int proportion) {
String content = "step: APPLICATION_FIRST\r\n" +
"proportion: " + proportion;

String RULE_KEY = ApplicationModel.getName() + ".migration";
DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
}

public static void writeForceInterfaceRule() {
String content = "step: FORCE_INTERFACE\r\n" +
"force: true";

String RULE_KEY = ApplicationModel.getName() + ".migration";
DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
}

public static void writeForceApplicationRule() {
String content = "step: FORCE_APPLICATION\r\n" +
"force: true";

String RULE_KEY = ApplicationModel.getName() + ".migration";
DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
}

}
@@ -1,2 +1,2 @@
dubbo.application.register-mode=interface
dubbo.application.service-discovery.migration=FORCE_INTERFACE
dubbo.application.register-mode=all
dubbo.application.metadata.delay=10
@@ -42,7 +42,9 @@ public static void setUp() throws Exception {
}

@Test
public void test20880() throws Exception {
public void test20880_interface() throws Exception {
UpgradeUtil.writeForceInterfaceRule();
checkIfNotified();
ZKTools.generateAppLevelOverride(100, 0);
Thread.sleep(5000);
for (int i = 0; i < 10; i++) {
@@ -53,7 +55,22 @@ public void test20880() throws Exception {
}

@Test
public void test20881() throws Exception {
public void test20880_application() throws Exception {
UpgradeUtil.writeForceApplicationRule();
checkIfNotified();
ZKTools.generateAppLevelOverride(100, 0);
Thread.sleep(5000);
for (int i = 0; i < 10; i++) {
String result = demoService.sayHello("world");
System.out.println(result);
Assert.assertTrue(result.contains("20880"));
}
}

@Test
public void test20881_interface() throws Exception {
UpgradeUtil.writeForceInterfaceRule();
checkIfNotified();
ZKTools.generateAppLevelOverride(0, 100);
Thread.sleep(5000);
for (int i = 0; i < 10; i++) {
@@ -62,4 +79,27 @@ public void test20881() throws Exception {
Assert.assertTrue(result.contains("20881"));
}
}

@Test
public void test20881_application() throws Exception {
UpgradeUtil.writeForceApplicationRule();
checkIfNotified();
ZKTools.generateAppLevelOverride(0, 100);
Thread.sleep(5000);
for (int i = 0; i < 10; i++) {
String result = demoService.sayHello("world");
System.out.println(result);
Assert.assertTrue(result.contains("20881"));
}
}

private void checkIfNotified() throws InterruptedException {
for (int i = 0; i < 50; i++) {
if (FrameworkStatusReporterImpl.getReport().size() == 1) {
FrameworkStatusReporterImpl.clearReport();
return;
}
Thread.sleep(100);
}
}
}
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.samples.governance;

import org.apache.dubbo.common.status.reporter.FrameworkStatusReporter;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

public class FrameworkStatusReporterImpl implements FrameworkStatusReporter {
private static final Map<String, String> report = new HashMap<>();

@Override
public void report(String type, Object obj) {
if (obj instanceof String) {
Object group = new Gson().fromJson((String) obj, Map.class).get("group");
report.put((String) group, (String) obj);
}
}

public static Map<String, String> getReport() {
return report;
}

public static void clearReport() {
report.clear();
}
}
@@ -0,0 +1 @@
test = org.apache.dubbo.demo.consumer.FrameworkStatusReporterImpl
@@ -20,5 +20,5 @@
# Supported component versions of the test case

# Spring app
dubbo.version=2.7*, 3.*
dubbo.version=3.*
spring.version=4.*, 5.*
@@ -31,7 +31,7 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<dubbo.version>2.7.7</dubbo.version>
<dubbo.version>3.0.1</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.samples.governance;

import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.rpc.model.ApplicationModel;

public class UpgradeUtil {
private static final String DUBBO_SERVICEDISCOVERY_MIGRATION = "DUBBO_SERVICEDISCOVERY_MIGRATION";

public static void writeApplicationFirstRule(int proportion) {
String content = "step: APPLICATION_FIRST\r\n" +
"proportion: " + proportion;

String RULE_KEY = ApplicationModel.getName() + ".migration";
DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
}

public static void writeForceInterfaceRule() {
String content = "step: FORCE_INTERFACE\r\n" +
"force: true";

String RULE_KEY = ApplicationModel.getName() + ".migration";
DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
}

public static void writeForceApplicationRule() {
String content = "step: FORCE_APPLICATION\r\n" +
"force: true";

String RULE_KEY = ApplicationModel.getName() + ".migration";
DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
}

}
@@ -1,2 +1 @@
dubbo.application.register-mode=interface
dubbo.application.service-discovery.migration=FORCE_INTERFACE
dubbo.application.register-mode=all
@@ -0,0 +1,99 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dubbo.samples.governance;

import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.samples.governance.api.DemoService;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/spring/dubbo-demo-consumer.xml"})
public class DemoServiceApplicationLevelIT {
@Autowired
private DemoService demoService;

@BeforeClass
public static void setUp() throws Exception {
ZKTools.initClient();
}

private static boolean init = false;

@Before
public void cleanAllRules() throws Exception {
if(!init) {
UpgradeUtil.writeForceApplicationRule();
checkIfNotified();
init = true;
}
ZKTools.cleanup();
}

@Test(expected = RpcException.class)
public void testWithoutRule() throws Exception {
Thread.sleep(2000);
demoService.sayHello("world", 1500);
}

@Test(expected = RpcException.class)
public void testWithServiceRuleWithInsufficientTimeout() throws Exception {
ZKTools.generateServiceLevelOverride(600);
Thread.sleep(2000);
demoService.sayHello("world", 800);
}

@Test
public void testWithServiceRuleWithSufficientTimeout() throws Exception {
ZKTools.generateServiceLevelOverride(6000);
Thread.sleep(2000);
Assert.assertTrue(demoService.sayHello("world", 1200).startsWith("Hello world"));
}

@Test(expected = RpcException.class)
public void testWithAppRuleWithInsufficientTimeout() throws Exception {
ZKTools.generateApplicationLevelOverride(600);
Thread.sleep(2000);
demoService.sayHello("world", 800);
}

@Test
public void testWithAppRuleWithSufficientTimeout() throws Exception {
ZKTools.generateApplicationLevelOverride(6000);
Thread.sleep(2000);
Assert.assertTrue(demoService.sayHello("world", 1200).startsWith("Hello world"));
}

private static void checkIfNotified() throws InterruptedException {
for (int i = 0; i < 50; i++) {
if (FrameworkStatusReporterImpl.getReport().size() == 1) {
FrameworkStatusReporterImpl.clearReport();
return;
}
Thread.sleep(100);
}
}
}

0 comments on commit 8193343

Please sign in to comment.