Skip to content

Commit

Permalink
test(apollo-admin): Optimize the test case
Browse files Browse the repository at this point in the history
  • Loading branch information
klboke committed Mar 31, 2023
1 parent 616f67e commit 1c47cd6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static com.ctrip.framework.apollo.biz.utils.ReleaseMessageKeyGenerator.generate;
import static org.junit.Assert.assertEquals;

/**
Expand Down Expand Up @@ -105,7 +104,7 @@ public void testQueryConfigWithDefaultClusterAndDefaultNamespaceAndIncorrectCase
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryGrayConfigWithDefaultClusterAndDefaultNamespaceOK() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION),
periodicSendMessage(executorService, assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION),
stop);

TimeUnit.MILLISECONDS.sleep(500);
Expand All @@ -128,7 +127,7 @@ public void testQueryGrayConfigWithDefaultClusterAndDefaultNamespaceOK() throws
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryGrayConfigWithDefaultClusterAndDefaultNamespaceAndIncorrectCase() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION),
periodicSendMessage(executorService, assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION),
stop);

TimeUnit.MILLISECONDS.sleep(500);
Expand Down Expand Up @@ -224,7 +223,7 @@ public void testQueryConfigNotModified() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicGrayConfigWithNoOverride() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
periodicSendMessage(executorService, assembleKey(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
stop);

TimeUnit.MILLISECONDS.sleep(500);
Expand Down Expand Up @@ -347,7 +346,7 @@ public void testQueryPublicConfigWithDataCenterNotFoundAndOverride() throws Exce
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicGrayConfigWithOverride() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
periodicSendMessage(executorService, assembleKey(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
stop);

TimeUnit.MILLISECONDS.sleep(500);
Expand All @@ -374,7 +373,7 @@ public void testQueryPublicGrayConfigWithOverride() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicGrayConfigWithIncorrectCaseAndOverride() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
periodicSendMessage(executorService, assembleKey(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
stop);

TimeUnit.MILLISECONDS.sleep(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.concurrent.atomic.AtomicBoolean;
import org.springframework.test.util.ReflectionTestUtils;

import static com.ctrip.framework.apollo.biz.utils.ReleaseMessageKeyGenerator.generate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -107,7 +106,7 @@ public void testQueryConfigAsProperties() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryConfigAsPropertiesWithGrayRelease() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION),
periodicSendMessage(executorService, assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION),
stop);

TimeUnit.MILLISECONDS.sleep(500);
Expand Down Expand Up @@ -229,7 +228,7 @@ public void testQueryPublicConfigAsJsonWithIncorrectCase() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigAsJsonWithGrayRelease() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
periodicSendMessage(executorService, assembleKey(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
stop);

TimeUnit.MILLISECONDS.sleep(500);
Expand Down Expand Up @@ -270,7 +269,7 @@ public void testQueryPublicConfigAsJsonWithGrayRelease() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigAsJsonWithGrayReleaseAndIncorrectCase() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
periodicSendMessage(executorService, assembleKey(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace),
stop);

TimeUnit.MILLISECONDS.sleep(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;

import static com.ctrip.framework.apollo.biz.utils.ReleaseMessageKeyGenerator.generate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

Expand Down Expand Up @@ -68,7 +67,7 @@ public void setUp() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespace() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(someAppId, someCluster, defaultNamespace), stop);
periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop);

ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
Expand All @@ -87,7 +86,7 @@ public void testPollNotificationWithDefaultNamespace() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespaceAsFile() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(someAppId, someCluster, defaultNamespace), stop);
periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop);

ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
Expand All @@ -108,7 +107,7 @@ public void testPollNotificationWithDefaultNamespaceAsFile() throws Exception {
public void testPollNotificationWithPrivateNamespaceAsFile() throws Exception {
String namespace = "someNamespace.xml";
AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace), stop);
periodicSendMessage(executorService, assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace), stop);

ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity(
Expand Down Expand Up @@ -163,7 +162,7 @@ public void testPollNotificationWthPublicNamespaceAndNoDataCenter() throws Excep
String publicAppId = "somePublicAppId";

AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace), stop);
periodicSendMessage(executorService, assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace), stop);

ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity(
Expand All @@ -187,7 +186,7 @@ public void testPollNotificationWthPublicNamespaceAndDataCenter() throws Excepti
String someDC = "someDC";

AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(publicAppId, someDC, somePublicNamespace), stop);
periodicSendMessage(executorService, assembleKey(publicAppId, someDC, somePublicNamespace), stop);

ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity(
Expand All @@ -211,7 +210,7 @@ public void testPollNotificationWthPublicNamespaceAsFile() throws Exception {
String someDC = "someDC";

AtomicBoolean stop = new AtomicBoolean();
periodicSendMessage(executorService, generate(publicAppId, someDC, somePublicNamespace), stop);
periodicSendMessage(executorService, assembleKey(publicAppId, someDC, somePublicNamespace), stop);

ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;

import static com.ctrip.framework.apollo.biz.utils.ReleaseMessageKeyGenerator.generate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -79,7 +78,7 @@ public void setUp() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespace() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
String key = generate(someAppId, someCluster, defaultNamespace);
String key = assembleKey(someAppId, someCluster, defaultNamespace);
periodicSendMessage(executorService, key, stop);

ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange(
Expand All @@ -106,7 +105,7 @@ public void testPollNotificationWithDefaultNamespace() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespaceAsFile() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
String key = generate(someAppId, someCluster, defaultNamespace);
String key = assembleKey(someAppId, someCluster, defaultNamespace);
periodicSendMessage(executorService, key,
stop);

Expand Down Expand Up @@ -135,7 +134,7 @@ public void testPollNotificationWithDefaultNamespaceAsFile() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithMultipleNamespaces() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
String key = generate(someAppId, someCluster, somePublicNamespace);
String key = assembleKey(someAppId, someCluster, somePublicNamespace);
periodicSendMessage(executorService, key, stop);

ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange(
Expand Down Expand Up @@ -164,7 +163,7 @@ public void testPollNotificationWithMultipleNamespaces() throws Exception {
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithMultipleNamespacesAndIncorrectCase() throws Exception {
AtomicBoolean stop = new AtomicBoolean();
String key = generate(someAppId, someCluster, somePublicNamespace);
String key = assembleKey(someAppId, someCluster, somePublicNamespace);
periodicSendMessage(executorService, key, stop);

String someDefaultNamespaceWithIncorrectCase = defaultNamespace.toUpperCase();
Expand Down Expand Up @@ -200,7 +199,7 @@ public void testPollNotificationWithPrivateNamespaceAsFile() throws Exception {
String namespace = "someNamespace.xml";
AtomicBoolean stop = new AtomicBoolean();

String key = generate(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace);
String key = assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace);
periodicSendMessage(executorService, key, stop);

ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange(
Expand Down Expand Up @@ -244,7 +243,7 @@ public void testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated()
assertEquals(defaultNamespace, notifications.get(0).getNamespaceName());
assertEquals(newNotificationId, notifications.get(0).getNotificationId());

String key = generate(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION);
String key = assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION);
ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
assertEquals(1, messages.getDetails().size());
assertTrue(messages.has(key));
Expand All @@ -258,7 +257,7 @@ public void testPollNotificationWthPublicNamespaceAndNoDataCenter() throws Excep
String publicAppId = "somePublicAppId";

AtomicBoolean stop = new AtomicBoolean();
String key = generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
periodicSendMessage(executorService, key, stop);

ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange(
Expand Down Expand Up @@ -289,7 +288,7 @@ public void testPollNotificationWthPublicNamespaceAndDataCenter() throws Excepti
String someDC = "someDC";

AtomicBoolean stop = new AtomicBoolean();
String key = generate(publicAppId, someDC, somePublicNamespace);
String key = assembleKey(publicAppId, someDC, somePublicNamespace);
periodicSendMessage(executorService, key, stop);

ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange(
Expand Down Expand Up @@ -322,7 +321,7 @@ public void testPollNotificationWthMultipleNamespacesAndMultipleNamespacesChange
String someDC = "someDC";

AtomicBoolean stop = new AtomicBoolean();
String key = generate(publicAppId, someDC, somePublicNamespace);
String key = assembleKey(publicAppId, someDC, somePublicNamespace);
periodicSendMessage(executorService, key, stop);

ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange(
Expand Down Expand Up @@ -355,7 +354,7 @@ public void testPollNotificationWthPublicNamespaceAsFile() throws Exception {
String someDC = "someDC";

AtomicBoolean stop = new AtomicBoolean();
String key = generate(publicAppId, someDC, somePublicNamespace);
String key = assembleKey(publicAppId, someDC, somePublicNamespace);
periodicSendMessage(executorService, key, stop);

ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange(
Expand Down Expand Up @@ -402,7 +401,7 @@ public void testPollNotificationWithPublicNamespaceWithNotificationIdOutDated()
assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
assertEquals(newNotificationId, notifications.get(0).getNotificationId());

String key = generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
assertEquals(1, messages.getDetails().size());
assertTrue(messages.has(key));
Expand Down Expand Up @@ -435,7 +434,7 @@ public void testPollNotificationWithMultiplePublicNamespaceWithIncorrectCaseWith
assertEquals(somePublicNameWithIncorrectCase, notifications.get(0).getNamespaceName());
assertEquals(newNotificationId, notifications.get(0).getNotificationId());

String key = generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
assertEquals(1, messages.getDetails().size());
assertTrue(messages.has(key));
Expand Down Expand Up @@ -468,7 +467,7 @@ public void testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase2Wit
assertEquals(somePublicNameWithIncorrectCase, notifications.get(0).getNamespaceName());
assertEquals(newNotificationId, notifications.get(0).getNotificationId());

String key = generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
assertEquals(1, messages.getDetails().size());
assertTrue(messages.has(key));
Expand Down Expand Up @@ -501,7 +500,7 @@ public void testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase3Wit
assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
assertEquals(newNotificationId, notifications.get(0).getNotificationId());

String key = generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
assertEquals(1, messages.getDetails().size());
assertTrue(messages.has(key));
Expand Down Expand Up @@ -534,7 +533,7 @@ public void testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase4Wit
assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
assertEquals(newNotificationId, notifications.get(0).getNotificationId());

String key = generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
assertEquals(1, messages.getDetails().size());
assertTrue(messages.has(key));
Expand Down Expand Up @@ -572,9 +571,9 @@ public void testPollNotificationWithMultipleNamespacesAndNotificationIdsOutDated
assertEquals(Sets.newHashSet(newDefaultNamespaceNotificationId, newPublicNamespaceNotification),
newNotificationIds);

String defaultNamespaceKey = generate(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT,
String defaultNamespaceKey = assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT,
ConfigConsts.NAMESPACE_APPLICATION);
String publicNamespaceKey = generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
String publicNamespaceKey = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);

ApolloNotificationMessages firstMessages = notifications.get(0).getMessages();
ApolloNotificationMessages secondMessages = notifications.get(1).getMessages();
Expand Down Expand Up @@ -627,9 +626,9 @@ public void testPollNotificationWithMultipleNamespacesAndNotificationIdsOutDated
assertEquals(Sets.newHashSet(newDefaultNamespaceNotificationId, newPublicNamespaceNotification),
newNotificationIds);

String defaultNamespaceKey = generate(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT,
String defaultNamespaceKey = assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT,
ConfigConsts.NAMESPACE_APPLICATION);
String publicNamespaceKey = generate(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
String publicNamespaceKey = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);

ApolloNotificationMessages firstMessages = notifications.get(0).getMessages();
ApolloNotificationMessages secondMessages = notifications.get(1).getMessages();
Expand Down

0 comments on commit 1c47cd6

Please sign in to comment.