Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump client springboot version #4189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
run: mvn -B clean package -P travis jacoco:report -Dmaven.gitcommitid.skip=true
- name: JDK 11
if: matrix.jdk == '11'
run: mvn clean compile -Dmaven.gitcommitid.skip=true
run: mvn -B clean compile -Dmaven.gitcommitid.skip=true
- name: JDK 17
if: matrix.jdk == '17'
run: mvn clean compile -Dmaven.gitcommitid.skip=true
run: mvn -B clean compile -Dmaven.gitcommitid.skip=true
- name: Upload coverage to Codecov
if: matrix.jdk == '8'
uses: codecov/codecov-action@v1
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Apollo 2.0.0
* [Fix the NPE occurred when using EnableApolloConfig with Spring 3.1.1](https://github.com/apolloconfig/apollo/pull/4180)
* [Bump guava from 29.0 to 31.0.1](https://github.com/apolloconfig/apollo/pull/4182)
* [fix the json number display issue when it's longer than 16](https://github.com/apolloconfig/apollo/pull/4183)
* [Bump client springboot version](https://github.com/apolloconfig/apollo/pull/4189)

------------------
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1)
13 changes: 0 additions & 13 deletions apollo-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@
<properties>
<github.path>${project.artifactId}</github.path>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring Boot 2 requires Java 8, so we need to manually stick to 1.5.x version in order to compile apollo-client against Java 7 -->
<!-- This is only for apollo-client compilation use, because optional Spring dependencies are not transitive -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.16.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- apollo -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@

import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.util.factory.PropertiesFactory;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.parser.ParserException;

import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.yaml.snakeyaml.representer.Representer;

/**
* Transplanted from org.springframework.beans.factory.config.YamlProcessor since apollo can't depend on Spring directly
Expand Down Expand Up @@ -64,7 +65,9 @@ public void process(Properties properties, Map<String, Object> map) {
* Create the {@link Yaml} instance to use.
*/
private Yaml createYaml() {
return new Yaml(new StrictMapAppenderConstructor());
LoaderOptions loadingConfig = new LoaderOptions();
loadingConfig.setAllowDuplicateKeys(false);
return new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), loadingConfig);
}

private boolean process(MatchCallback callback, Yaml yaml, String content) {
Expand Down Expand Up @@ -163,43 +166,4 @@ private interface MatchCallback {
void process(Properties properties, Map<String, Object> map);
}

/**
* A specialized {@link SafeConstructor} that checks for duplicate keys.
*/
private static class StrictMapAppenderConstructor extends SafeConstructor {

// Declared as public for use in subclasses
StrictMapAppenderConstructor() {
super();
}

@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
try {
return super.constructMapping(node);
} catch (IllegalStateException ex) {
throw new ParserException("while parsing MappingNode", node.getStartMark(), ex.getMessage(), node.getEndMark());
}
}

@Override
hezhangjian marked this conversation as resolved.
Show resolved Hide resolved
protected Map<Object, Object> createDefaultMap() {
final Map<Object, Object> delegate = super.createDefaultMap();
return new AbstractMap<Object, Object>() {
@Override
public Object put(Object key, Object value) {
if (delegate.containsKey(key)) {
throw new IllegalStateException("Duplicate key: " + key);
}
return delegate.put(key, value);
}

@Override
public Set<Entry<Object, Object>> entrySet() {
return delegate.entrySet();
}
};
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
Expand Down Expand Up @@ -119,7 +120,7 @@ public HttpResponse<List<ApolloConfigNotification>> answer(InvocationOnMock invo
TimeUnit.MILLISECONDS.sleep(50);
} catch (InterruptedException e) {
}
HttpRequest request = invocation.getArgumentAt(0, HttpRequest.class);
HttpRequest request = invocation.getArgument(0, HttpRequest.class);

assertTrue(request.getUrl().contains(someServerUrl + "/notifications/v2?"));
assertTrue(request.getUrl().contains("appId=" + someAppId));
Expand Down Expand Up @@ -225,7 +226,7 @@ public HttpResponse<List<ApolloConfigNotification>> answer(InvocationOnMock invo
} catch (InterruptedException e) {
}

HttpRequest request = invocation.getArgumentAt(0, HttpRequest.class);
HttpRequest request = invocation.getArgument(0, HttpRequest.class);

Map<String, String> headers = request.getHeaders();
assertNotNull(headers);
Expand Down Expand Up @@ -281,7 +282,7 @@ public HttpResponse<List<ApolloConfigNotification>> answer(InvocationOnMock invo

//the first time
if (counter.incrementAndGet() == 1) {
HttpRequest request = invocation.getArgumentAt(0, HttpRequest.class);
HttpRequest request = invocation.getArgument(0, HttpRequest.class);

assertTrue(request.getUrl().contains("notifications="));
assertTrue(request.getUrl().contains(someNamespace));
Expand All @@ -291,7 +292,7 @@ public HttpResponse<List<ApolloConfigNotification>> answer(InvocationOnMock invo
when(pollResponse.getStatusCode()).thenReturn(HttpServletResponse.SC_OK);
when(pollResponse.getBody()).thenReturn(Lists.newArrayList(someNotification));
} else if (submitAnotherNamespaceFinish.get()) {
HttpRequest request = invocation.getArgumentAt(0, HttpRequest.class);
HttpRequest request = invocation.getArgument(0, HttpRequest.class);
assertTrue(request.getUrl().contains("notifications="));
assertTrue(request.getUrl().contains(someNamespace));
assertTrue(request.getUrl().contains(anotherNamespace));
Expand All @@ -314,7 +315,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
onAnotherRepositoryNotified.set(true);
return null;
}
}).when(anotherRepository).onLongPollNotified(any(ServiceDTO.class), any(ApolloNotificationMessages.class));
}).when(anotherRepository).onLongPollNotified(Mockito.any(ServiceDTO.class), Mockito.nullable(ApolloNotificationMessages.class));

remoteConfigLongPollService.submit(someNamespace, someRepository);

Expand All @@ -326,8 +327,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {

remoteConfigLongPollService.stopLongPollingRefresh();

verify(someRepository, times(1)).onLongPollNotified(any(ServiceDTO.class), any(ApolloNotificationMessages.class));
verify(anotherRepository, times(1)).onLongPollNotified(any(ServiceDTO.class), any(ApolloNotificationMessages.class));
verify(someRepository, times(1)).onLongPollNotified(Mockito.any(ServiceDTO.class), Mockito.nullable(ApolloNotificationMessages.class));
verify(anotherRepository, times(1)).onLongPollNotified(Mockito.any(ServiceDTO.class), Mockito.nullable(ApolloNotificationMessages.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void testLoadConfigWithAccessKeySecret() throws Exception {
doAnswer(new Answer<HttpResponse<ApolloConfig>>() {
@Override
public HttpResponse<ApolloConfig> answer(InvocationOnMock invocation) throws Throwable {
HttpRequest request = invocation.getArgumentAt(0, HttpRequest.class);
HttpRequest request = invocation.getArgument(0, HttpRequest.class);
Map<String, String> headers = request.getHeaders();
assertNotNull(headers);
assertTrue(headers.containsKey(Signature.HTTP_HEADER_TIMESTAMP));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand Down Expand Up @@ -86,8 +87,8 @@ public static void beforeClass() throws Exception {

when(mockedConfig.getPropertyNames()).thenReturn(Sets.newHashSet(TEST_BEAN_CONDITIONAL_ON_KEY, someProperty));

when(mockedConfig.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), anyString())).thenReturn(Boolean.TRUE.toString());
when(mockedConfig.getProperty(eq(someProperty), anyString())).thenReturn(someValue);
when(mockedConfig.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), Mockito.nullable(String.class))).thenReturn(Boolean.TRUE.toString());
when(mockedConfig.getProperty(eq(someProperty), Mockito.nullable(String.class))).thenReturn(someValue);

mockConfig(ConfigConsts.NAMESPACE_APPLICATION, mockedConfig);
}
Expand Down Expand Up @@ -131,7 +132,7 @@ public static void beforeClass() throws Exception {
Config anotherConfig = mock(Config.class);

when(config.getPropertyNames()).thenReturn(Sets.newHashSet(TEST_BEAN_CONDITIONAL_ON_KEY));
when(config.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), anyString())).thenReturn(Boolean.TRUE.toString());
when(config.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), Mockito.nullable(String.class))).thenReturn(Boolean.TRUE.toString());

mockConfig(ConfigConsts.NAMESPACE_APPLICATION, anotherConfig);
mockConfig(FX_APOLLO_NAMESPACE, config);
Expand Down Expand Up @@ -209,7 +210,7 @@ public static void beforeClass() throws Exception {
Config config = mock(Config.class);

when(config.getPropertyNames()).thenReturn(Sets.newHashSet(TEST_BEAN_CONDITIONAL_ON_KEY));
when(config.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), anyString())).thenReturn(Boolean.FALSE.toString());
when(config.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), Mockito.nullable(String.class))).thenReturn(Boolean.FALSE.toString());

mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config);
}
Expand Down Expand Up @@ -344,7 +345,7 @@ public static void beforeClass() throws Exception {
Config config = mock(Config.class);

when(config.getPropertyNames()).thenReturn(Sets.newHashSet(TEST_BEAN_CONDITIONAL_ON_KEY));
when(config.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), anyString())).thenReturn(Boolean.FALSE.toString());
when(config.getProperty(eq(TEST_BEAN_CONDITIONAL_ON_KEY), Mockito.nullable(String.class))).thenReturn(Boolean.FALSE.toString());

mockConfig(ConfigConsts.NAMESPACE_APPLICATION, config);
}
Expand Down Expand Up @@ -420,10 +421,10 @@ public static void afterClass() {

@Test
public void test() {
List<EnvironmentPostProcessor> processorList = SpringFactoriesLoader.loadFactories(EnvironmentPostProcessor.class, getClass().getClassLoader());
List<String> names = SpringFactoriesLoader.loadFactoryNames(EnvironmentPostProcessor.class, getClass().getClassLoader());
hezhangjian marked this conversation as resolved.
Show resolved Hide resolved
boolean containsApollo = false;
for (EnvironmentPostProcessor postProcessor : processorList) {
if (postProcessor instanceof ApolloApplicationContextInitializer) {
for (String name : names) {
if (name.equals("com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer")) {
containsApollo = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.junit.After;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.BeanCreationException;
Expand Down Expand Up @@ -152,15 +153,15 @@ public void testEnableApolloConfigResolveExpressionSimple() {
String someValue = UUID.randomUUID().toString();
mockConfig(ConfigConsts.NAMESPACE_APPLICATION, mock(Config.class));
Config xxxConfig = mock(Config.class);
when(xxxConfig.getProperty(eq(someKey), anyString())).thenReturn(someValue);
when(xxxConfig.getProperty(eq(someKey), Mockito.nullable(String.class))).thenReturn(someValue);
mockConfig("xxx", xxxConfig);

TestEnableApolloConfigResolveExpressionWithDefaultValueConfiguration configuration =
getSimpleBean(TestEnableApolloConfigResolveExpressionWithDefaultValueConfiguration.class);

// check
assertEquals(someValue, configuration.getSomeKey());
verify(xxxConfig, times(1)).getProperty(eq(someKey), anyString());
verify(xxxConfig, times(1)).getProperty(eq(someKey), Mockito.nullable(String.class));
}

@Test
Expand All @@ -173,15 +174,15 @@ public void testEnableApolloConfigResolveExpressionFromSystemProperty() {
System.setProperty(SystemPropertyKeyConstants.SIMPLE_NAMESPACE, resolvedNamespaceName);

Config yyyConfig = mock(Config.class);
when(yyyConfig.getProperty(eq(someKey), anyString())).thenReturn(someValue);
when(yyyConfig.getProperty(eq(someKey), Mockito.nullable(String.class))).thenReturn(someValue);
mockConfig(resolvedNamespaceName, yyyConfig);

TestEnableApolloConfigResolveExpressionWithDefaultValueConfiguration configuration =
getSimpleBean(TestEnableApolloConfigResolveExpressionWithDefaultValueConfiguration.class);

// check
assertEquals(someValue, configuration.getSomeKey());
verify(yyyConfig, times(1)).getProperty(eq(someKey), anyString());
verify(yyyConfig, times(1)).getProperty(eq(someKey), Mockito.nullable(String.class));
}

@Test(expected = BeanCreationException.class)
Expand Down Expand Up @@ -210,7 +211,7 @@ public void testApolloConfigChangeListener() throws Exception {
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
applicationListeners.add(invocation.getArgumentAt(0, ConfigChangeListener.class));
applicationListeners.add(invocation.getArgument(0, ConfigChangeListener.class));

return Void.class;
}
Expand All @@ -219,7 +220,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
fxApolloListeners.add(invocation.getArgumentAt(0, ConfigChangeListener.class));
fxApolloListeners.add(invocation.getArgument(0, ConfigChangeListener.class));

return Void.class;
}
Expand Down Expand Up @@ -283,7 +284,7 @@ public void testApolloConfigChangeListenerWithInheritance() throws Exception {
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
applicationListeners.add(invocation.getArgumentAt(0, ConfigChangeListener.class));
applicationListeners.add(invocation.getArgument(0, ConfigChangeListener.class));

return Void.class;
}
Expand All @@ -292,7 +293,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
fxApolloListeners.add(invocation.getArgumentAt(0, ConfigChangeListener.class));
fxApolloListeners.add(invocation.getArgument(0, ConfigChangeListener.class));

return Void.class;
}
Expand Down Expand Up @@ -341,10 +342,10 @@ public void testApolloConfigChangeListenerWithInterestedKeys() throws Exception
final ArgumentCaptor<Set> fxApolloConfigInterestedKeys = ArgumentCaptor.forClass(Set.class);

verify(applicationConfig, times(2))
.addChangeListener(any(ConfigChangeListener.class), applicationConfigInterestedKeys.capture(), anySetOf(String.class));
.addChangeListener(any(ConfigChangeListener.class), applicationConfigInterestedKeys.capture(), Mockito.nullable(Set.class));

verify(fxApolloConfig, times(1))
.addChangeListener(any(ConfigChangeListener.class), fxApolloConfigInterestedKeys.capture(), anySetOf(String.class));
.addChangeListener(any(ConfigChangeListener.class), fxApolloConfigInterestedKeys.capture(), Mockito.nullable(Set.class));

assertEquals(2, applicationConfigInterestedKeys.getAllValues().size());

Expand Down Expand Up @@ -372,7 +373,7 @@ public void testApolloConfigChangeListenerWithInterestedKeyPrefixes() {
.forClass(Set.class);

verify(applicationConfig, times(1))
.addChangeListener(any(ConfigChangeListener.class), anySetOf(String.class),
.addChangeListener(any(ConfigChangeListener.class), Mockito.nullable(Set.class),
interestedKeyPrefixesArgumentCaptor.capture());

assertEquals(1, interestedKeyPrefixesArgumentCaptor.getAllValues().size());
Expand Down Expand Up @@ -403,7 +404,7 @@ public void testApolloConfigChangeListenerWithInterestedKeyPrefixes_fire()
TestApolloConfigChangeListenerWithInterestedKeyPrefixesBean1.class, AppConfig11.class);

verify(simpleConfig, atLeastOnce())
.addChangeListener(any(ConfigChangeListener.class), anySetOf(String.class),
.addChangeListener(any(ConfigChangeListener.class), Mockito.nullable(Set.class),
anySetOf(String.class));

Properties properties = new Properties();
Expand Down
Loading