Commit b04949c3 by Jason Song

Use new strategy to load config.

1. specified cluster 2. data center as cluster 3. default cluster
parent 4ef524e0
...@@ -178,9 +178,13 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -178,9 +178,13 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
logger.debug("Config server responds with 304 HTTP status code."); logger.debug("Config server responds with 304 HTTP status code.");
return m_configCache.get(); return m_configCache.get();
} }
logger.debug("Loaded config: {}", response.getBody());
return response.getBody(); ApolloConfig result = response.getBody();
Cat.logEvent("Apollo.Client.ConfigLoaded." + result.getNamespaceName(), result.getReleaseKey());
logger.debug("Loaded config for {}: {}", m_namespace, result);
return result;
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Cat.logError(ex);
transaction.setStatus(ex); transaction.setStatus(ex);
......
...@@ -25,6 +25,7 @@ public class ConfigUtil { ...@@ -25,6 +25,7 @@ public class ConfigUtil {
/** /**
* Get the app id for the current application. * Get the app id for the current application.
*
* @return the app id * @return the app id
* @throws IllegalStateException if app id is not set * @throws IllegalStateException if app id is not set
*/ */
...@@ -36,18 +37,30 @@ public class ConfigUtil { ...@@ -36,18 +37,30 @@ public class ConfigUtil {
/** /**
* Get the data center info for the current application. * Get the data center info for the current application.
*
* @return the current data center, null if there is no such info. * @return the current data center, null if there is no such info.
*/ */
public String getDataCenter() { public String getDataCenter() {
return Foundation.server().getDataCenter(); String dataCenter = Foundation.server().getDataCenter();
//TODO use sub env from framework foundation if data center is null
return dataCenter;
} }
/** /**
* Get the cluster name for the current application. * Get the cluster name for the current application.
*
* @return the cluster name, or "default" if not specified * @return the cluster name, or "default" if not specified
*/ */
public String getCluster() { public String getCluster() {
//Load data center from system property
String cluster = System.getProperty("apollo.cluster"); String cluster = System.getProperty("apollo.cluster");
//Use data center as cluster
if (cluster == null) {
cluster = getDataCenter();
}
//Use default cluster
if (cluster == null) { if (cluster == null) {
cluster = ConfigConsts.CLUSTER_NAME_DEFAULT; cluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
} }
...@@ -56,6 +69,7 @@ public class ConfigUtil { ...@@ -56,6 +69,7 @@ public class ConfigUtil {
/** /**
* Get the current environment. * Get the current environment.
*
* @return the env * @return the env
* @throws IllegalStateException if env is set * @throws IllegalStateException if env is set
*/ */
......
...@@ -65,15 +65,18 @@ public class ConfigController { ...@@ -65,15 +65,18 @@ public class ConfigController {
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
List<Release> releases = Lists.newLinkedList(); List<Release> releases = Lists.newLinkedList();
Release currentAppRelease = configService.findRelease(appId, clusterName, namespace); Release currentAppRelease = loadConfig(appId, clusterName, namespace, dataCenter);
String appClusterNameLoaded = clusterName;
if (currentAppRelease != null) { if (currentAppRelease != null) {
releases.add(currentAppRelease); releases.add(currentAppRelease);
//we have cluster search process, so the cluster name might be overridden
appClusterNameLoaded = currentAppRelease.getClusterName();
} }
//if namespace is not 'application', should check if it's a public configuration //if namespace is not 'application', should check if it's a public configuration
if (!Objects.equals(ConfigConsts.NAMESPACE_DEFAULT, namespace)) { if (!Objects.equals(ConfigConsts.NAMESPACE_DEFAULT, namespace)) {
Release publicRelease = this.findPublicConfig(appId, namespace, dataCenter); Release publicRelease = this.findPublicConfig(appId, clusterName, namespace, dataCenter);
if (!Objects.isNull(publicRelease)) { if (!Objects.isNull(publicRelease)) {
releases.add(publicRelease); releases.add(publicRelease);
} }
...@@ -96,14 +99,14 @@ public class ConfigController { ...@@ -96,14 +99,14 @@ public class ConfigController {
// Client side configuration is the same with server side, return 304 // Client side configuration is the same with server side, return 304
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
Cat.logEvent("Apollo.Config.NotModified", Cat.logEvent("Apollo.Config.NotModified",
assembleKey(appId, clusterName, namespace, dataCenter)); assembleKey(appId, appClusterNameLoaded, namespace, dataCenter));
return null; return null;
} }
ApolloConfig apolloConfig = new ApolloConfig(appId, clusterName, namespace, mergedReleaseKey); ApolloConfig apolloConfig = new ApolloConfig(appId, appClusterNameLoaded, namespace, mergedReleaseKey);
apolloConfig.setConfigurations(mergeReleaseConfigurations(releases)); apolloConfig.setConfigurations(mergeReleaseConfigurations(releases));
Cat.logEvent("Apollo.Config.Found", assembleKey(appId, clusterName, namespace, dataCenter)); Cat.logEvent("Apollo.Config.Found", assembleKey(appId, appClusterNameLoaded, namespace, dataCenter));
return apolloConfig; return apolloConfig;
} }
...@@ -112,7 +115,7 @@ public class ConfigController { ...@@ -112,7 +115,7 @@ public class ConfigController {
* @param namespace the namespace * @param namespace the namespace
* @param dataCenter the datacenter * @param dataCenter the datacenter
*/ */
private Release findPublicConfig(String applicationId, String namespace, String dataCenter) { private Release findPublicConfig(String applicationId, String clusterName, String namespace, String dataCenter) {
AppNamespace appNamespace = appNamespaceService.findByNamespaceName(namespace); AppNamespace appNamespace = appNamespaceService.findByNamespaceName(namespace);
//check whether the namespace's appId equals to current one //check whether the namespace's appId equals to current one
...@@ -122,10 +125,24 @@ public class ConfigController { ...@@ -122,10 +125,24 @@ public class ConfigController {
String publicConfigAppId = appNamespace.getAppId(); String publicConfigAppId = appNamespace.getAppId();
return loadConfig(publicConfigAppId, clusterName, namespace, dataCenter);
}
private Release loadConfig(String appId, String clusterName, String namespace, String dataCenter) {
//load from specified cluster fist
if (!Objects.equals(ConfigConsts.CLUSTER_NAME_DEFAULT, clusterName)) {
Release clusterRelease =
configService.findRelease(appId, clusterName, namespace);
if (!Objects.isNull(clusterRelease)) {
return clusterRelease;
}
}
//try to load via data center //try to load via data center
if (!Objects.isNull(dataCenter)) { if (!Objects.isNull(dataCenter) && !Objects.equals(dataCenter, clusterName)) {
Release dataCenterRelease = Release dataCenterRelease =
configService.findRelease(publicConfigAppId, dataCenter, namespace); configService.findRelease(appId, dataCenter, namespace);
if (!Objects.isNull(dataCenterRelease)) { if (!Objects.isNull(dataCenterRelease)) {
return dataCenterRelease; return dataCenterRelease;
} }
...@@ -133,7 +150,7 @@ public class ConfigController { ...@@ -133,7 +150,7 @@ public class ConfigController {
//fallback to default release //fallback to default release
return configService return configService
.findRelease(publicConfigAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace); .findRelease(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace);
} }
/** /**
......
...@@ -7,6 +7,7 @@ import com.google.common.collect.HashMultimap; ...@@ -7,6 +7,7 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import com.ctrip.framework.apollo.biz.entity.AppNamespace; import com.ctrip.framework.apollo.biz.entity.AppNamespace;
import com.ctrip.framework.apollo.biz.message.MessageListener; import com.ctrip.framework.apollo.biz.message.MessageListener;
...@@ -30,6 +31,7 @@ import org.springframework.web.context.request.async.DeferredResult; ...@@ -30,6 +31,7 @@ import org.springframework.web.context.request.async.DeferredResult;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -59,11 +61,11 @@ public class NotificationController implements MessageListener { ...@@ -59,11 +61,11 @@ public class NotificationController implements MessageListener {
@RequestParam(value = "cluster") String cluster, @RequestParam(value = "cluster") String cluster,
@RequestParam(value = "namespace", defaultValue = ConfigConsts.NAMESPACE_DEFAULT) String namespace, @RequestParam(value = "namespace", defaultValue = ConfigConsts.NAMESPACE_DEFAULT) String namespace,
@RequestParam(value = "dataCenter", required = false) String dataCenter) { @RequestParam(value = "dataCenter", required = false) String dataCenter) {
List<String> watchedKeys = Lists.newArrayList(assembleKey(appId, cluster, namespace)); Set<String> watchedKeys = assembleWatchKeys(appId, cluster, namespace, dataCenter);
//Listen on more namespaces, since it's not the default namespace //Listen on more namespaces, since it's not the default namespace
if (!Objects.equals(ConfigConsts.NAMESPACE_DEFAULT, namespace)) { if (!Objects.equals(ConfigConsts.NAMESPACE_DEFAULT, namespace)) {
watchedKeys.addAll(this.findPublicConfigWatchKey(appId, namespace, dataCenter)); watchedKeys.addAll(this.findPublicConfigWatchKey(appId, cluster, namespace, dataCenter));
} }
DeferredResult<ResponseEntity<ApolloConfigNotification>> deferredResult = DeferredResult<ResponseEntity<ApolloConfigNotification>> deferredResult =
...@@ -94,9 +96,9 @@ public class NotificationController implements MessageListener { ...@@ -94,9 +96,9 @@ public class NotificationController implements MessageListener {
return STRING_JOINER.join(appId, cluster, namespace); return STRING_JOINER.join(appId, cluster, namespace);
} }
private List<String> findPublicConfigWatchKey(String applicationId, String namespace, private Set<String> findPublicConfigWatchKey(String applicationId, String clusterName,
String dataCenter) { String namespace,
List<String> publicWatchedKeys = Lists.newArrayList(); String dataCenter) {
AppNamespace appNamespace = appNamespaceService.findByNamespaceName(namespace); AppNamespace appNamespace = appNamespaceService.findByNamespaceName(namespace);
/** /**
* Manually close the entity manager. * Manually close the entity manager.
...@@ -108,21 +110,32 @@ public class NotificationController implements MessageListener { ...@@ -108,21 +110,32 @@ public class NotificationController implements MessageListener {
//check whether the namespace's appId equals to current one //check whether the namespace's appId equals to current one
if (Objects.isNull(appNamespace) || Objects.equals(applicationId, appNamespace.getAppId())) { if (Objects.isNull(appNamespace) || Objects.equals(applicationId, appNamespace.getAppId())) {
return publicWatchedKeys; return Sets.newHashSet();
} }
String publicConfigAppId = appNamespace.getAppId(); String publicConfigAppId = appNamespace.getAppId();
return assembleWatchKeys(publicConfigAppId, clusterName, namespace, dataCenter);
}
private Set<String> assembleWatchKeys(String appId, String clusterName, String namespace,
String dataCenter) {
Set<String> watchedKeys = Sets.newHashSet();
//watch specified cluster config change
if (!Objects.equals(ConfigConsts.CLUSTER_NAME_DEFAULT, clusterName)) {
watchedKeys.add(assembleKey(appId, clusterName, namespace));
}
//watch data center config change //watch data center config change
if (!Objects.isNull(dataCenter)) { if (!Objects.isNull(dataCenter) && !Objects.equals(dataCenter, clusterName)) {
publicWatchedKeys.add(assembleKey(publicConfigAppId, dataCenter, namespace)); watchedKeys.add(assembleKey(appId, dataCenter, namespace));
} }
//watch default cluster config change //watch default cluster config change
publicWatchedKeys watchedKeys.add(assembleKey(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace));
.add(assembleKey(publicConfigAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespace));
return publicWatchedKeys; return watchedKeys;
} }
@Override @Override
...@@ -154,7 +167,7 @@ public class NotificationController implements MessageListener { ...@@ -154,7 +167,7 @@ public class NotificationController implements MessageListener {
logger.info("Notification completed"); logger.info("Notification completed");
} }
private void logWatchedKeysToCat(List<String> watchedKeys, String eventName) { private void logWatchedKeysToCat(Set<String> watchedKeys, String eventName) {
for (String watchedKey : watchedKeys) { for (String watchedKey : watchedKeys) {
Cat.logEvent(eventName, watchedKey); Cat.logEvent(eventName, watchedKey);
} }
......
...@@ -45,6 +45,7 @@ public class ConfigControllerTest { ...@@ -45,6 +45,7 @@ public class ConfigControllerTest {
private AppNamespaceService appNamespaceService; private AppNamespaceService appNamespaceService;
private String someAppId; private String someAppId;
private String someClusterName; private String someClusterName;
private String defaultClusterName;
private String defaultNamespaceName; private String defaultNamespaceName;
private String somePublicNamespaceName; private String somePublicNamespaceName;
private String someDataCenter; private String someDataCenter;
...@@ -61,12 +62,14 @@ public class ConfigControllerTest { ...@@ -61,12 +62,14 @@ public class ConfigControllerTest {
someAppId = "1"; someAppId = "1";
someClusterName = "someClusterName"; someClusterName = "someClusterName";
defaultClusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
defaultNamespaceName = ConfigConsts.NAMESPACE_DEFAULT; defaultNamespaceName = ConfigConsts.NAMESPACE_DEFAULT;
somePublicNamespaceName = "somePublicNamespace"; somePublicNamespaceName = "somePublicNamespace";
someDataCenter = "someDC"; someDataCenter = "someDC";
String someValidConfiguration = "{\"apollo.bar\": \"foo\"}"; String someValidConfiguration = "{\"apollo.bar\": \"foo\"}";
String somePublicConfiguration = "{\"apollo.public.bar\": \"foo\"}"; String somePublicConfiguration = "{\"apollo.public.bar\": \"foo\"}";
when(someRelease.getClusterName()).thenReturn(someClusterName);
when(someRelease.getConfigurations()).thenReturn(someValidConfiguration); when(someRelease.getConfigurations()).thenReturn(someValidConfiguration);
when(somePublicRelease.getConfigurations()).thenReturn(somePublicConfiguration); when(somePublicRelease.getConfigurations()).thenReturn(somePublicConfiguration);
} }
...@@ -129,6 +132,55 @@ public class ConfigControllerTest { ...@@ -129,6 +132,55 @@ public class ConfigControllerTest {
} }
@Test @Test
public void testQueryConfigWithDefaultClusterWithDataCenterRelease() throws Exception {
String someClientSideReleaseKey = "1";
String someServerSideNewReleaseKey = "2";
HttpServletResponse someResponse = mock(HttpServletResponse.class);
when(configService.findRelease(someAppId, someDataCenter, defaultNamespaceName))
.thenReturn(someRelease);
when(someRelease.getReleaseKey()).thenReturn(someServerSideNewReleaseKey);
when(someRelease.getClusterName()).thenReturn(someDataCenter);
ApolloConfig result = configController.queryConfig(someAppId, defaultClusterName,
defaultNamespaceName, someDataCenter, someClientSideReleaseKey,
someResponse);
verify(configService, times(1)).findRelease(someAppId, someDataCenter, defaultNamespaceName);
assertEquals(someAppId, result.getAppId());
assertEquals(someDataCenter, result.getCluster());
assertEquals(defaultNamespaceName, result.getNamespaceName());
assertEquals(someServerSideNewReleaseKey, result.getReleaseKey());
}
@Test
public void testQueryConfigWithDefaultClusterWithNoDataCenterRelease() throws Exception {
String someClientSideReleaseKey = "1";
String someServerSideNewReleaseKey = "2";
HttpServletResponse someResponse = mock(HttpServletResponse.class);
when(configService.findRelease(someAppId, someDataCenter, defaultNamespaceName))
.thenReturn(null);
when(configService.findRelease(someAppId, defaultClusterName, defaultNamespaceName))
.thenReturn(someRelease);
when(someRelease.getReleaseKey()).thenReturn(someServerSideNewReleaseKey);
when(someRelease.getClusterName()).thenReturn(defaultClusterName);
ApolloConfig result = configController.queryConfig(someAppId, defaultClusterName,
defaultNamespaceName, someDataCenter, someClientSideReleaseKey,
someResponse);
verify(configService, times(1)).findRelease(someAppId, someDataCenter, defaultNamespaceName);
verify(configService, times(1)).findRelease(someAppId, defaultClusterName, defaultNamespaceName);
assertEquals(someAppId, result.getAppId());
assertEquals(defaultClusterName, result.getCluster());
assertEquals(defaultNamespaceName, result.getNamespaceName());
assertEquals(someServerSideNewReleaseKey, result.getReleaseKey());
}
@Test
public void testQueryConfigWithAppOwnNamespace() throws Exception { public void testQueryConfigWithAppOwnNamespace() throws Exception {
String someClientSideReleaseKey = "1"; String someClientSideReleaseKey = "1";
String someServerSideReleaseKey = "2"; String someServerSideReleaseKey = "2";
......
...@@ -35,6 +35,7 @@ public class NotificationControllerTest { ...@@ -35,6 +35,7 @@ public class NotificationControllerTest {
private NotificationController controller; private NotificationController controller;
private String someAppId; private String someAppId;
private String someCluster; private String someCluster;
private String defaultCluster;
private String defaultNamespace; private String defaultNamespace;
private String somePublicNamespace; private String somePublicNamespace;
private String someDataCenter; private String someDataCenter;
...@@ -53,6 +54,7 @@ public class NotificationControllerTest { ...@@ -53,6 +54,7 @@ public class NotificationControllerTest {
someAppId = "someAppId"; someAppId = "someAppId";
someCluster = "someCluster"; someCluster = "someCluster";
defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
defaultNamespace = ConfigConsts.NAMESPACE_DEFAULT; defaultNamespace = ConfigConsts.NAMESPACE_DEFAULT;
somePublicNamespace = "somePublicNamespace"; somePublicNamespace = "somePublicNamespace";
someDataCenter = "someDC"; someDataCenter = "someDC";
...@@ -68,11 +70,58 @@ public class NotificationControllerTest { ...@@ -68,11 +70,58 @@ public class NotificationControllerTest {
deferredResult = controller deferredResult = controller
.pollNotification(someAppId, someCluster, defaultNamespace, someDataCenter); .pollNotification(someAppId, someCluster, defaultNamespace, someDataCenter);
String key = List<String> clusters =
Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR) Lists.newArrayList(someCluster, someDataCenter, ConfigConsts.CLUSTER_NAME_DEFAULT);
.join(someAppId, someCluster, defaultNamespace);
assertEquals(1, deferredResults.size()); assertEquals(clusters.size(), deferredResults.size());
assertTrue(deferredResults.get(key).contains(deferredResult));
for (String cluster : clusters) {
String key =
Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, cluster, defaultNamespace);
assertTrue(deferredResults.get(key).contains(deferredResult));
}
}
@Test
public void testPollNotificationWithDefaultNamespaceWithDefaultClusterWithDataCenter()
throws Exception {
DeferredResult<ResponseEntity<ApolloConfigNotification>>
deferredResult = controller
.pollNotification(someAppId, defaultCluster, defaultNamespace, someDataCenter);
List<String> clusters =
Lists.newArrayList(someDataCenter, defaultCluster);
assertEquals(clusters.size(), deferredResults.size());
for (String cluster : clusters) {
String key =
Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, cluster, defaultNamespace);
assertTrue(deferredResults.get(key).contains(deferredResult));
}
}
@Test
public void testPollNotificationWithDefaultNamespaceWithDefaultClusterWithNoDataCenter()
throws Exception {
DeferredResult<ResponseEntity<ApolloConfigNotification>>
deferredResult = controller
.pollNotification(someAppId, defaultCluster, defaultNamespace, null);
List<String> clusters =
Lists.newArrayList(defaultCluster);
assertEquals(clusters.size(), deferredResults.size());
for (String cluster : clusters) {
String key =
Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, cluster, defaultNamespace);
assertTrue(deferredResults.get(key).contains(deferredResult));
}
} }
@Test @Test
...@@ -88,16 +137,19 @@ public class NotificationControllerTest { ...@@ -88,16 +137,19 @@ public class NotificationControllerTest {
deferredResult = controller deferredResult = controller
.pollNotification(someAppId, someCluster, somePublicNamespace, someDataCenter); .pollNotification(someAppId, someCluster, somePublicNamespace, someDataCenter);
List<String> publicClusters = List<String> clusters =
Lists.newArrayList(someDataCenter, ConfigConsts.CLUSTER_NAME_DEFAULT); Lists.newArrayList(someCluster, someDataCenter, ConfigConsts.CLUSTER_NAME_DEFAULT);
assertEquals(3, deferredResults.size()); assertEquals(clusters.size() * 2, deferredResults.size());
String key =
Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR) for (String cluster : clusters) {
.join(someAppId, someCluster, somePublicNamespace); String publicKey =
assertTrue(deferredResults.get(key).contains(deferredResult)); Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, cluster, somePublicNamespace);
assertTrue(deferredResults.get(publicKey).contains(deferredResult));
}
for (String cluster : publicClusters) { for (String cluster : clusters) {
String publicKey = String publicKey =
Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR) Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(somePublicAppId, cluster, somePublicNamespace); .join(somePublicAppId, cluster, somePublicNamespace);
......
...@@ -110,6 +110,7 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest ...@@ -110,6 +110,7 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest
@Test @Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-dc-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) @Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigWithDataCenterFoundAndOverride() throws Exception { public void testQueryPublicConfigWithDataCenterFoundAndOverride() throws Exception {
ResponseEntity<ApolloConfig> response = restTemplate ResponseEntity<ApolloConfig> response = restTemplate
...@@ -118,11 +119,13 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest ...@@ -118,11 +119,13 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC);
ApolloConfig result = response.getBody(); ApolloConfig result = response.getBody();
assertEquals("TEST-RELEASE-KEY5" + ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR + "TEST-RELEASE-KEY4", result.getReleaseKey()); assertEquals(
"TEST-RELEASE-KEY6" + ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR + "TEST-RELEASE-KEY4",
result.getReleaseKey());
assertEquals(someAppId, result.getAppId()); assertEquals(someAppId, result.getAppId());
assertEquals(someDefaultCluster, result.getCluster()); assertEquals(someDC, result.getCluster());
assertEquals(somePublicNamespace, result.getNamespaceName()); assertEquals(somePublicNamespace, result.getNamespaceName());
assertEquals("override-v1", result.getConfigurations().get("k1")); assertEquals("override-someDC-v1", result.getConfigurations().get("k1"));
assertEquals("someDC-v2", result.getConfigurations().get("k2")); assertEquals("someDC-v2", result.getConfigurations().get("k2"));
} }
...@@ -147,6 +150,7 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest ...@@ -147,6 +150,7 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest
@Test @Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-default-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) @Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigWithDataCenterNotFoundAndOverride() throws Exception { public void testQueryPublicConfigWithDataCenterNotFoundAndOverride() throws Exception {
String someDCNotFound = "someDCNotFound"; String someDCNotFound = "someDCNotFound";
...@@ -156,7 +160,9 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest ...@@ -156,7 +160,9 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDCNotFound); getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDCNotFound);
ApolloConfig result = response.getBody(); ApolloConfig result = response.getBody();
assertEquals("TEST-RELEASE-KEY5" + ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR + "TEST-RELEASE-KEY3", result.getReleaseKey()); assertEquals(
"TEST-RELEASE-KEY5" + ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR + "TEST-RELEASE-KEY3",
result.getReleaseKey());
assertEquals(someAppId, result.getAppId()); assertEquals(someAppId, result.getAppId());
assertEquals(someDefaultCluster, result.getCluster()); assertEquals(someDefaultCluster, result.getCluster());
assertEquals(somePublicNamespace, result.getNamespaceName()); assertEquals(somePublicNamespace, result.getNamespaceName());
......
INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, NamespaceName, Configurations)
VALUES (995, 'TEST-RELEASE-KEY6', 'INTEGRATION-TEST-DEFAULT-OVERRIDE-PUBLIC-DC','First Release','someAppId', 'someDC', 'somePublicNamespace', '{"k1":"override-someDC-v1"}');
INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, NamespaceName, Configurations)
VALUES (994, 'TEST-RELEASE-KEY5', 'INTEGRATION-TEST-DEFAULT-OVERRIDE-PUBLIC','First Release','someAppId', 'default', 'somePublicNamespace', '{"k1":"override-v1"}');
...@@ -25,5 +25,3 @@ INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, Namespac ...@@ -25,5 +25,3 @@ INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, Namespac
VALUES (992, 'TEST-RELEASE-KEY3', 'INTEGRATION-TEST-PUBLIC-DEFAULT','First Release','somePublicAppId', 'default', 'somePublicNamespace', '{"k1":"default-v1", "k2":"default-v2"}'); VALUES (992, 'TEST-RELEASE-KEY3', 'INTEGRATION-TEST-PUBLIC-DEFAULT','First Release','somePublicAppId', 'default', 'somePublicNamespace', '{"k1":"default-v1", "k2":"default-v2"}');
INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, NamespaceName, Configurations) INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, NamespaceName, Configurations)
VALUES (993, 'TEST-RELEASE-KEY4', 'INTEGRATION-TEST-PUBLIC-NAMESPACE','First Release','somePublicAppId', 'someDC', 'somePublicNamespace', '{"k1":"someDC-v1", "k2":"someDC-v2"}'); VALUES (993, 'TEST-RELEASE-KEY4', 'INTEGRATION-TEST-PUBLIC-NAMESPACE','First Release','somePublicAppId', 'someDC', 'somePublicNamespace', '{"k1":"someDC-v1", "k2":"someDC-v2"}');
INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, NamespaceName, Configurations)
VALUES (994, 'TEST-RELEASE-KEY5', 'INTEGRATION-TEST-DEFAULT-OVERRIDE-PUBLIC','First Release','someAppId', 'default', 'somePublicNamespace', '{"k1":"override-v1"}');
19575
\ No newline at end of file
...@@ -139,7 +139,7 @@ ...@@ -139,7 +139,7 @@
<dependency> <dependency>
<groupId>com.ctrip.framework</groupId> <groupId>com.ctrip.framework</groupId>
<artifactId>framework-foundation</artifactId> <artifactId>framework-foundation</artifactId>
<version>1.1.5</version> <version>1.1.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.dianping.cat</groupId> <groupId>com.dianping.cat</groupId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment