Commit e7d91c7d by lepdou

change namespacePrefix to namespace

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