Skip to content

Commit

Permalink
Add test cases to the Configurator after version 2.7 (#8560)
Browse files Browse the repository at this point in the history
  • Loading branch information
BurningCN authored Aug 23, 2021
1 parent 72e1f6e commit 0382a6b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

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

/**
* OverrideConfiguratorTest
*/
Expand Down Expand Up @@ -65,4 +68,53 @@ public void testOverrideHost() {
Assertions.assertEquals("1000", url.getParameter("timeout"));
}

// Test the version after 2.7
@Test
public void testAbsentForVersion27() {
{
String consumerUrlV27 = "dubbo://172.24.160.179/com.foo.BarService?application=foo&side=consumer&timeout=100";

URL consumerConfiguratorUrl = URL.valueOf("absent://0.0.0.0/com.foo.BarService");
Map<String, String> params = new HashMap<>();
params.put("side", "consumer");
params.put("configVersion", "2.7");
params.put("application", "foo");
params.put("timeout", "10000");
params.put("weight", "200");
consumerConfiguratorUrl = consumerConfiguratorUrl.addParameters(params);

AbsentConfigurator configurator = new AbsentConfigurator(consumerConfiguratorUrl);
// Meet the configured conditions:
// same side
// The port of configuratorUrl is 0
// The host of configuratorUrl is 0.0.0.0 or the local address is the same as consumerUrlV27
// same appName
URL url = configurator.configure(URL.valueOf(consumerUrlV27));
Assertions.assertEquals(url.getParameter("timeout"), "100");
Assertions.assertEquals(url.getParameter("weight"), "200");
}

{
String providerUrlV27 = "dubbo://172.24.160.179:21880/com.foo.BarService?application=foo&side=provider&weight=100";

URL providerConfiguratorUrl = URL.valueOf("absent://172.24.160.179:21880/com.foo.BarService");
Map<String, String> params = new HashMap<>();
params.put("side", "provider");
params.put("configVersion", "2.7");
params.put("application", "foo");
params.put("timeout", "20000");
params.put("weight", "200");
providerConfiguratorUrl = providerConfiguratorUrl.addParameters(params);
// Meet the configured conditions:
// same side
// same port
// The host of configuratorUrl is 0.0.0.0 or the host of providerConfiguratorUrl is the same as consumerUrlV27
// same appName
AbsentConfigurator configurator = new AbsentConfigurator(providerConfiguratorUrl);
URL url = configurator.configure(URL.valueOf(providerUrlV27));
Assertions.assertEquals(url.getParameter("timeout"), "20000");
Assertions.assertEquals(url.getParameter("weight"), "100");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

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

/**
* OverrideConfiguratorTest
*/
Expand Down Expand Up @@ -65,4 +68,50 @@ public void testOverride_Host() {
Assertions.assertEquals("1000", url.getParameter("timeout"));
}

// Test the version after 2.7
@Test
public void testOverrideForVersion27() {
{
String consumerUrlV27 = "dubbo://172.24.160.179/com.foo.BarService?application=foo&side=consumer&timeout=100";

URL consumerConfiguratorUrl = URL.valueOf("override://0.0.0.0/com.foo.BarService");
Map<String, String> params = new HashMap<>();
params.put("side", "consumer");
params.put("configVersion", "2.7");
params.put("application", "foo");
params.put("timeout", "10000");
consumerConfiguratorUrl = consumerConfiguratorUrl.addParameters(params);

OverrideConfigurator configurator = new OverrideConfigurator(consumerConfiguratorUrl);
// Meet the configured conditions:
// same side
// The port of configuratorUrl is 0
// The host of configuratorUrl is 0.0.0.0 or the local address is the same as consumerUrlV27
// same appName
URL url = configurator.configure(URL.valueOf(consumerUrlV27));
Assertions.assertEquals(url.getParameter("timeout"), "10000");
}

{
String providerUrlV27 = "dubbo://172.24.160.179:21880/com.foo.BarService?application=foo&side=provider&weight=100";

URL providerConfiguratorUrl = URL.valueOf("override://172.24.160.179:21880/com.foo.BarService");
Map<String, String> params = new HashMap<>();
params.put("side", "provider");
params.put("configVersion", "2.7");
params.put("application", "foo");
params.put("weight", "200");
providerConfiguratorUrl = providerConfiguratorUrl.addParameters(params);
// Meet the configured conditions:
// same side
// same port
// The host of configuratorUrl is 0.0.0.0 or the host of providerConfiguratorUrl is the same as consumerUrlV27
// same appName
OverrideConfigurator configurator = new OverrideConfigurator(providerConfiguratorUrl);
URL url = configurator.configure(URL.valueOf(providerUrlV27));
Assertions.assertEquals(url.getParameter("weight"), "200");
}

}

}

0 comments on commit 0382a6b

Please sign in to comment.