Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add aubbo_configcenter_apollo_removeListener_test #7893

Merged
merged 1 commit into from
May 28, 2021
Merged
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 @@ -24,7 +24,10 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;

import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -41,6 +44,7 @@
* Notice: EmbeddedApollo(apollo mock server) only support < junit5, please not upgrade the junit version in this UT,
* the junit version in this UT is junit4, and the dependency comes from apollo-mockserver.
*/
@TestMethodOrder(OrderAnnotation.class)
public class ApolloDynamicConfigurationTest {
private static final String SESSION_TIMEOUT_KEY = "session";
private static final String DEFAULT_NAMESPACE = "dubbo";
Expand Down Expand Up @@ -84,6 +88,7 @@ public void setUp() {
* Test get rule.
*/
@Test
@Order(1)
public void testGetRule() {
String mockKey = "mockKey1";
String mockValue = String.valueOf(new Random().nextInt());
Expand All @@ -101,6 +106,7 @@ public void testGetRule() {
* @throws InterruptedException the interrupted exception
*/
@Test
@Order(2)
public void testGetInternalProperty() throws InterruptedException {
String mockKey = "mockKey2";
String mockValue = String.valueOf(new Random().nextInt());
Expand All @@ -123,6 +129,7 @@ public void testGetInternalProperty() throws InterruptedException {
* @throws Exception the exception
*/
@Test
@Order(3)
public void testAddListener() throws Exception {
String mockKey = "mockKey3";
String mockValue = String.valueOf(new Random().nextInt());
Expand All @@ -145,6 +152,44 @@ public void process(org.apache.dubbo.common.config.configcenter.ConfigChangedEve
assertEquals(ConfigChangeType.MODIFIED, result.getChangeType());
}

/**
* Test remove listener.
*
* @throws Exception the exception
*/
@Test
@Order(4)
public void testRemoveListener() throws Exception {
String mockKey = "mockKey4";
String mockValue = String.valueOf(new Random().nextInt());

final SettableFuture<org.apache.dubbo.common.config.configcenter.ConfigChangedEvent> future = SettableFuture.create();

apolloDynamicConfiguration = new ApolloDynamicConfiguration(url);
apolloDynamicConfiguration.addListener(mockKey, DEFAULT_NAMESPACE, new ConfigurationListener() {
@Override
public void process(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent event) {
future.set(event);
}
});

putData(mockKey, mockValue);
future.get(3000, TimeUnit.MILLISECONDS);

apolloDynamicConfiguration.removeListener(mockKey, DEFAULT_NAMESPACE, new ConfigurationListener() {
@Override
public void process(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent event) {
future.set(event);
}
});

deleteData(mockKey);
org.apache.dubbo.common.config.configcenter.ConfigChangedEvent result = future.get(3000, TimeUnit.MILLISECONDS);
assertEquals(mockValue, result.getContent());
assertEquals(mockKey, result.getKey());
assertEquals(ConfigChangeType.MODIFIED, result.getChangeType());
}

private static void putData(String namespace, String key, String value) {
embeddedApollo.addOrModifyProperty(namespace, key, value);
}
Expand All @@ -153,6 +198,9 @@ private static void putData(String key, String value) {
embeddedApollo.addOrModifyProperty(DEFAULT_NAMESPACE, key, value);
}

private static void deleteData(String key) {
embeddedApollo.deleteProperty(DEFAULT_NAMESPACE, key);
}
private static void putMockRuleData(String key, String value, String group) {
String fileName = ApolloDynamicConfigurationTest.class.getResource("/").getPath() + "mockdata-" + group + ".properties";
putMockData(key, value, fileName);
Expand Down