Commit e7d91c7d by lepdou

change namespacePrefix to namespace

parent 3da14c8c
...@@ -42,8 +42,8 @@ public class ConfigService { ...@@ -42,8 +42,8 @@ public class ConfigService {
return getManager().getConfig(namespace); return getManager().getConfig(namespace);
} }
public static ConfigFile getConfigFile(String namespacePrefix, ConfigFileFormat configFileFormat) { public static ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat) {
return getManager().getConfigFile(namespacePrefix, configFileFormat); return getManager().getConfigFile(namespace, configFileFormat);
} }
private static ConfigManager getManager() { private static ConfigManager getManager() {
......
...@@ -17,9 +17,9 @@ public interface ConfigManager { ...@@ -17,9 +17,9 @@ public interface ConfigManager {
/** /**
* Get the config file instance for the namespace specified. * Get the config file instance for the namespace specified.
* @param namespacePrefix the namespace * @param namespace the namespace
* @param configFileFormat the config file format * @param configFileFormat the config file format
* @return the config file instance for the namespace * @return the config file instance for the namespace
*/ */
public ConfigFile getConfigFile(String namespacePrefix, ConfigFileFormat configFileFormat); public ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat);
} }
...@@ -45,19 +45,19 @@ public class DefaultConfigManager implements ConfigManager { ...@@ -45,19 +45,19 @@ public class DefaultConfigManager implements ConfigManager {
} }
@Override @Override
public ConfigFile getConfigFile(String namespacePrefix, ConfigFileFormat configFileFormat) { public ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat) {
String namespace = String.format("%s.%s", namespacePrefix, configFileFormat.getValue()); String namespaceFileName = String.format("%s.%s", namespace, configFileFormat.getValue());
ConfigFile configFile = m_configFiles.get(namespace); ConfigFile configFile = m_configFiles.get(namespaceFileName);
if (configFile == null) { if (configFile == null) {
synchronized (this) { synchronized (this) {
configFile = m_configFiles.get(namespace); configFile = m_configFiles.get(namespaceFileName);
if (configFile == null) { if (configFile == null) {
ConfigFactory factory = m_factoryManager.getFactory(namespace); ConfigFactory factory = m_factoryManager.getFactory(namespaceFileName);
configFile = factory.createConfigFile(namespace, configFileFormat); configFile = factory.createConfigFile(namespaceFileName, configFileFormat);
m_configFiles.put(namespace, configFile); m_configFiles.put(namespaceFileName, configFile);
} }
} }
} }
......
...@@ -65,16 +65,16 @@ public class ConfigServiceTest extends ComponentTestCase { ...@@ -65,16 +65,16 @@ public class ConfigServiceTest extends ComponentTestCase {
@Test @Test
public void testMockConfigFactoryForConfigFile() throws Exception { public void testMockConfigFactoryForConfigFile() throws Exception {
String someNamespacePrefix = "mock"; String someNamespace = "mock";
ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties; ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties;
String someNamespace = String someNamespaceFileName =
String.format("%s.%s", someNamespacePrefix, someConfigFileFormat.getValue()); String.format("%s.%s", someNamespace, someConfigFileFormat.getValue());
defineComponent(ConfigFactory.class, someNamespace, MockConfigFactory.class); defineComponent(ConfigFactory.class, someNamespaceFileName, MockConfigFactory.class);
ConfigFile configFile = ConfigService.getConfigFile(someNamespacePrefix, someConfigFileFormat); ConfigFile configFile = ConfigService.getConfigFile(someNamespace, someConfigFileFormat);
assertEquals(someNamespace, configFile.getNamespace()); assertEquals(someNamespaceFileName, configFile.getNamespace());
assertEquals(someNamespace + ":" + someConfigFileFormat.getValue(), configFile.getContent()); assertEquals(someNamespaceFileName + ":" + someConfigFileFormat.getValue(), configFile.getContent());
} }
private static class MockConfig extends AbstractConfig { private static class MockConfig extends AbstractConfig {
......
...@@ -56,11 +56,11 @@ public class DefaultConfigManagerTest extends ComponentTestCase { ...@@ -56,11 +56,11 @@ public class DefaultConfigManagerTest extends ComponentTestCase {
@Test @Test
public void testGetConfigFile() throws Exception { public void testGetConfigFile() throws Exception {
String someNamespacePrefix = "someName"; String someNamespace = "someName";
ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties; ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties;
ConfigFile configFile = ConfigFile configFile =
defaultConfigManager.getConfigFile(someNamespacePrefix, someConfigFileFormat); defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat);
assertEquals(someConfigFileFormat, configFile.getConfigFileFormat()); assertEquals(someConfigFileFormat, configFile.getConfigFileFormat());
assertEquals(someConfigContent, configFile.getContent()); assertEquals(someConfigContent, configFile.getContent());
...@@ -68,13 +68,13 @@ public class DefaultConfigManagerTest extends ComponentTestCase { ...@@ -68,13 +68,13 @@ public class DefaultConfigManagerTest extends ComponentTestCase {
@Test @Test
public void testGetConfigFileMultipleTimesWithSameNamespace() throws Exception { public void testGetConfigFileMultipleTimesWithSameNamespace() throws Exception {
String someNamespacePrefix = "someName"; String someNamespace = "someName";
ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties; ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties;
ConfigFile someConfigFile = ConfigFile someConfigFile =
defaultConfigManager.getConfigFile(someNamespacePrefix, someConfigFileFormat); defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat);
ConfigFile anotherConfigFile = ConfigFile anotherConfigFile =
defaultConfigManager.getConfigFile(someNamespacePrefix, someConfigFileFormat); defaultConfigManager.getConfigFile(someNamespace, someConfigFileFormat);
assertThat( assertThat(
"Get config file multiple times with the same namespace should return the same config file instance", "Get config file multiple times with the same namespace should return the same config file instance",
......
...@@ -131,16 +131,16 @@ public class ConfigControllerTest { ...@@ -131,16 +131,16 @@ public class ConfigControllerTest {
public void testQueryConfigFileWithPrivateNamespace() throws Exception { public void testQueryConfigFileWithPrivateNamespace() throws Exception {
String someClientSideReleaseKey = "1"; String someClientSideReleaseKey = "1";
String someServerSideNewReleaseKey = "2"; String someServerSideNewReleaseKey = "2";
String somePrivateNamespacePrefix = "datasource"; String somePrivateNamespace = "datasource";
HttpServletResponse someResponse = mock(HttpServletResponse.class); HttpServletResponse someResponse = mock(HttpServletResponse.class);
String somePrivateNamespaceName = String.format("%s.%s", somePrivateNamespacePrefix, "xml"); String somePrivateNamespaceName = String.format("%s.%s", somePrivateNamespace, "xml");
AppNamespace appNamespace = mock(AppNamespace.class); AppNamespace appNamespace = mock(AppNamespace.class);
when(configService.findRelease(someAppId, someClusterName, somePrivateNamespacePrefix)) when(configService.findRelease(someAppId, someClusterName, somePrivateNamespace))
.thenReturn(someRelease); .thenReturn(someRelease);
when(someRelease.getReleaseKey()).thenReturn(someServerSideNewReleaseKey); when(someRelease.getReleaseKey()).thenReturn(someServerSideNewReleaseKey);
when(namespaceUtil.filterNamespaceName(somePrivateNamespaceName)).thenReturn(somePrivateNamespacePrefix); when(namespaceUtil.filterNamespaceName(somePrivateNamespaceName)).thenReturn(somePrivateNamespace);
when(appNamespaceService.findOne(someAppId, somePrivateNamespacePrefix)) when(appNamespaceService.findOne(someAppId, somePrivateNamespace))
.thenReturn(appNamespace); .thenReturn(appNamespace);
ApolloConfig result = configController.queryConfig(someAppId, someClusterName, ApolloConfig result = configController.queryConfig(someAppId, someClusterName,
......
...@@ -15,18 +15,18 @@ import java.io.InputStreamReader; ...@@ -15,18 +15,18 @@ import java.io.InputStreamReader;
public class ApolloConfigFileDemo { public class ApolloConfigFileDemo {
private static final Logger logger = LoggerFactory.getLogger(ApolloConfigDemo.class); private static final Logger logger = LoggerFactory.getLogger(ApolloConfigDemo.class);
private ConfigFile configFile; private ConfigFile configFile;
private String namespacePrefix = "application"; private String namespace = "application";
public ApolloConfigFileDemo() { public ApolloConfigFileDemo() {
configFile = ConfigService.getConfigFile(namespacePrefix, ConfigFileFormat.XML); configFile = ConfigService.getConfigFile(namespace, ConfigFileFormat.XML);
} }
private void print() { private void print() {
if (!configFile.hasContent()) { if (!configFile.hasContent()) {
System.out.println("No config file content found for " + namespacePrefix); System.out.println("No config file content found for " + namespace);
return; return;
} }
System.out.println("=== Config File Content for " + namespacePrefix + " is as follows: "); System.out.println("=== Config File Content for " + namespace + " is as follows: ");
System.out.println(configFile.getContent()); System.out.println(configFile.getContent());
} }
......
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