Skip to content

Commit

Permalink
Simplify code (apolloconfig#3290)
Browse files Browse the repository at this point in the history
  • Loading branch information
waters00 authored Sep 11, 2020
1 parent fe2f059 commit e321a8e
Show file tree
Hide file tree
Showing 87 changed files with 173 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testNamespaceModifyItem() {
Namespace namespace = createNamespace(namespaceId);

Release release = createRelease("{\"k1\":\"v1\"}");
List<Item> items = Arrays.asList(createItem("k1", "v2"));
List<Item> items = Collections.singletonList(createItem("k1", "v2"));

when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(items);
Expand All @@ -88,7 +88,7 @@ public void testNamespaceDeleteItem() {
Namespace namespace = createNamespace(namespaceId);

Release release = createRelease("{\"k1\":\"v1\"}");
List<Item> items = Arrays.asList(createItem("k2", "v2"));
List<Item> items = Collections.singletonList(createItem("k2", "v2"));

when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(items);
Expand All @@ -106,7 +106,7 @@ public void testChildNamespaceModified() {
Namespace parentNamespace = createNamespace(parentNamespaceId);

Release childRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
List<Item> childItems = Arrays.asList(createItem("k1", "v3"));
List<Item> childItems = Collections.singletonList(createItem("k1", "v3"));
Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");

when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
Expand All @@ -126,7 +126,7 @@ public void testChildNamespaceNotModified() {
Namespace parentNamespace = createNamespace(parentNamespaceId);

Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
List<Item> childItems = Arrays.asList(createItem("k1", "v3"));
List<Item> childItems = Collections.singletonList(createItem("k1", "v3"));
Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");

when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.web.client.HttpClientErrorException;

import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

public class ClusterControllerTest extends AbstractControllerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testDeleteNotExists() {

@Test
public void testFindEmpty() {
when(appService.findAll(any(Pageable.class))).thenReturn(new ArrayList<App>());
when(appService.findAll(any(Pageable.class))).thenReturn(new ArrayList<>());
Pageable pageable = PageRequest.of(0, 10);
List<AppDTO> appDTOs = appController.find(null, pageable);
Assert.assertNotNull(appDTOs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public void testReleaseBuild() {

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.add("name", "someReleaseName");
parameters.add("comment", "someComment");
parameters.add("operator", "test");
HttpEntity<MultiValueMap<String, String>> entity =
new HttpEntity<MultiValueMap<String, String>>(parameters, headers);
new HttpEntity<>(parameters, headers);
ResponseEntity<ReleaseDTO> response = restTemplate.postForEntity(
"http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName()
+ "/namespaces/" + namespace.getNamespaceName() + "/releases",
Expand All @@ -85,7 +85,7 @@ public void testReleaseBuild() {
Assert.assertEquals("default", release.getClusterName());
Assert.assertEquals("application", release.getNamespaceName());

Map<String, String> configurations = new HashMap<String, String>();
Map<String, String> configurations = new HashMap<>();
configurations.put("k1", "v1");
configurations.put("k2", "v2");
configurations.put("k3", "v3");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ReleaseMessageScanner() {
public void afterPropertiesSet() throws Exception {
databaseScanInterval = bizConfig.releaseMessageScanIntervalInMilli();
maxIdScanned = loadLargestMessageId();
executorService.scheduleWithFixedDelay((Runnable) () -> {
executorService.scheduleWithFixedDelay(() -> {
Transaction transaction = Tracer.newTransaction("Apollo.ReleaseMessageScanner", "scanMessage");
try {
scanMessages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.springframework.core.env.Environment;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.concurrent.TimeUnit;
Expand Down
43 changes: 22 additions & 21 deletions apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface Config {
* @param defaultValue the default value when key is not found or any error occurred
* @return the property value
*/
public String getProperty(String key, String defaultValue);
String getProperty(String key, String defaultValue);

/**
* Return the integer property value with the given key, or {@code defaultValue} if the key
Expand All @@ -28,7 +28,7 @@ public interface Config {
* @param defaultValue the default value when key is not found or any error occurred
* @return the property value as integer
*/
public Integer getIntProperty(String key, Integer defaultValue);
Integer getIntProperty(String key, Integer defaultValue);

/**
* Return the long property value with the given key, or {@code defaultValue} if the key doesn't
Expand All @@ -38,7 +38,7 @@ public interface Config {
* @param defaultValue the default value when key is not found or any error occurred
* @return the property value as long
*/
public Long getLongProperty(String key, Long defaultValue);
Long getLongProperty(String key, Long defaultValue);

/**
* Return the short property value with the given key, or {@code defaultValue} if the key doesn't
Expand All @@ -48,7 +48,7 @@ public interface Config {
* @param defaultValue the default value when key is not found or any error occurred
* @return the property value as short
*/
public Short getShortProperty(String key, Short defaultValue);
Short getShortProperty(String key, Short defaultValue);

/**
* Return the float property value with the given key, or {@code defaultValue} if the key doesn't
Expand All @@ -58,7 +58,7 @@ public interface Config {
* @param defaultValue the default value when key is not found or any error occurred
* @return the property value as float
*/
public Float getFloatProperty(String key, Float defaultValue);
Float getFloatProperty(String key, Float defaultValue);

/**
* Return the double property value with the given key, or {@code defaultValue} if the key doesn't
Expand All @@ -68,7 +68,7 @@ public interface Config {
* @param defaultValue the default value when key is not found or any error occurred
* @return the property value as double
*/
public Double getDoubleProperty(String key, Double defaultValue);
Double getDoubleProperty(String key, Double defaultValue);

/**
* Return the byte property value with the given key, or {@code defaultValue} if the key doesn't
Expand All @@ -78,7 +78,7 @@ public interface Config {
* @param defaultValue the default value when key is not found or any error occurred
* @return the property value as byte
*/
public Byte getByteProperty(String key, Byte defaultValue);
Byte getByteProperty(String key, Byte defaultValue);

/**
* Return the boolean property value with the given key, or {@code defaultValue} if the key
Expand All @@ -88,7 +88,7 @@ public interface Config {
* @param defaultValue the default value when key is not found or any error occurred
* @return the property value as boolean
*/
public Boolean getBooleanProperty(String key, Boolean defaultValue);
Boolean getBooleanProperty(String key, Boolean defaultValue);

/**
* Return the array property value with the given key, or {@code defaultValue} if the key doesn't exist.
Expand All @@ -97,7 +97,7 @@ public interface Config {
* @param delimiter the delimiter regex
* @param defaultValue the default value when key is not found or any error occurred
*/
public String[] getArrayProperty(String key, String delimiter, String[] defaultValue);
String[] getArrayProperty(String key, String delimiter, String[] defaultValue);

/**
* Return the Date property value with the given name, or {@code defaultValue} if the name doesn't exist.
Expand All @@ -108,7 +108,7 @@ public interface Config {
* @param defaultValue the default value when name is not found or any error occurred
* @return the property value
*/
public Date getDateProperty(String key, Date defaultValue);
Date getDateProperty(String key, Date defaultValue);

/**
* Return the Date property value with the given name, or {@code defaultValue} if the name doesn't exist.
Expand All @@ -120,7 +120,7 @@ public interface Config {
* @param defaultValue the default value when name is not found or any error occurred
* @return the property value
*/
public Date getDateProperty(String key, String format, Date defaultValue);
Date getDateProperty(String key, String format, Date defaultValue);

/**
* Return the Date property value with the given name, or {@code defaultValue} if the name doesn't exist.
Expand All @@ -132,7 +132,7 @@ public interface Config {
* @param defaultValue the default value when name is not found or any error occurred
* @return the property value
*/
public Date getDateProperty(String key, String format, Locale locale, Date defaultValue);
Date getDateProperty(String key, String format, Locale locale, Date defaultValue);

/**
* Return the Enum property value with the given key, or {@code defaultValue} if the key doesn't exist.
Expand All @@ -143,7 +143,7 @@ public interface Config {
* @param <T> the enum
* @return the property value
*/
public <T extends Enum<T>> T getEnumProperty(String key, Class<T> enumType, T defaultValue);
<T extends Enum<T>> T getEnumProperty(String key, Class<T> enumType, T defaultValue);

/**
* Return the duration property value(in milliseconds) with the given name, or {@code
Expand All @@ -162,14 +162,14 @@ public interface Config {
* @param defaultValue the default value when name is not found or any error occurred
* @return the parsed property value(in milliseconds)
*/
public long getDurationProperty(String key, long defaultValue);
long getDurationProperty(String key, long defaultValue);

/**
* Add change listener to this config instance, will be notified when any key is changed in this namespace.
*
* @param listener the config change listener
*/
public void addChangeListener(ConfigChangeListener listener);
void addChangeListener(ConfigChangeListener listener);

/**
* Add change listener to this config instance, will only be notified when any of the interested keys is changed in this namespace.
Expand All @@ -179,7 +179,7 @@ public interface Config {
*
* @since 1.0.0
*/
public void addChangeListener(ConfigChangeListener listener, Set<String> interestedKeys);
void addChangeListener(ConfigChangeListener listener, Set<String> interestedKeys);

/**
* Add change listener to this config instance, will only be notified when any of the interested keys is changed in this namespace.
Expand All @@ -194,7 +194,8 @@ public interface Config {
*
* @since 1.3.0
*/
public void addChangeListener(ConfigChangeListener listener, Set<String> interestedKeys, Set<String> interestedKeyPrefixes);
void addChangeListener(ConfigChangeListener listener, Set<String> interestedKeys,
Set<String> interestedKeyPrefixes);

/**
* Remove the change listener
Expand All @@ -204,14 +205,14 @@ public interface Config {
*
* @since 1.1.0
*/
public boolean removeChangeListener(ConfigChangeListener listener);
boolean removeChangeListener(ConfigChangeListener listener);

/**
* Return a set of the property names
*
* @return the property names
*/
public Set<String> getPropertyNames();
Set<String> getPropertyNames();

/**
* Return the user-defined property value with the given key, or {@code defaultValue} if the key doesn't exist.
Expand All @@ -224,7 +225,7 @@ public interface Config {
*
* @since 1.1.0
*/
public <T> T getProperty(String key, Function<String, T> function, T defaultValue);
<T> T getProperty(String key, Function<String, T> function, T defaultValue);

/**
* Return the config's source type, i.e. where is the config loaded from
Expand All @@ -233,5 +234,5 @@ public interface Config {
*
* @since 1.1.0
*/
public ConfigSourceType getSourceType();
ConfigSourceType getSourceType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public interface ConfigChangeListener {
* Invoked when there is any config change for the namespace.
* @param changeEvent the event for this change
*/
public void onChange(ConfigChangeEvent changeEvent);
void onChange(ConfigChangeEvent changeEvent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public interface ConfigFile {
* @param listener the specific config change listener to remove
* @return true if the specific config change listener is found and removed
*/
public boolean removeChangeListener(ConfigFileChangeListener listener);
boolean removeChangeListener(ConfigFileChangeListener listener);

/**
* Return the config's source type, i.e. where is the config loaded from
*
* @return the config's source type
*/
public ConfigSourceType getSourceType();
ConfigSourceType getSourceType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public interface ConfigManager {
* @param namespace the namespace
* @return the config instance for the namespace
*/
public Config getConfig(String namespace);
Config getConfig(String namespace);

/**
* Get the config file instance for the namespace specified.
* @param namespace the namespace
* @param configFileFormat the config file format
* @return the config file instance for the namespace
*/
public ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat);
ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ public interface ConfigRepository {
* Get the config from this repository.
* @return config
*/
public Properties getConfig();
Properties getConfig();

/**
* Set the fallback repo for this repository.
* @param upstreamConfigRepository the upstream repo
*/
public void setUpstreamRepository(ConfigRepository upstreamConfigRepository);
void setUpstreamRepository(ConfigRepository upstreamConfigRepository);

/**
* Add change listener.
* @param listener the listener to observe the changes
*/
public void addChangeListener(RepositoryChangeListener listener);
void addChangeListener(RepositoryChangeListener listener);

/**
* Remove change listener.
* @param listener the listener to remove
*/
public void removeChangeListener(RepositoryChangeListener listener);
void removeChangeListener(RepositoryChangeListener listener);

/**
* Return the config's source type, i.e. where is the config loaded from
*
* @return the config's source type
*/
public ConfigSourceType getSourceType();
ConfigSourceType getSourceType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public interface RepositoryChangeListener {
* @param namespace the namespace of this repository change
* @param newProperties the properties after change
*/
public void onRepositoryChange(String namespace, Properties newProperties);
void onRepositoryChange(String namespace, Properties newProperties);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public interface ConfigFactory {
* @param namespace the namespace
* @return the newly created config instance
*/
public Config create(String namespace);
Config create(String namespace);

/**
* Create the config file instance for the namespace
* @param namespace the namespace
* @return the newly created config file instance
*/
public ConfigFile createConfigFile(String namespace, ConfigFileFormat configFileFormat);
ConfigFile createConfigFile(String namespace, ConfigFileFormat configFileFormat);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public interface ConfigFactoryManager {
* @param namespace the namespace
* @return the config factory for this namespace
*/
public ConfigFactory getFactory(String namespace);
ConfigFactory getFactory(String namespace);
}
Loading

0 comments on commit e321a8e

Please sign in to comment.