提交 f048baff 编写于 作者: J Jason Song

use guice as apollo-client ioc mechanism

上级 c219ee89
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apollo-biz</artifactId>
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -88,7 +88,7 @@ If you need this functionality, you could specify the cluster as follows:
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>0.6.4</version>
<version>0.7.0</version>
</dependency>
## III. Client Usage
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -21,12 +21,12 @@
<artifactId>apollo-core</artifactId>
</dependency>
<!-- end of apollo -->
<!-- foundation service -->
<!-- guice -->
<dependency>
<groupId>org.unidal.framework</groupId>
<artifactId>foundation-service</artifactId>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<!-- end of foundation service -->
<!-- end of guice -->
<!-- log -->
<dependency>
<groupId>org.slf4j</groupId>
......@@ -61,19 +61,5 @@
<scope>test</scope>
</dependency>
<!-- end of test -->
<!-- dal-jdbc -->
<dependency>
<groupId>org.unidal.framework</groupId>
<artifactId>dal-jdbc</artifactId>
<version>2.4.0</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>com.dianping.cat</groupId>
<artifactId>cat-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- end of dal-jdbc -->
</dependencies>
</project>
package com.ctrip.framework.apollo;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.internals.ConfigManager;
import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.spi.ConfigRegistry;
import com.ctrip.framework.apollo.tracer.Tracer;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.unidal.lookup.ContainerLoader;
/**
* Entry point for client config use
......@@ -20,25 +15,14 @@ import org.unidal.lookup.ContainerLoader;
public class ConfigService {
private static final ConfigService s_instance = new ConfigService();
private PlexusContainer m_container;
private volatile ConfigManager m_configManager;
private volatile ConfigRegistry m_configRegistry;
private ConfigService() {
m_container = ContainerLoader.getDefaultContainer();
}
private ConfigManager getManager() {
if (m_configManager == null) {
synchronized (this) {
if (m_configManager == null) {
try {
m_configManager = m_container.lookup(ConfigManager.class);
} catch (ComponentLookupException ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to load ConfigManager!", ex);
Tracer.logError(exception);
throw exception;
}
m_configManager = ApolloInjector.getInstance(ConfigManager.class);
}
}
}
......@@ -50,13 +34,7 @@ public class ConfigService {
if (m_configRegistry == null) {
synchronized (this) {
if (m_configRegistry == null) {
try {
m_configRegistry = m_container.lookup(ConfigRegistry.class);
} catch (ComponentLookupException ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to load ConfigRegistry!", ex);
Tracer.logError(exception);
throw exception;
}
m_configRegistry = ApolloInjector.getInstance(ConfigRegistry.class);
}
}
}
......@@ -127,9 +105,8 @@ public class ConfigService {
}
// for test only
static void setContainer(PlexusContainer m_container) {
static void reset() {
synchronized (s_instance) {
s_instance.m_container = m_container;
s_instance.m_configManager = null;
s_instance.m_configRegistry = null;
}
......
package com.ctrip.framework.apollo.build;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.internals.Injector;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.foundation.internals.ServiceBootstrap;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class ApolloInjector {
private static Injector s_injector;
private static Object lock = new Object();
private static Injector getInjector() {
if (s_injector == null) {
synchronized (lock) {
if (s_injector == null) {
try {
s_injector = ServiceBootstrap.loadFirst(Injector.class);
} catch (Throwable ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to initialize Apollo Injector!", ex);
Tracer.logError(exception);
throw exception;
}
}
}
}
return s_injector;
}
public static <T> T getInstance(Class<T> clazz) {
try {
return getInjector().getInstance(clazz);
} catch (Throwable ex) {
Tracer.logError(ex);
throw new ApolloConfigException(String.format("Unable to load instance for type %s!", clazz.getName()), ex);
}
}
public static <T> T getInstance(Class<T> clazz, String name) {
try {
return getInjector().getInstance(clazz, name);
} catch (Throwable ex) {
Tracer.logError(ex);
throw new ApolloConfigException(
String.format("Unable to load instance for type %s and name %s !", clazz.getName(), name), ex);
}
}
}
package com.ctrip.framework.apollo.build;
import com.ctrip.framework.apollo.internals.ConfigServiceLocator;
import com.ctrip.framework.apollo.internals.DefaultConfigManager;
import com.ctrip.framework.apollo.internals.RemoteConfigLongPollService;
import com.ctrip.framework.apollo.spi.DefaultConfigFactory;
import com.ctrip.framework.apollo.spi.DefaultConfigFactoryManager;
import com.ctrip.framework.apollo.spi.DefaultConfigRegistry;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import org.unidal.lookup.configuration.AbstractResourceConfigurator;
import org.unidal.lookup.configuration.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class ComponentConfigurator extends AbstractResourceConfigurator {
public static void main(String[] args) {
generatePlexusComponentsXmlFile(new ComponentConfigurator());
}
@Override
public List<Component> defineComponents() {
List<Component> all = new ArrayList<>();
all.add(A(DefaultConfigManager.class));
all.add(A(DefaultConfigFactory.class));
all.add(A(DefaultConfigRegistry.class));
all.add(A(DefaultConfigFactoryManager.class));
all.add(A(ConfigUtil.class));
all.add(A(HttpUtil.class));
all.add(A(ConfigServiceLocator.class));
all.add(A(RemoteConfigLongPollService.class));
return all;
}
}
package com.ctrip.framework.apollo.ds;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.foundation.Foundation;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.unidal.dal.jdbc.datasource.DataSourceProvider;
import org.unidal.dal.jdbc.datasource.model.entity.DataSourcesDef;
import org.unidal.dal.jdbc.datasource.model.transform.DefaultSaxParser;
import org.unidal.lookup.annotation.Named;
/**
* Data source provider based on Apollo configuration service.
* <p>
*
* Use following component definition to replace default
* <code>DataSourceProvider</code>:
* <p>
* <code><pre>
* public List<Component> defineComponents() {
* List<Component> all = new ArrayList<>();
*
* all.add(A(ApolloDataSourceProvider.class));
*
* return all;
* }
* </pre></code>
*
* <b>WARNING:</b> all defined <code>DataSourceProvider</code> components will
* be taken affect. DO NOT define unused <code>DataSourceProvider</code>
* component.
*/
@Named(type = DataSourceProvider.class, value = "apollo")
public class ApolloDataSourceProvider implements DataSourceProvider, LogEnabled {
private Logger m_logger;
private DataSourcesDef m_def;
@Override
public DataSourcesDef defineDatasources() {
if (m_def == null) {
ConfigFile file = ConfigService.getConfigFile("datasources", ConfigFileFormat.XML);
String appId = Foundation.app().getAppId();
String envType = Foundation.server().getEnvType();
if (file != null && file.hasContent()) {
String content = file.getContent();
m_logger.info(String.format("Found datasources.xml from Apollo(env=%s, app.id=%s)!", envType, appId));
try {
m_def = DefaultSaxParser.parse(content);
} catch (Exception e) {
throw new IllegalStateException(String.format("Error when parsing datasources.xml from Apollo(env=%s, app.id=%s)!", envType, appId), e);
}
} else {
m_logger.warn(String.format("Can't get datasources.xml from Apollo(env=%s, app.id=%s)!", envType, appId));
m_def = new DataSourcesDef();
}
}
return m_def;
}
@Override
public void enableLogging(Logger logger) {
m_logger = logger;
}
}
package com.ctrip.framework.apollo.internals;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
......@@ -20,21 +26,13 @@ import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.function.Functions;
import com.ctrip.framework.apollo.util.parser.Parsers;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.lookup.ContainerLoader;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
/**
* @author Jason Song(song_s@ctrip.com)
......@@ -65,15 +63,10 @@ public abstract class AbstractConfig implements Config {
}
public AbstractConfig() {
try {
m_configUtil = ContainerLoader.getDefaultContainer().lookup(ConfigUtil.class);
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
m_configVersion = new AtomicLong();
m_arrayCache = Maps.newConcurrentMap();
allCaches = Lists.newArrayList();
} catch (ComponentLookupException ex) {
Tracer.logError(ex);
throw new ApolloConfigException("Unable to load component!", ex);
}
}
@Override
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.internals;
import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import java.util.List;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Properties;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.google.common.collect.Lists;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.internals;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
......@@ -18,28 +21,17 @@ import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;
import com.google.gson.reflect.TypeToken;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.lookup.annotation.Inject;
import org.unidal.lookup.annotation.Named;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@Named(type = ConfigServiceLocator.class)
public class ConfigServiceLocator implements Initializable {
public class ConfigServiceLocator {
private static final Logger logger = LoggerFactory.getLogger(ConfigServiceLocator.class);
@Inject
private HttpUtil m_httpUtil;
@Inject
private ConfigUtil m_configUtil;
private AtomicReference<List<ServiceDTO>> m_configServices;
private Type m_responseType;
......@@ -55,12 +47,10 @@ public class ConfigServiceLocator implements Initializable {
m_configServices = new AtomicReference<>(initial);
m_responseType = new TypeToken<List<ServiceDTO>>() {
}.getType();
m_httpUtil = ApolloInjector.getInstance(HttpUtil.class);
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
this.m_executorService = Executors.newScheduledThreadPool(1,
ApolloThreadFactory.create("ConfigServiceLocator", true));
}
@Override
public void initialize() throws InitializationException {
this.tryUpdateConfigServices();
this.schedulePeriodicRefresh();
}
......
package com.ctrip.framework.apollo.internals;
import com.google.common.collect.ImmutableMap;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
......@@ -22,6 +10,17 @@ import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.google.common.collect.ImmutableMap;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.internals;
import com.google.common.collect.Maps;
import java.util.Map;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.spi.ConfigFactoryManager;
import org.unidal.lookup.annotation.Inject;
import org.unidal.lookup.annotation.Named;
import java.util.Map;
import com.google.common.collect.Maps;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Named(type = ConfigManager.class)
public class DefaultConfigManager implements ConfigManager {
@Inject
private ConfigFactoryManager m_factoryManager;
private Map<String, Config> m_configs = Maps.newConcurrentMap();
private Map<String, ConfigFile> m_configFiles = Maps.newConcurrentMap();
public DefaultConfigManager() {
m_factoryManager = ApolloInjector.getInstance(ConfigFactoryManager.class);
}
@Override
public Config getConfig(String namespace) {
Config config = m_configs.get(namespace);
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.spi.ConfigFactoryManager;
import com.ctrip.framework.apollo.spi.ConfigRegistry;
import com.ctrip.framework.apollo.spi.DefaultConfigFactory;
import com.ctrip.framework.apollo.spi.DefaultConfigFactoryManager;
import com.ctrip.framework.apollo.spi.DefaultConfigRegistry;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Singleton;
/**
* Guice injector
* @author Jason Song(song_s@ctrip.com)
*/
public class DefaultInjector implements Injector {
private com.google.inject.Injector m_injector;
public DefaultInjector() {
try {
m_injector = Guice.createInjector(new ApolloModule());
} catch (Throwable ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to initialize Guice Injector!", ex);
Tracer.logError(exception);
throw exception;
}
}
@Override
public <T> T getInstance(Class<T> clazz) {
try {
return m_injector.getInstance(clazz);
} catch (Throwable ex) {
Tracer.logError(ex);
throw new ApolloConfigException(
String.format("Unable to load instance for %s!", clazz.getName()), ex);
}
}
@Override
public <T> T getInstance(Class<T> clazz, String name) {
//Guice does not support get instance by type and name
return null;
}
private static class ApolloModule extends AbstractModule {
@Override
protected void configure() {
bind(ConfigManager.class).to(DefaultConfigManager.class).in(Singleton.class);
bind(ConfigFactoryManager.class).to(DefaultConfigFactoryManager.class).in(Singleton.class);
bind(ConfigRegistry.class).to(DefaultConfigRegistry.class).in(Singleton.class);
bind(ConfigFactory.class).to(DefaultConfigFactory.class).in(Singleton.class);
bind(ConfigUtil.class).in(Singleton.class);
bind(HttpUtil.class).in(Singleton.class);
bind(ConfigServiceLocator.class).in(Singleton.class);
bind(RemoteConfigLongPollService.class).in(Singleton.class);
}
}
}
package com.ctrip.framework.apollo.internals;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public interface Injector {
/**
* Returns the appropriate instance for the given injection type
*/
<T> T getInstance(Class<T> clazz);
/**
* Returns the appropriate instance for the given injection type and name
*/
<T> T getInstance(Class<T> clazz, String name);
}
package com.ctrip.framework.apollo.internals;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.lookup.ContainerLoader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
......@@ -28,6 +11,20 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......@@ -35,7 +32,6 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
implements RepositoryChangeListener {
private static final Logger logger = LoggerFactory.getLogger(LocalFileConfigRepository.class);
private static final String CONFIG_DIR = "/config-cache";
private final PlexusContainer m_container;
private final String m_namespace;
private File m_baseDir;
private final ConfigUtil m_configUtil;
......@@ -53,13 +49,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
public LocalFileConfigRepository(String namespace, ConfigRepository upstream) {
m_namespace = namespace;
m_container = ContainerLoader.getDefaultContainer();
try {
m_configUtil = m_container.lookup(ConfigUtil.class);
} catch (ComponentLookupException ex) {
Tracer.logError(ex);
throw new ApolloConfigException("Unable to load component!", ex);
}
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
this.setLocalCacheDir(findLocalCacheDir(), false);
this.setUpstreamRepository(upstream);
this.trySync();
......
package com.ctrip.framework.apollo.internals;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.utils.PropertiesUtil;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......
package com.ctrip.framework.apollo.internals;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;
import com.google.common.reflect.TypeToken;
import com.google.common.util.concurrent.RateLimiter;
import com.google.gson.Gson;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
......@@ -28,29 +29,23 @@ import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.lookup.annotation.Inject;
import org.unidal.lookup.annotation.Named;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;
import com.google.common.reflect.TypeToken;
import com.google.common.util.concurrent.RateLimiter;
import com.google.gson.Gson;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Named(type = RemoteConfigLongPollService.class)
public class RemoteConfigLongPollService implements Initializable {
public class RemoteConfigLongPollService {
private static final Logger logger = LoggerFactory.getLogger(RemoteConfigLongPollService.class);
private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR);
private static final Joiner.MapJoiner MAP_JOINER = Joiner.on("&").withKeyValueSeparator("=");
......@@ -65,11 +60,8 @@ public class RemoteConfigLongPollService implements Initializable {
private final ConcurrentMap<String, Long> m_notifications;
private Type m_responseType;
private Gson gson;
@Inject
private ConfigUtil m_configUtil;
@Inject
private HttpUtil m_httpUtil;
@Inject
private ConfigServiceLocator m_serviceLocator;
/**
......@@ -87,10 +79,9 @@ public class RemoteConfigLongPollService implements Initializable {
m_responseType = new TypeToken<List<ApolloConfigNotification>>() {
}.getType();
gson = new Gson();
}
@Override
public void initialize() throws InitializationException {
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
m_httpUtil = ApolloInjector.getInstance(HttpUtil.class);
m_serviceLocator = ApolloInjector.getInstance(ConfigServiceLocator.class);
m_longPollRateLimiter = RateLimiter.create(m_configUtil.getLongPollQPS());
}
......
package com.ctrip.framework.apollo.internals;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;
import com.google.common.util.concurrent.RateLimiter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.Apollo;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
......@@ -22,21 +27,13 @@ import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.lookup.ContainerLoader;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;
import com.google.common.util.concurrent.RateLimiter;
/**
* @author Jason Song(song_s@ctrip.com)
......@@ -45,11 +42,10 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
private static final Logger logger = LoggerFactory.getLogger(RemoteConfigRepository.class);
private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR);
private static final Joiner.MapJoiner MAP_JOINER = Joiner.on("&").withKeyValueSeparator("=");
private PlexusContainer m_container;
private final ConfigServiceLocator m_serviceLocator;
private final HttpUtil m_httpUtil;
private final ConfigUtil m_configUtil;
private final RemoteConfigLongPollService remoteConfigLongPollService;
private ConfigServiceLocator m_serviceLocator;
private HttpUtil m_httpUtil;
private ConfigUtil m_configUtil;
private RemoteConfigLongPollService remoteConfigLongPollService;
private volatile AtomicReference<ApolloConfig> m_configCache;
private final String m_namespace;
private final static ScheduledExecutorService m_executorService;
......@@ -71,16 +67,10 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
public RemoteConfigRepository(String namespace) {
m_namespace = namespace;
m_configCache = new AtomicReference<>();
m_container = ContainerLoader.getDefaultContainer();
try {
m_configUtil = m_container.lookup(ConfigUtil.class);
m_httpUtil = m_container.lookup(HttpUtil.class);
m_serviceLocator = m_container.lookup(ConfigServiceLocator.class);
remoteConfigLongPollService = m_container.lookup(RemoteConfigLongPollService.class);
} catch (ComponentLookupException ex) {
Tracer.logError(ex);
throw new ApolloConfigException("Unable to load component!", ex);
}
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
m_httpUtil = ApolloInjector.getInstance(HttpUtil.class);
m_serviceLocator = ApolloInjector.getInstance(ConfigServiceLocator.class);
remoteConfigLongPollService = ApolloInjector.getInstance(RemoteConfigLongPollService.class);
m_longPollServiceDto = new AtomicReference<>();
m_loadConfigRateLimiter = RateLimiter.create(m_configUtil.getLoadConfigQPS());
this.trySync();
......
package com.ctrip.framework.apollo.internals;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......
package com.ctrip.framework.apollo.spi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.internals.ConfigRepository;
import com.ctrip.framework.apollo.internals.DefaultConfig;
......@@ -14,20 +18,17 @@ import com.ctrip.framework.apollo.internals.YamlConfigFile;
import com.ctrip.framework.apollo.internals.YmlConfigFile;
import com.ctrip.framework.apollo.util.ConfigUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.lookup.annotation.Inject;
import org.unidal.lookup.annotation.Named;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Named(type = ConfigFactory.class)
public class DefaultConfigFactory implements ConfigFactory {
private static final Logger logger = LoggerFactory.getLogger(DefaultConfigFactory.class);
@Inject
private ConfigUtil m_configUtil;
public DefaultConfigFactory() {
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
}
@Override
public Config create(String namespace) {
DefaultConfig defaultConfig =
......
package com.ctrip.framework.apollo.spi;
import com.google.common.collect.Maps;
import org.unidal.lookup.ContainerHolder;
import org.unidal.lookup.LookupException;
import org.unidal.lookup.annotation.Inject;
import org.unidal.lookup.annotation.Named;
import java.util.Map;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.google.common.collect.Maps;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Named(type = ConfigFactoryManager.class)
public class DefaultConfigFactoryManager extends ContainerHolder implements ConfigFactoryManager {
@Inject
public class DefaultConfigFactoryManager implements ConfigFactoryManager {
private ConfigRegistry m_registry;
private Map<String, ConfigFactory> m_factories = Maps.newConcurrentMap();
public DefaultConfigFactoryManager() {
m_registry = ApolloInjector.getInstance(ConfigRegistry.class);
}
@Override
public ConfigFactory getFactory(String namespace) {
// step 1: check hacked factory
......@@ -36,16 +34,14 @@ public class DefaultConfigFactoryManager extends ContainerHolder implements Conf
}
// step 3: check declared config factory
try {
factory = lookup(ConfigFactory.class, namespace);
} catch (LookupException ex) {
// ignore it
factory = ApolloInjector.getInstance(ConfigFactory.class, namespace);
if (factory != null) {
return factory;
}
// step 4: check default config factory
if (factory == null) {
factory = lookup(ConfigFactory.class);
}
factory = ApolloInjector.getInstance(ConfigFactory.class);
m_factories.put(namespace, factory);
......
package com.ctrip.framework.apollo.spi;
import com.google.common.collect.Maps;
import java.util.Map;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.unidal.lookup.annotation.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import com.google.common.collect.Maps;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Named(type = ConfigRegistry.class)
public class DefaultConfigRegistry implements ConfigRegistry, LogEnabled {
public class DefaultConfigRegistry implements ConfigRegistry {
private static final Logger s_logger = LoggerFactory.getLogger(DefaultConfigRegistry.class);
private Map<String, ConfigFactory> m_instances = Maps.newConcurrentMap();
private Logger m_logger;
@Override
public void register(String namespace, ConfigFactory factory) {
if (m_instances.containsKey(namespace)) {
m_logger.warn(
String.format("ConfigFactory(%s) is overridden by %s!", namespace, factory.getClass()));
s_logger.warn("ConfigFactory({}) is overridden by {}!", namespace, factory.getClass());
}
m_instances.put(namespace, factory);
......@@ -33,9 +29,4 @@ public class DefaultConfigRegistry implements ConfigRegistry, LogEnabled {
return config;
}
@Override
public void enableLogging(Logger logger) {
m_logger = logger;
}
}
package com.ctrip.framework.apollo.spring.annotation;
import com.google.common.base.Preconditions;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
......@@ -14,8 +10,11 @@ import org.springframework.core.PriorityOrdered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.google.common.base.Preconditions;
/**
* Apollo Annotation Processor for Spring Application
......
package com.ctrip.framework.apollo.spring.annotation;
import com.ctrip.framework.apollo.core.ConfigConsts;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.ctrip.framework.apollo.core.ConfigConsts;
/**
* Use this annotation to inject Apollo Config Instance.
*
......
package com.ctrip.framework.apollo.spring.annotation;
import com.ctrip.framework.apollo.core.ConfigConsts;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.ctrip.framework.apollo.core.ConfigConsts;
/**
* Use this annotation to register Apollo ConfigChangeListener.
*
......
package com.ctrip.framework.apollo.spring.annotation;
import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.spring.config.PropertySourcesProcessor;
import com.ctrip.framework.apollo.spring.util.BeanRegistrationUtil;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import com.ctrip.framework.apollo.spring.config.PropertySourcesProcessor;
import com.ctrip.framework.apollo.spring.util.BeanRegistrationUtil;
import com.google.common.collect.Lists;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......
package com.ctrip.framework.apollo.spring.annotation;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import com.ctrip.framework.apollo.core.ConfigConsts;
/**
* Use this annotation to register Apollo property sources when using Java Config.
*
......
package com.ctrip.framework.apollo.spring.config;
import java.util.Set;
import org.springframework.core.env.EnumerablePropertySource;
import com.ctrip.framework.apollo.Config;
......
package com.ctrip.framework.apollo.spring.config;
import com.ctrip.framework.apollo.spring.annotation.ApolloAnnotationProcessor;
import com.ctrip.framework.apollo.spring.util.BeanRegistrationUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import com.ctrip.framework.apollo.spring.annotation.ApolloAnnotationProcessor;
import com.ctrip.framework.apollo.spring.util.BeanRegistrationUtil;
/**
* Apollo Property Sources processor for Spring XML Based Application
*
......
package com.ctrip.framework.apollo.spring.config;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
import org.springframework.core.Ordered;
import org.w3c.dom.Element;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......
package com.ctrip.framework.apollo.spring.config;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Multimap;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import java.util.Collection;
import java.util.Iterator;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
......@@ -17,9 +13,11 @@ import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicBoolean;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Multimap;
/**
* Apollo Property Sources processor for Spring Annotation Based Application
......
package com.ctrip.framework.apollo.spring.util;
import java.util.Objects;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import java.util.Objects;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......
package com.ctrip.framework.apollo.util;
import com.google.common.base.Strings;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.MetaDomainConsts;
......@@ -8,17 +11,11 @@ import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.enums.EnvUtils;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.foundation.Foundation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.unidal.lookup.annotation.Named;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Strings;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Named(type = ConfigUtil.class)
public class ConfigUtil {
private static final Logger logger = LoggerFactory.getLogger(ConfigUtil.class);
private static final String TOOLING_CLUSTER = "tooling";
......
package com.ctrip.framework.apollo.util;
import java.util.List;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import java.util.List;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......
package com.ctrip.framework.apollo.util.function;
import com.google.common.base.Function;
import java.util.Date;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.util.parser.ParserException;
import com.ctrip.framework.apollo.util.parser.Parsers;
import java.util.Date;
import com.google.common.base.Function;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.util.http;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.io.BaseEncoding;
import com.google.gson.Gson;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException;
import com.ctrip.framework.apollo.util.ConfigUtil;
import org.unidal.helper.Files;
import org.unidal.lookup.annotation.Inject;
import org.unidal.lookup.annotation.Named;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.google.common.base.Function;
import com.google.common.io.BaseEncoding;
import com.google.common.io.CharStreams;
import com.google.gson.Gson;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Named(type = HttpUtil.class)
public class HttpUtil {
@Inject
private ConfigUtil m_configUtil;
private Gson gson;
private String basicAuth;
......@@ -34,6 +29,7 @@ public class HttpUtil {
* Constructor.
*/
public HttpUtil() {
m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
gson = new Gson();
try {
basicAuth = "Basic " + BaseEncoding.base64().encode("user:".getBytes("UTF-8"));
......@@ -82,7 +78,7 @@ public class HttpUtil {
private <T> HttpResponse<T> doGetWithSerializeFunction(HttpRequest httpRequest,
Function<String, T> serializeFunction) {
InputStream is = null;
InputStreamReader isr = null;
int statusCode;
try {
HttpURLConnection conn = (HttpURLConnection) new URL(httpRequest.getUrl()).openConnection();
......@@ -108,8 +104,8 @@ public class HttpUtil {
statusCode = conn.getResponseCode();
if (statusCode == 200) {
is = conn.getInputStream();
String content = Files.IO.INSTANCE.readFrom(is, Charsets.UTF_8.name());
isr = new InputStreamReader(conn.getInputStream());
String content = CharStreams.toString(isr);
return new HttpResponse<>(statusCode, serializeFunction.apply(content));
}
......@@ -120,10 +116,10 @@ public class HttpUtil {
} catch (Throwable ex) {
throw new ApolloConfigException("Could not complete get operation", ex);
} finally {
if (is != null) {
if (isr != null) {
try {
is.close();
} catch (IOException ex) {
isr.close();
} catch (IOException e) {
// ignore
}
}
......
<plexus>
<components>
<component>
<role>com.ctrip.framework.apollo.internals.ConfigManager</role>
<implementation>com.ctrip.framework.apollo.internals.DefaultConfigManager</implementation>
<requirements>
<requirement>
<role>com.ctrip.framework.apollo.spi.ConfigFactoryManager</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.framework.apollo.spi.ConfigFactory</role>
<implementation>com.ctrip.framework.apollo.spi.DefaultConfigFactory</implementation>
<requirements>
<requirement>
<role>com.ctrip.framework.apollo.util.ConfigUtil</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.framework.apollo.spi.ConfigRegistry</role>
<implementation>com.ctrip.framework.apollo.spi.DefaultConfigRegistry</implementation>
</component>
<component>
<role>com.ctrip.framework.apollo.spi.ConfigFactoryManager</role>
<implementation>com.ctrip.framework.apollo.spi.DefaultConfigFactoryManager</implementation>
<requirements>
<requirement>
<role>com.ctrip.framework.apollo.spi.ConfigRegistry</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.framework.apollo.util.ConfigUtil</role>
<implementation>com.ctrip.framework.apollo.util.ConfigUtil</implementation>
</component>
<component>
<role>com.ctrip.framework.apollo.util.http.HttpUtil</role>
<implementation>com.ctrip.framework.apollo.util.http.HttpUtil</implementation>
<requirements>
<requirement>
<role>com.ctrip.framework.apollo.util.ConfigUtil</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.framework.apollo.internals.ConfigServiceLocator</role>
<implementation>com.ctrip.framework.apollo.internals.ConfigServiceLocator</implementation>
<requirements>
<requirement>
<role>com.ctrip.framework.apollo.util.http.HttpUtil</role>
</requirement>
<requirement>
<role>com.ctrip.framework.apollo.util.ConfigUtil</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.framework.apollo.internals.RemoteConfigLongPollService</role>
<implementation>com.ctrip.framework.apollo.internals.RemoteConfigLongPollService</implementation>
<requirements>
<requirement>
<role>com.ctrip.framework.apollo.util.ConfigUtil</role>
</requirement>
<requirement>
<role>com.ctrip.framework.apollo.util.http.HttpUtil</role>
</requirement>
<requirement>
<role>com.ctrip.framework.apollo.internals.ConfigServiceLocator</role>
</requirement>
</requirements>
</component>
</components>
</plexus>
com.ctrip.framework.apollo.internals.DefaultInjector
\ No newline at end of file
package com.ctrip.framework.apollo;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import com.ctrip.framework.apollo.integration.ConfigIntegrationTest;
import com.ctrip.framework.apollo.internals.DefaultConfigManagerTest;
import com.ctrip.framework.apollo.internals.DefaultConfigTest;
......@@ -22,10 +26,6 @@ import com.ctrip.framework.apollo.util.ExceptionUtilTest;
import com.ctrip.framework.apollo.util.parser.DateParserTest;
import com.ctrip.framework.apollo.util.parser.DurationParserTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
ConfigServiceTest.class, DefaultConfigRegistryTest.class, DefaultConfigFactoryManagerTest.class,
......
package com.ctrip.framework.apollo;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.gson.Gson;
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.util.ConfigUtil;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
......@@ -18,22 +18,22 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.unidal.lookup.ComponentTestCase;
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.internals.DefaultInjector;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.gson.Gson;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public abstract class BaseIntegrationTest extends ComponentTestCase {
public abstract class BaseIntegrationTest{
private static final int PORT = findFreePort();
private static final String metaServiceUrl = "http://localhost:" + PORT;
private static final String someAppName = "someAppName";
......@@ -56,8 +56,6 @@ public abstract class BaseIntegrationTest extends ComponentTestCase {
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
someAppId = "1003171";
someClusterName = "someClusterName";
someDataCenter = "someDC";
......@@ -65,9 +63,11 @@ public abstract class BaseIntegrationTest extends ComponentTestCase {
refreshTimeUnit = TimeUnit.MINUTES;
//as ConfigService is singleton, so we must manually clear its container
ConfigService.setContainer(getContainer());
ConfigService.reset();
MockInjector.reset();
MockInjector.setDelegate(new DefaultInjector());
defineComponent(ConfigUtil.class, MockConfigUtil.class);
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
}
/**
......@@ -93,7 +93,6 @@ public abstract class BaseIntegrationTest extends ComponentTestCase {
if (server != null && server.isStarted()) {
server.stop();
}
super.tearDown();
}
protected ContextHandler mockMetaServerHandler() {
......
package com.ctrip.framework.apollo;
import static org.junit.Assert.assertEquals;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.internals.AbstractConfig;
import com.ctrip.framework.apollo.internals.DefaultInjector;
import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.util.ConfigUtil;
import org.junit.Before;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
import java.util.Set;
import static org.junit.Assert.assertEquals;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class ConfigServiceTest extends ComponentTestCase {
public class ConfigServiceTest {
private static String someAppId;
@Override
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
someAppId = "someAppId";
//as ConfigService is singleton, so we must manually clear its container
ConfigService.setContainer(getContainer());
defineComponent(ConfigUtil.class, MockConfigUtil.class);
ConfigService.reset();
MockInjector.reset();
MockInjector.setDelegate(new DefaultInjector());
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
}
@Test
......@@ -58,7 +59,7 @@ public class ConfigServiceTest extends ComponentTestCase {
public void testMockConfigFactory() throws Exception {
String someNamespace = "mock";
String someKey = "someKey";
defineComponent(ConfigFactory.class, someNamespace, MockConfigFactory.class);
MockInjector.setInstance(ConfigFactory.class, someNamespace, new MockConfigFactory());
Config config = ConfigService.getConfig(someNamespace);
......@@ -72,7 +73,7 @@ public class ConfigServiceTest extends ComponentTestCase {
ConfigFileFormat someConfigFileFormat = ConfigFileFormat.Properties;
String someNamespaceFileName =
String.format("%s.%s", someNamespace, someConfigFileFormat.getValue());
defineComponent(ConfigFactory.class, someNamespaceFileName, MockConfigFactory.class);
MockInjector.setInstance(ConfigFactory.class, someNamespaceFileName, new MockConfigFactory());
ConfigFile configFile = ConfigService.getConfigFile(someNamespace, someConfigFileFormat);
......
package com.ctrip.framework.apollo.build;
import java.util.Map;
import com.ctrip.framework.apollo.internals.DefaultInjector;
import com.ctrip.framework.apollo.internals.Injector;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class MockInjector implements Injector {
private static Map<Class, Object> classMap = Maps.newHashMap();
private static Table<Class, String, Object> classTable = HashBasedTable.create();
private static Injector delegate = new DefaultInjector();
@Override
public <T> T getInstance(Class<T> clazz) {
T o = (T) classMap.get(clazz);
if (o != null) {
return o;
}
if (delegate != null) {
return delegate.getInstance(clazz);
}
return null;
}
@Override
public <T> T getInstance(Class<T> clazz, String name) {
T o = (T) classTable.get(clazz, name);
if (o != null) {
return o;
}
if (delegate != null) {
return delegate.getInstance(clazz, name);
}
return null;
}
public static void setInstance(Class clazz, Object o) {
classMap.put(clazz, o);
}
public static void setInstance(Class clazz, String name, Object o) {
classTable.put(clazz, name, o);
}
public static void setDelegate(Injector delegateInjector) {
delegate = delegateInjector;
}
public static void reset() {
classMap.clear();
classTable.clear();
delegate = null;
}
}
package com.ctrip.framework.apollo.integration;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.SettableFuture;
import com.ctrip.framework.apollo.BaseIntegrationTest;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.internals.RemoteConfigLongPollService;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
......@@ -39,10 +19,30 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;
import com.ctrip.framework.apollo.BaseIntegrationTest;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.internals.RemoteConfigLongPollService;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.SettableFuture;
/**
* @author Jason Song(song_s@ctrip.com)
......@@ -66,7 +66,7 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
configDir.delete();
}
configDir.mkdirs();
remoteConfigLongPollService = lookup(RemoteConfigLongPollService.class);
remoteConfigLongPollService = ApolloInjector.getInstance(RemoteConfigLongPollService.class);
}
@Override
......
package com.ctrip.framework.apollo.internals;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.spi.ConfigFactoryManager;
import org.junit.Before;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
import java.util.Set;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import com.ctrip.framework.apollo.util.ConfigUtil;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class DefaultConfigManagerTest extends ComponentTestCase {
public class DefaultConfigManagerTest {
private DefaultConfigManager defaultConfigManager;
private static String someConfigContent;
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
defineComponent(ConfigFactoryManager.class, MockConfigFactoryManager.class);
defaultConfigManager = (DefaultConfigManager) lookup(ConfigManager.class);
MockInjector.reset();
MockInjector.setInstance(ConfigFactoryManager.class, new MockConfigFactoryManager());
MockInjector.setInstance(ConfigUtil.class, new ConfigUtil());
defaultConfigManager = new DefaultConfigManager();
someConfigContent = "someContent";
}
......
package com.ctrip.framework.apollo.internals;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import com.google.common.util.concurrent.SettableFuture;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.util.ConfigUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import com.google.common.util.concurrent.SettableFuture;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class DefaultConfigTest extends ComponentTestCase {
public class DefaultConfigTest {
private File someResourceDir;
private String someNamespace;
private ConfigRepository configRepository;
......@@ -43,9 +42,8 @@ public class DefaultConfigTest extends ComponentTestCase {
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
defineComponent(ConfigUtil.class, MockConfigUtil.class);
MockInjector.reset();
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
someResourceDir = new File(ClassLoaderUtil.getClassPath() + "/META-INF/config");
someResourceDir.mkdirs();
......@@ -55,7 +53,6 @@ public class DefaultConfigTest extends ComponentTestCase {
@After
public void tearDown() throws Exception {
super.tearDown();
recursiveDelete(someResourceDir);
}
......@@ -197,7 +194,7 @@ public class DefaultConfigTest extends ComponentTestCase {
Integer someDefaultValue = -1;
defineComponent(ConfigUtil.class, MockConfigUtilWithSmallCache.class);
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtilWithSmallCache());
//set up config repo
someProperties = mock(Properties.class);
......@@ -230,7 +227,7 @@ public class DefaultConfigTest extends ComponentTestCase {
Integer someDefaultValue = -1;
defineComponent(ConfigUtil.class, MockConfigUtilWithShortExpireTime.class);
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtilWithShortExpireTime());
//set up config repo
someProperties = mock(Properties.class);
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
......@@ -9,13 +14,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.internals;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.io.Files;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.util.ConfigUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.unidal.lookup.ComponentTestCase;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
......@@ -27,10 +9,27 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.io.Files;
/**
* Created by Jason on 4/9/16.
*/
public class LocalFileConfigRepositoryTest extends ComponentTestCase {
public class LocalFileConfigRepositoryTest {
private File someBaseDir;
private String someNamespace;
private ConfigRepository upstreamRepo;
......@@ -42,8 +41,6 @@ public class LocalFileConfigRepositoryTest extends ComponentTestCase {
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
someBaseDir = new File("src/test/resources/config-cache");
someBaseDir.mkdir();
......@@ -55,12 +52,12 @@ public class LocalFileConfigRepositoryTest extends ComponentTestCase {
upstreamRepo = mock(ConfigRepository.class);
when(upstreamRepo.getConfig()).thenReturn(someProperties);
defineComponent(ConfigUtil.class, MockConfigUtil.class);
MockInjector.reset();
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
}
@After
public void tearDown() throws Exception {
super.tearDown();
recursiveDelete(someBaseDir);
}
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
......@@ -8,13 +14,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.internals;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.SettableFuture;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.http.HttpServletResponse;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -20,36 +26,30 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.springframework.test.util.ReflectionTestUtils;
import org.unidal.lookup.ComponentTestCase;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.http.HttpServletResponse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.SettableFuture;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@RunWith(MockitoJUnitRunner.class)
public class RemoteConfigLongPollServiceTest extends ComponentTestCase {
public class RemoteConfigLongPollServiceTest {
private RemoteConfigLongPollService remoteConfigLongPollService;
@Mock
private HttpResponse<List<ApolloConfigNotification>> pollResponse;
@Mock
private HttpUtil httpUtil;
@Mock
private ConfigServiceLocator configServiceLocator;
private Type responseType;
private static String someServerUrl;
......@@ -58,15 +58,19 @@ public class RemoteConfigLongPollServiceTest extends ComponentTestCase {
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
MockInjector.reset();
MockInjector.setInstance(HttpUtil.class, httpUtil);
ServiceDTO serviceDTO = mock(ServiceDTO.class);
when(serviceDTO.getHomepageUrl()).thenReturn(someServerUrl);
when(configServiceLocator.getConfigServices()).thenReturn(Lists.newArrayList(serviceDTO));
MockInjector.setInstance(ConfigServiceLocator.class, configServiceLocator);
defineComponent(ConfigUtil.class, MockConfigUtil.class);
defineComponent(ConfigServiceLocator.class, MockConfigServiceLocator.class);
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
remoteConfigLongPollService = lookup(RemoteConfigLongPollService.class);
remoteConfigLongPollService = new RemoteConfigLongPollService();
ReflectionTestUtils.setField(remoteConfigLongPollService, "m_httpUtil", httpUtil);
responseType =
(Type) ReflectionTestUtils.getField(remoteConfigLongPollService, "m_responseType");
......@@ -365,18 +369,4 @@ public class RemoteConfigLongPollServiceTest extends ComponentTestCase {
}
}
public static class MockConfigServiceLocator extends ConfigServiceLocator {
@Override
public List<ServiceDTO> getConfigServices() {
ServiceDTO serviceDTO = mock(ServiceDTO.class);
when(serviceDTO.getHomepageUrl()).thenReturn(someServerUrl);
return Lists.newArrayList(serviceDTO);
}
@Override
public void initialize() throws InitializationException {
//do nothing
}
}
}
package com.ctrip.framework.apollo.internals;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.SettableFuture;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletResponse;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -23,31 +26,26 @@ import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.unidal.lookup.ComponentTestCase;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletResponse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.SettableFuture;
/**
* Created by Jason on 4/9/16.
*/
@RunWith(MockitoJUnitRunner.class)
public class RemoteConfigRepositoryTest extends ComponentTestCase {
public class RemoteConfigRepositoryTest {
@Mock
private ConfigServiceLocator configServiceLocator;
private String someNamespace;
......@@ -59,17 +57,26 @@ public class RemoteConfigRepositoryTest extends ComponentTestCase {
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
someNamespace = "someName";
when(pollResponse.getStatusCode()).thenReturn(HttpServletResponse.SC_NOT_MODIFIED);
defineComponent(ConfigUtil.class, MockConfigUtil.class);
defineComponent(ConfigServiceLocator.class, MockConfigServiceLocator.class);
defineComponent(HttpUtil.class, MockHttpUtil.class);
MockInjector.reset();
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
String someServerUrl = "http://someServer";
ServiceDTO serviceDTO = mock(ServiceDTO.class);
remoteConfigLongPollService = lookup(RemoteConfigLongPollService.class);
when(serviceDTO.getHomepageUrl()).thenReturn(someServerUrl);
when(configServiceLocator.getConfigServices()).thenReturn(Lists.newArrayList(serviceDTO));
MockInjector.setInstance(ConfigServiceLocator.class, configServiceLocator);
MockInjector.setInstance(HttpUtil.class, new MockHttpUtil());
remoteConfigLongPollService = new RemoteConfigLongPollService();
MockInjector.setInstance(RemoteConfigLongPollService.class, remoteConfigLongPollService);
}
@Test
......@@ -245,23 +252,6 @@ public class RemoteConfigRepositoryTest extends ComponentTestCase {
}
}
public static class MockConfigServiceLocator extends ConfigServiceLocator {
@Override
public List<ServiceDTO> getConfigServices() {
String someServerUrl = "http://someServer";
ServiceDTO serviceDTO = mock(ServiceDTO.class);
when(serviceDTO.getHomepageUrl()).thenReturn(someServerUrl);
return Lists.newArrayList(serviceDTO);
}
@Override
public void initialize() throws InitializationException {
//do nothing
}
}
public static class MockHttpUtil extends HttpUtil {
@Override
public <T> HttpResponse<T> doGet(HttpRequest httpRequest, Class<T> responseType) {
......
package com.ctrip.framework.apollo.internals;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.SettableFuture;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
......@@ -15,11 +12,13 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.SettableFuture;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
......@@ -9,13 +14,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.spi;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import org.junit.Before;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class DefaultConfigFactoryManagerTest extends ComponentTestCase {
public class DefaultConfigFactoryManagerTest {
private DefaultConfigFactoryManager defaultConfigFactoryManager;
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
defineComponent(ConfigRegistry.class, MockConfigRegistry.class);
defaultConfigFactoryManager =
(DefaultConfigFactoryManager) lookup(ConfigFactoryManager.class);
MockInjector.reset();
MockInjector.setInstance(ConfigRegistry.class, new MockConfigRegistry());
defaultConfigFactoryManager = new DefaultConfigFactoryManager();
}
@Test
......@@ -39,7 +37,7 @@ public class DefaultConfigFactoryManagerTest extends ComponentTestCase {
@Test
public void testGetFactoryFromNamespace() throws Exception {
String someNamespace = "someName";
defineComponent(ConfigFactory.class, someNamespace, SomeConfigFactory.class);
MockInjector.setInstance(ConfigFactory.class, someNamespace, new SomeConfigFactory());
ConfigFactory result = defaultConfigFactoryManager.getFactory(someNamespace);
......@@ -50,7 +48,7 @@ public class DefaultConfigFactoryManagerTest extends ComponentTestCase {
@Test
public void testGetFactoryFromNamespaceMultipleTimes() throws Exception {
String someNamespace = "someName";
defineComponent(ConfigFactory.class, someNamespace, SomeConfigFactory.class);
MockInjector.setInstance(ConfigFactory.class, someNamespace, new SomeConfigFactory());
ConfigFactory result = defaultConfigFactoryManager.getFactory(someNamespace);
ConfigFactory anotherResult = defaultConfigFactoryManager.getFactory(someNamespace);
......@@ -63,7 +61,7 @@ public class DefaultConfigFactoryManagerTest extends ComponentTestCase {
@Test
public void testGetFactoryFromDefault() throws Exception {
String someNamespace = "someName";
defineComponent(ConfigFactory.class, AnotherConfigFactory.class);
MockInjector.setInstance(ConfigFactory.class, new AnotherConfigFactory());
ConfigFactory result = defaultConfigFactoryManager.getFactory(someNamespace);
......
package com.ctrip.framework.apollo.spi;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.internals.DefaultConfig;
......@@ -13,39 +30,21 @@ import com.ctrip.framework.apollo.internals.YamlConfigFile;
import com.ctrip.framework.apollo.internals.YmlConfigFile;
import com.ctrip.framework.apollo.util.ConfigUtil;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;
import org.unidal.lookup.ComponentTestCase;
import java.util.Properties;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class DefaultConfigFactoryTest extends ComponentTestCase {
public class DefaultConfigFactoryTest {
private DefaultConfigFactory defaultConfigFactory;
private static String someAppId;
private static Env someEnv;
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
someAppId = "someId";
someEnv = Env.DEV;
defineComponent(ConfigUtil.class, MockConfigUtil.class);
defaultConfigFactory = spy((DefaultConfigFactory) lookup(ConfigFactory.class));
MockInjector.reset();
MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
defaultConfigFactory = spy(new DefaultConfigFactory());
}
@Test
......
package com.ctrip.framework.apollo.spi;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class DefaultConfigRegistryTest extends ComponentTestCase {
public class DefaultConfigRegistryTest {
private DefaultConfigRegistry defaultConfigRegistry;
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
defaultConfigRegistry = (DefaultConfigRegistry) lookup(ConfigRegistry.class);
MockInjector.reset();
defaultConfigRegistry = new DefaultConfigRegistry();
}
@Test
......
package com.ctrip.framework.apollo.spring;
import com.google.common.collect.Maps;
import java.lang.reflect.Method;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.springframework.util.ReflectionUtils;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.build.MockInjector;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.internals.ConfigManager;
import com.ctrip.framework.apollo.spring.config.PropertySourcesProcessor;
import org.codehaus.plexus.PlexusContainer;
import org.junit.After;
import org.junit.Before;
import org.springframework.util.ReflectionUtils;
import org.unidal.lookup.ComponentTestCase;
import java.lang.reflect.Method;
import java.util.Map;
import com.google.common.collect.Maps;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public abstract class AbstractSpringIntegrationTest extends ComponentTestCase {
public abstract class AbstractSpringIntegrationTest {
private static final Map<String, Config> CONFIG_REGISTRY = Maps.newHashMap();
private static Method PROPERTY_SOURCES_PROCESSOR_CLEAR;
private static Method CONFIG_SERVICE_SET_CONTAINER;
private static Method CONFIG_SERVICE_RESET;
static {
try {
PROPERTY_SOURCES_PROCESSOR_CLEAR = PropertySourcesProcessor.class.getDeclaredMethod("reset");
ReflectionUtils.makeAccessible(PROPERTY_SOURCES_PROCESSOR_CLEAR);
CONFIG_SERVICE_SET_CONTAINER = ConfigService.class.getDeclaredMethod("setContainer", PlexusContainer.class);
ReflectionUtils.makeAccessible(CONFIG_SERVICE_SET_CONTAINER);
CONFIG_SERVICE_RESET = ConfigService.class.getDeclaredMethod("reset");
ReflectionUtils.makeAccessible(CONFIG_SERVICE_RESET);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
@Override
@Before
public void setUp() throws Exception {
super.tearDown();//clear the container
super.setUp();
//as PropertySourcesProcessor has some static states, so we must manually clear its state
ReflectionUtils.invokeMethod(PROPERTY_SOURCES_PROCESSOR_CLEAR, null);
//as ConfigService is singleton, so we must manually clear its container
ReflectionUtils.invokeMethod(CONFIG_SERVICE_SET_CONTAINER, null, getContainer());
defineComponent(ConfigManager.class, MockConfigManager.class);
ReflectionUtils.invokeMethod(CONFIG_SERVICE_RESET, null);
MockInjector.reset();
MockInjector.setInstance(ConfigManager.class, new MockConfigManager());
}
@Override
@After
public void tearDown() throws Exception {
super.tearDown();
CONFIG_REGISTRY.clear();
}
......
package com.ctrip.framework.apollo.spring;
import com.google.common.collect.Lists;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import java.util.List;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
......@@ -18,12 +15,14 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import com.google.common.collect.Lists;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.spring;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
......@@ -11,11 +13,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.spring;
import com.google.common.collect.Lists;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import java.util.List;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
......@@ -15,12 +13,13 @@ import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import com.google.common.collect.Lists;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.spring;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.core.ConfigConsts;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......
package com.ctrip.framework.apollo.util;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* @author Jason Song(song_s@ctrip.com)
*/
......
package com.ctrip.framework.apollo.util.parser;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.util.parser;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class DurationParserTest {
private Parsers.DurationParser durationParser = Parsers.forDuration();
......
com.ctrip.framework.apollo.build.MockInjector
\ No newline at end of file
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -4,7 +4,7 @@
<parent>
<artifactId>apollo</artifactId>
<groupId>com.ctrip.framework.apollo</groupId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apollo-demo</artifactId>
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId>
<version>0.6.4-SNAPSHOT</version>
<version>0.7.0-SNAPSHOT</version>
<name>Apollo</name>
<packaging>pom</packaging>
<description>Ctrip Configuration Center</description>
......@@ -263,9 +263,9 @@
<version>5.1.39</version>
</dependency>
<dependency>
<groupId>org.unidal.framework</groupId>
<artifactId>foundation-service</artifactId>
<version>2.5.6</version>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
<!--for test -->
<dependency>
......@@ -583,12 +583,6 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>internal.repo</id>
<url>https://raw.github.com/ctripcorp/apollo/mvn-repo/</url>
</repository>
</repositories>
</profile>
<profile>
<!-- for open source usage -->
......@@ -599,12 +593,6 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>internal.repo</id>
<url>https://raw.github.com/ctripcorp/apollo/mvn-repo/</url>
</repository>
</repositories>
</profile>
<profile>
<!-- for ctrip development -->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册