repo_name
stringclasses 5
values | pr_number
int64 1.52k
15.5k
| pr_title
stringlengths 8
143
| pr_description
stringlengths 0
10.2k
| author
stringlengths 3
18
| date_created
timestamp[ns, tz=UTC] | date_merged
timestamp[ns, tz=UTC] | previous_commit
stringlengths 40
40
| pr_commit
stringlengths 40
40
| query
stringlengths 11
10.2k
| filepath
stringlengths 6
220
| before_content
stringlengths 0
597M
| after_content
stringlengths 0
597M
| label
int64 -1
1
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/SpringBootSampleApplication.java | package com.ctrip.framework.apollo.demo.spring.springBootDemo;
import com.ctrip.framework.apollo.demo.spring.springBootDemo.config.SampleRedisConfig;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;
import com.ctrip.framework.apollo.demo.spring.common.bean.AnnotatedBean;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
/**
* @author Jason Song([email protected])
*/
@SpringBootApplication(scanBasePackages = {"com.ctrip.framework.apollo.demo.spring.common",
"com.ctrip.framework.apollo.demo.spring.springBootDemo"
})
public class SpringBootSampleApplication {
public static void main(String[] args) throws IOException {
ApplicationContext context = new SpringApplicationBuilder(SpringBootSampleApplication.class).run(args);
AnnotatedBean annotatedBean = context.getBean(AnnotatedBean.class);
SampleRedisConfig redisConfig = null;
try {
redisConfig = context.getBean(SampleRedisConfig.class);
} catch (NoSuchBeanDefinitionException ex) {
System.out.println("SampleRedisConfig is null, 'redis.cache.enabled' must have been set to false.");
}
System.out.println("SpringBootSampleApplication Demo. Input any key except quit to print the values. Input quit to exit.");
while (true) {
System.out.print("> ");
String input = new BufferedReader(new InputStreamReader(System.in, Charsets.UTF_8)).readLine();
if (!Strings.isNullOrEmpty(input) && input.trim().equalsIgnoreCase("quit")) {
System.exit(0);
}
System.out.println(annotatedBean.toString());
if (redisConfig != null) {
System.out.println(redisConfig.toString());
}
}
}
}
| package com.ctrip.framework.apollo.demo.spring.springBootDemo;
import com.ctrip.framework.apollo.demo.spring.springBootDemo.config.SampleRedisConfig;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;
import com.ctrip.framework.apollo.demo.spring.common.bean.AnnotatedBean;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
/**
* @author Jason Song([email protected])
*/
@SpringBootApplication(scanBasePackages = {"com.ctrip.framework.apollo.demo.spring.common",
"com.ctrip.framework.apollo.demo.spring.springBootDemo"
})
public class SpringBootSampleApplication {
public static void main(String[] args) throws IOException {
ApplicationContext context = new SpringApplicationBuilder(SpringBootSampleApplication.class).run(args);
AnnotatedBean annotatedBean = context.getBean(AnnotatedBean.class);
SampleRedisConfig redisConfig = null;
try {
redisConfig = context.getBean(SampleRedisConfig.class);
} catch (NoSuchBeanDefinitionException ex) {
System.out.println("SampleRedisConfig is null, 'redis.cache.enabled' must have been set to false.");
}
System.out.println("SpringBootSampleApplication Demo. Input any key except quit to print the values. Input quit to exit.");
while (true) {
System.out.print("> ");
String input = new BufferedReader(new InputStreamReader(System.in, Charsets.UTF_8)).readLine();
if (!Strings.isNullOrEmpty(input) && input.trim().equalsIgnoreCase("quit")) {
System.exit(0);
}
System.out.println(annotatedBean.toString());
if (redisConfig != null) {
System.out.println(redisConfig.toString());
}
}
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/RetryableRestTemplateTest.java | package com.ctrip.framework.apollo.portal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
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.common.exception.ServiceException;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.portal.component.AdminServiceAddressLocator;
import com.ctrip.framework.apollo.portal.component.RetryableRestTemplate;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.environment.PortalMetaDomainService;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import java.net.SocketTimeoutException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpHost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
public class RetryableRestTemplateTest extends AbstractUnitTest {
@Mock
private AdminServiceAddressLocator serviceAddressLocator;
@Mock
private RestTemplate restTemplate;
@Mock
private PortalMetaDomainService portalMetaDomainService;
@Mock
private PortalConfig portalConfig;
@InjectMocks
private RetryableRestTemplate retryableRestTemplate;
private static final Gson GSON = new Gson();
private String path = "app";
private String serviceOne = "http://10.0.0.1";
private String serviceTwo = "http://10.0.0.2";
private String serviceThree = "http://10.0.0.3";
private ResourceAccessException socketTimeoutException = new ResourceAccessException("");
private ResourceAccessException httpHostConnectException = new ResourceAccessException("");
private ResourceAccessException connectTimeoutException = new ResourceAccessException("");
private Object request = new Object();
private Object result = new Object();
private Class<?> requestType = request.getClass();
@Before
public void init() {
socketTimeoutException.initCause(new SocketTimeoutException());
httpHostConnectException
.initCause(new HttpHostConnectException(new ConnectTimeoutException(),
new HttpHost(serviceOne, 80)));
connectTimeoutException.initCause(new ConnectTimeoutException());
}
@Test(expected = ServiceException.class)
public void testNoAdminServer() {
when(serviceAddressLocator.getServiceList(any())).thenReturn(Collections.emptyList());
retryableRestTemplate.get(Env.DEV, path, Object.class);
}
@Test(expected = ServiceException.class)
public void testAllServerDown() {
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(socketTimeoutException);
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(httpHostConnectException);
when(restTemplate
.exchange(eq(serviceThree + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(connectTimeoutException);
retryableRestTemplate.get(Env.DEV, path, Object.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, times(1))
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, times(1))
.exchange(eq(serviceThree + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
}
@Test
public void testOneServerDown() {
ResponseEntity someEntity = mock(ResponseEntity.class);
when(someEntity.getBody()).thenReturn(result);
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(socketTimeoutException);
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenReturn(someEntity);
when(restTemplate
.exchange(eq(serviceThree + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(connectTimeoutException);
Object actualResult = retryableRestTemplate.get(Env.DEV, path, Object.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, times(1))
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, never())
.exchange(eq(serviceThree + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
assertEquals(result, actualResult);
}
@Test
public void testPostSocketTimeoutNotRetry() {
ResponseEntity someEntity = mock(ResponseEntity.class);
when(someEntity.getBody()).thenReturn(result);
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class))).thenThrow(socketTimeoutException);
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class))).thenReturn(someEntity);
Throwable exception = null;
Object actualResult = null;
try {
actualResult = retryableRestTemplate.post(Env.DEV, path, request, Object.class);
} catch (Throwable ex) {
exception = ex;
}
assertNull(actualResult);
assertSame(socketTimeoutException, exception);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, never())
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class));
}
@Test
public void testDelete() {
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.DELETE), any(HttpEntity.class),
(Class<Object>) isNull())).thenReturn(someEntity);
retryableRestTemplate.delete(Env.DEV, path);
verify(restTemplate)
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.DELETE), any(HttpEntity.class),
(Class<Object>) isNull());
}
@Test
public void testPut() {
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.PUT), any(HttpEntity.class),
(Class<Object>) isNull())).thenReturn(someEntity);
retryableRestTemplate.put(Env.DEV, path, request);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate)
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.PUT), argumentCaptor.capture(),
(Class<Object>) isNull());
assertEquals(request, argumentCaptor.getValue().getBody());
}
@Test
public void testPostObjectWithNoAccessToken() {
Env someEnv = Env.DEV;
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(someEnv, path, request, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
HttpHeaders headers = entity.getHeaders();
assertSame(request, entity.getBody());
assertTrue(headers.isEmpty());
}
@Test
public void testPostObjectWithAccessToken() {
Env someEnv = Env.DEV;
String someToken = "someToken";
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(someEnv, path, request, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
HttpHeaders headers = entity.getHeaders();
List<String> headerValue = headers.get(HttpHeaders.AUTHORIZATION);
assertSame(request, entity.getBody());
assertEquals(1, headers.size());
assertEquals(1, headerValue.size());
assertEquals(someToken, headerValue.get(0));
}
@Test
public void testPostObjectWithNoAccessTokenForEnv() {
Env someEnv = Env.DEV;
Env anotherEnv = Env.PRO;
String someToken = "someToken";
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(serviceAddressLocator.getServiceList(anotherEnv))
.thenReturn(Collections.singletonList(mockService(serviceTwo)));
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(anotherEnv, path, request, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
HttpHeaders headers = entity.getHeaders();
assertSame(request, entity.getBody());
assertTrue(headers.isEmpty());
}
@Test
public void testPostEntityWithNoAccessToken() {
Env someEnv = Env.DEV;
String originalHeader = "someHeader";
String originalValue = "someValue";
HttpHeaders originalHeaders = new HttpHeaders();
originalHeaders.add(originalHeader, originalValue);
HttpEntity<Object> requestEntity = new HttpEntity<>(request, originalHeaders);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(someEnv, path, requestEntity, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
assertSame(requestEntity, entity);
assertSame(request, entity.getBody());
assertEquals(originalHeaders, entity.getHeaders());
}
@Test
public void testPostEntityWithAccessToken() {
Env someEnv = Env.DEV;
String someToken = "someToken";
String originalHeader = "someHeader";
String originalValue = "someValue";
HttpHeaders originalHeaders = new HttpHeaders();
originalHeaders.add(originalHeader, originalValue);
HttpEntity<Object> requestEntity = new HttpEntity<>(request, originalHeaders);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(someEnv, path, requestEntity, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
HttpHeaders headers = entity.getHeaders();
assertSame(request, entity.getBody());
assertEquals(2, headers.size());
assertEquals(originalValue, headers.get(originalHeader).get(0));
assertEquals(someToken, headers.get(HttpHeaders.AUTHORIZATION).get(0));
}
@Test
public void testGetEntityWithNoAccessToken() {
Env someEnv = Env.DEV;
ParameterizedTypeReference requestType = mock(ParameterizedTypeReference.class);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
ResponseEntity actualResult = retryableRestTemplate.get(someEnv, path, requestType);
assertEquals(someEntity, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), argumentCaptor.capture(),
eq(requestType));
HttpHeaders headers = argumentCaptor.getValue().getHeaders();
assertTrue(headers.isEmpty());
}
@Test
public void testGetEntityWithAccessToken() {
Env someEnv = Env.DEV;
String someToken = "someToken";
ParameterizedTypeReference requestType = mock(ParameterizedTypeReference.class);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
ResponseEntity actualResult = retryableRestTemplate.get(someEnv, path, requestType);
assertEquals(someEntity, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), argumentCaptor.capture(),
eq(requestType));
HttpHeaders headers = argumentCaptor.getValue().getHeaders();
List<String> headerValue = headers.get(HttpHeaders.AUTHORIZATION);
assertEquals(1, headers.size());
assertEquals(1, headerValue.size());
assertEquals(someToken, headerValue.get(0));
}
@Test
public void testGetEntityWithNoAccessTokenForEnv() {
Env someEnv = Env.DEV;
Env anotherEnv = Env.PRO;
String someToken = "someToken";
ParameterizedTypeReference requestType = mock(ParameterizedTypeReference.class);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(serviceAddressLocator.getServiceList(anotherEnv))
.thenReturn(Collections.singletonList(mockService(serviceTwo)));
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
ResponseEntity actualResult = retryableRestTemplate.get(anotherEnv, path, requestType);
assertEquals(someEntity, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), argumentCaptor.capture(),
eq(requestType));
HttpHeaders headers = argumentCaptor.getValue().getHeaders();
assertTrue(headers.isEmpty());
}
private String mockAdminServiceTokens(Env env, String token) {
Map<String, String> tokenMap = Maps.newHashMap();
tokenMap.put(env.getName(), token);
return GSON.toJson(tokenMap);
}
private ServiceDTO mockService(String homeUrl) {
ServiceDTO serviceDTO = new ServiceDTO();
serviceDTO.setHomepageUrl(homeUrl);
return serviceDTO;
}
}
| package com.ctrip.framework.apollo.portal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
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.common.exception.ServiceException;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.portal.component.AdminServiceAddressLocator;
import com.ctrip.framework.apollo.portal.component.RetryableRestTemplate;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.environment.PortalMetaDomainService;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import java.net.SocketTimeoutException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpHost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
public class RetryableRestTemplateTest extends AbstractUnitTest {
@Mock
private AdminServiceAddressLocator serviceAddressLocator;
@Mock
private RestTemplate restTemplate;
@Mock
private PortalMetaDomainService portalMetaDomainService;
@Mock
private PortalConfig portalConfig;
@InjectMocks
private RetryableRestTemplate retryableRestTemplate;
private static final Gson GSON = new Gson();
private String path = "app";
private String serviceOne = "http://10.0.0.1";
private String serviceTwo = "http://10.0.0.2";
private String serviceThree = "http://10.0.0.3";
private ResourceAccessException socketTimeoutException = new ResourceAccessException("");
private ResourceAccessException httpHostConnectException = new ResourceAccessException("");
private ResourceAccessException connectTimeoutException = new ResourceAccessException("");
private Object request = new Object();
private Object result = new Object();
private Class<?> requestType = request.getClass();
@Before
public void init() {
socketTimeoutException.initCause(new SocketTimeoutException());
httpHostConnectException
.initCause(new HttpHostConnectException(new ConnectTimeoutException(),
new HttpHost(serviceOne, 80)));
connectTimeoutException.initCause(new ConnectTimeoutException());
}
@Test(expected = ServiceException.class)
public void testNoAdminServer() {
when(serviceAddressLocator.getServiceList(any())).thenReturn(Collections.emptyList());
retryableRestTemplate.get(Env.DEV, path, Object.class);
}
@Test(expected = ServiceException.class)
public void testAllServerDown() {
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(socketTimeoutException);
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(httpHostConnectException);
when(restTemplate
.exchange(eq(serviceThree + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(connectTimeoutException);
retryableRestTemplate.get(Env.DEV, path, Object.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, times(1))
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, times(1))
.exchange(eq(serviceThree + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
}
@Test
public void testOneServerDown() {
ResponseEntity someEntity = mock(ResponseEntity.class);
when(someEntity.getBody()).thenReturn(result);
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(socketTimeoutException);
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenReturn(someEntity);
when(restTemplate
.exchange(eq(serviceThree + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class))).thenThrow(connectTimeoutException);
Object actualResult = retryableRestTemplate.get(Env.DEV, path, Object.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, times(1))
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, never())
.exchange(eq(serviceThree + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(Object.class));
assertEquals(result, actualResult);
}
@Test
public void testPostSocketTimeoutNotRetry() {
ResponseEntity someEntity = mock(ResponseEntity.class);
when(someEntity.getBody()).thenReturn(result);
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class))).thenThrow(socketTimeoutException);
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class))).thenReturn(someEntity);
Throwable exception = null;
Object actualResult = null;
try {
actualResult = retryableRestTemplate.post(Env.DEV, path, request, Object.class);
} catch (Throwable ex) {
exception = ex;
}
assertNull(actualResult);
assertSame(socketTimeoutException, exception);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class));
verify(restTemplate, never())
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class));
}
@Test
public void testDelete() {
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.DELETE), any(HttpEntity.class),
(Class<Object>) isNull())).thenReturn(someEntity);
retryableRestTemplate.delete(Env.DEV, path);
verify(restTemplate)
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.DELETE), any(HttpEntity.class),
(Class<Object>) isNull());
}
@Test
public void testPut() {
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(any()))
.thenReturn(Arrays
.asList(mockService(serviceOne), mockService(serviceTwo), mockService(serviceThree)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.PUT), any(HttpEntity.class),
(Class<Object>) isNull())).thenReturn(someEntity);
retryableRestTemplate.put(Env.DEV, path, request);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate)
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.PUT), argumentCaptor.capture(),
(Class<Object>) isNull());
assertEquals(request, argumentCaptor.getValue().getBody());
}
@Test
public void testPostObjectWithNoAccessToken() {
Env someEnv = Env.DEV;
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(someEnv, path, request, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
HttpHeaders headers = entity.getHeaders();
assertSame(request, entity.getBody());
assertTrue(headers.isEmpty());
}
@Test
public void testPostObjectWithAccessToken() {
Env someEnv = Env.DEV;
String someToken = "someToken";
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(someEnv, path, request, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
HttpHeaders headers = entity.getHeaders();
List<String> headerValue = headers.get(HttpHeaders.AUTHORIZATION);
assertSame(request, entity.getBody());
assertEquals(1, headers.size());
assertEquals(1, headerValue.size());
assertEquals(someToken, headerValue.get(0));
}
@Test
public void testPostObjectWithNoAccessTokenForEnv() {
Env someEnv = Env.DEV;
Env anotherEnv = Env.PRO;
String someToken = "someToken";
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(serviceAddressLocator.getServiceList(anotherEnv))
.thenReturn(Collections.singletonList(mockService(serviceTwo)));
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(anotherEnv, path, request, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
HttpHeaders headers = entity.getHeaders();
assertSame(request, entity.getBody());
assertTrue(headers.isEmpty());
}
@Test
public void testPostEntityWithNoAccessToken() {
Env someEnv = Env.DEV;
String originalHeader = "someHeader";
String originalValue = "someValue";
HttpHeaders originalHeaders = new HttpHeaders();
originalHeaders.add(originalHeader, originalValue);
HttpEntity<Object> requestEntity = new HttpEntity<>(request, originalHeaders);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(someEnv, path, requestEntity, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
assertSame(requestEntity, entity);
assertSame(request, entity.getBody());
assertEquals(originalHeaders, entity.getHeaders());
}
@Test
public void testPostEntityWithAccessToken() {
Env someEnv = Env.DEV;
String someToken = "someToken";
String originalHeader = "someHeader";
String originalValue = "someValue";
HttpHeaders originalHeaders = new HttpHeaders();
originalHeaders.add(originalHeader, originalValue);
HttpEntity<Object> requestEntity = new HttpEntity<>(request, originalHeaders);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
when(someEntity.getBody()).thenReturn(result);
Object actualResult = retryableRestTemplate.post(someEnv, path, requestEntity, requestType);
assertEquals(result, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.POST), argumentCaptor.capture(),
eq(requestType));
HttpEntity entity = argumentCaptor.getValue();
HttpHeaders headers = entity.getHeaders();
assertSame(request, entity.getBody());
assertEquals(2, headers.size());
assertEquals(originalValue, headers.get(originalHeader).get(0));
assertEquals(someToken, headers.get(HttpHeaders.AUTHORIZATION).get(0));
}
@Test
public void testGetEntityWithNoAccessToken() {
Env someEnv = Env.DEV;
ParameterizedTypeReference requestType = mock(ParameterizedTypeReference.class);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
ResponseEntity actualResult = retryableRestTemplate.get(someEnv, path, requestType);
assertEquals(someEntity, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), argumentCaptor.capture(),
eq(requestType));
HttpHeaders headers = argumentCaptor.getValue().getHeaders();
assertTrue(headers.isEmpty());
}
@Test
public void testGetEntityWithAccessToken() {
Env someEnv = Env.DEV;
String someToken = "someToken";
ParameterizedTypeReference requestType = mock(ParameterizedTypeReference.class);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(restTemplate
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
ResponseEntity actualResult = retryableRestTemplate.get(someEnv, path, requestType);
assertEquals(someEntity, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceOne + "/" + path), eq(HttpMethod.GET), argumentCaptor.capture(),
eq(requestType));
HttpHeaders headers = argumentCaptor.getValue().getHeaders();
List<String> headerValue = headers.get(HttpHeaders.AUTHORIZATION);
assertEquals(1, headers.size());
assertEquals(1, headerValue.size());
assertEquals(someToken, headerValue.get(0));
}
@Test
public void testGetEntityWithNoAccessTokenForEnv() {
Env someEnv = Env.DEV;
Env anotherEnv = Env.PRO;
String someToken = "someToken";
ParameterizedTypeReference requestType = mock(ParameterizedTypeReference.class);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens())
.thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv))
.thenReturn(Collections.singletonList(mockService(serviceOne)));
when(serviceAddressLocator.getServiceList(anotherEnv))
.thenReturn(Collections.singletonList(mockService(serviceTwo)));
when(restTemplate
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class),
eq(requestType))).thenReturn(someEntity);
ResponseEntity actualResult = retryableRestTemplate.get(anotherEnv, path, requestType);
assertEquals(someEntity, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1))
.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), argumentCaptor.capture(),
eq(requestType));
HttpHeaders headers = argumentCaptor.getValue().getHeaders();
assertTrue(headers.isEmpty());
}
private String mockAdminServiceTokens(Env env, String token) {
Map<String, String> tokenMap = Maps.newHashMap();
tokenMap.put(env.getName(), token);
return GSON.toJson(tokenMap);
}
private ServiceDTO mockService(String homeUrl) {
ServiceDTO serviceDTO = new ServiceDTO();
serviceDTO.setHomepageUrl(homeUrl);
return serviceDTO;
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-core/src/main/java/com/ctrip/framework/apollo/tracer/internals/cat/CatTransaction.java | package com.ctrip.framework.apollo.tracer.internals.cat;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import java.lang.reflect.Method;
/**
* @author Jason Song([email protected])
*/
public class CatTransaction implements Transaction {
private static Class CAT_TRANSACTION_CLASS;
private static Method SET_STATUS_WITH_STRING;
private static Method SET_STATUS_WITH_THROWABLE;
private static Method ADD_DATA_WITH_KEY_AND_VALUE;
private static Method COMPLETE;
private Object catTransaction;
static {
try {
CAT_TRANSACTION_CLASS = Class.forName(CatNames.CAT_TRANSACTION_CLASS);
SET_STATUS_WITH_STRING = CAT_TRANSACTION_CLASS.getMethod(CatNames.SET_STATUS_METHOD, String.class);
SET_STATUS_WITH_THROWABLE = CAT_TRANSACTION_CLASS.getMethod(CatNames.SET_STATUS_METHOD,
Throwable.class);
ADD_DATA_WITH_KEY_AND_VALUE = CAT_TRANSACTION_CLASS.getMethod(CatNames.ADD_DATA_METHOD,
String.class, Object.class);
COMPLETE = CAT_TRANSACTION_CLASS.getMethod(CatNames.COMPLETE_METHOD);
} catch (Throwable ex) {
throw new IllegalStateException("Initialize Cat transaction failed", ex);
}
}
static void init() {
//do nothing, just to initialize the static variables
}
public CatTransaction(Object catTransaction) {
this.catTransaction = catTransaction;
}
@Override
public void setStatus(String status) {
try {
SET_STATUS_WITH_STRING.invoke(catTransaction, status);
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
@Override
public void setStatus(Throwable status) {
try {
SET_STATUS_WITH_THROWABLE.invoke(catTransaction, status);
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
@Override
public void addData(String key, Object value) {
try {
ADD_DATA_WITH_KEY_AND_VALUE.invoke(catTransaction, key, value);
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
@Override
public void complete() {
try {
COMPLETE.invoke(catTransaction);
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
}
| package com.ctrip.framework.apollo.tracer.internals.cat;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import java.lang.reflect.Method;
/**
* @author Jason Song([email protected])
*/
public class CatTransaction implements Transaction {
private static Class CAT_TRANSACTION_CLASS;
private static Method SET_STATUS_WITH_STRING;
private static Method SET_STATUS_WITH_THROWABLE;
private static Method ADD_DATA_WITH_KEY_AND_VALUE;
private static Method COMPLETE;
private Object catTransaction;
static {
try {
CAT_TRANSACTION_CLASS = Class.forName(CatNames.CAT_TRANSACTION_CLASS);
SET_STATUS_WITH_STRING = CAT_TRANSACTION_CLASS.getMethod(CatNames.SET_STATUS_METHOD, String.class);
SET_STATUS_WITH_THROWABLE = CAT_TRANSACTION_CLASS.getMethod(CatNames.SET_STATUS_METHOD,
Throwable.class);
ADD_DATA_WITH_KEY_AND_VALUE = CAT_TRANSACTION_CLASS.getMethod(CatNames.ADD_DATA_METHOD,
String.class, Object.class);
COMPLETE = CAT_TRANSACTION_CLASS.getMethod(CatNames.COMPLETE_METHOD);
} catch (Throwable ex) {
throw new IllegalStateException("Initialize Cat transaction failed", ex);
}
}
static void init() {
//do nothing, just to initialize the static variables
}
public CatTransaction(Object catTransaction) {
this.catTransaction = catTransaction;
}
@Override
public void setStatus(String status) {
try {
SET_STATUS_WITH_STRING.invoke(catTransaction, status);
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
@Override
public void setStatus(Throwable status) {
try {
SET_STATUS_WITH_THROWABLE.invoke(catTransaction, status);
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
@Override
public void addData(String key, Object value) {
try {
ADD_DATA_WITH_KEY_AND_VALUE.invoke(catTransaction, key, value);
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
@Override
public void complete() {
try {
COMPLETE.invoke(catTransaction);
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/EmailConfiguration.java | package com.ctrip.framework.apollo.portal.spi.configuration;
import com.ctrip.framework.apollo.common.condition.ConditionalOnMissingProfile;
import com.ctrip.framework.apollo.portal.spi.EmailService;
import com.ctrip.framework.apollo.portal.spi.ctrip.CtripEmailService;
import com.ctrip.framework.apollo.portal.spi.ctrip.CtripEmailRequestBuilder;
import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultEmailService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
public class EmailConfiguration {
/**
* spring.profiles.active = ctrip
*/
@Configuration
@Profile("ctrip")
public static class CtripEmailConfiguration {
@Bean
public EmailService ctripEmailService() {
return new CtripEmailService();
}
@Bean
public CtripEmailRequestBuilder emailRequestBuilder() {
return new CtripEmailRequestBuilder();
}
}
/**
* spring.profiles.active != ctrip
*/
@Configuration
@ConditionalOnMissingProfile({"ctrip"})
public static class DefaultEmailConfiguration {
@Bean
@ConditionalOnMissingBean(EmailService.class)
public EmailService defaultEmailService() {
return new DefaultEmailService();
}
}
}
| package com.ctrip.framework.apollo.portal.spi.configuration;
import com.ctrip.framework.apollo.common.condition.ConditionalOnMissingProfile;
import com.ctrip.framework.apollo.portal.spi.EmailService;
import com.ctrip.framework.apollo.portal.spi.ctrip.CtripEmailService;
import com.ctrip.framework.apollo.portal.spi.ctrip.CtripEmailRequestBuilder;
import com.ctrip.framework.apollo.portal.spi.defaultimpl.DefaultEmailService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
public class EmailConfiguration {
/**
* spring.profiles.active = ctrip
*/
@Configuration
@Profile("ctrip")
public static class CtripEmailConfiguration {
@Bean
public EmailService ctripEmailService() {
return new CtripEmailService();
}
@Bean
public CtripEmailRequestBuilder emailRequestBuilder() {
return new CtripEmailRequestBuilder();
}
}
/**
* spring.profiles.active != ctrip
*/
@Configuration
@ConditionalOnMissingProfile({"ctrip"})
public static class DefaultEmailConfiguration {
@Bean
@ConditionalOnMissingBean(EmailService.class)
public EmailService defaultEmailService() {
return new DefaultEmailService();
}
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/NotificationControllerV2Test.java | package com.ctrip.framework.apollo.configservice.controller;
import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.utils.EntityManagerUtil;
import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache;
import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil;
import com.ctrip.framework.apollo.configservice.wrapper.DeferredResultWrapper;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;
import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.context.request.async.DeferredResult;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Jason Song([email protected])
*/
@RunWith(MockitoJUnitRunner.class)
public class NotificationControllerV2Test {
private NotificationControllerV2 controller;
private String someAppId;
private String someCluster;
private String defaultCluster;
private String defaultNamespace;
private String somePublicNamespace;
private String someDataCenter;
private long someNotificationId;
private String someClientIp;
@Mock
private ReleaseMessageServiceWithCache releaseMessageService;
@Mock
private EntityManagerUtil entityManagerUtil;
@Mock
private NamespaceUtil namespaceUtil;
@Mock
private WatchKeysUtil watchKeysUtil;
@Mock
private BizConfig bizConfig;
private Gson gson;
private Multimap<String, DeferredResultWrapper> deferredResults;
@Before
public void setUp() throws Exception {
gson = new Gson();
controller = new NotificationControllerV2(
watchKeysUtil, releaseMessageService, entityManagerUtil, namespaceUtil, gson, bizConfig
);
when(bizConfig.releaseMessageNotificationBatch()).thenReturn(100);
when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(5);
someAppId = "someAppId";
someCluster = "someCluster";
defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
somePublicNamespace = "somePublicNamespace";
someDataCenter = "someDC";
someNotificationId = 1;
someClientIp = "someClientIp";
when(namespaceUtil.filterNamespaceName(defaultNamespace)).thenReturn(defaultNamespace);
when(namespaceUtil.filterNamespaceName(somePublicNamespace)).thenReturn(somePublicNamespace);
when(namespaceUtil.normalizeNamespace(someAppId, defaultNamespace)).thenReturn(defaultNamespace);
when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespace)).thenReturn(somePublicNamespace);
deferredResults =
(Multimap<String, DeferredResultWrapper>) ReflectionTestUtils.getField(controller, "deferredResults");
}
@Test
public void testPollNotificationWithDefaultNamespace() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = "anotherKey";
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey, anotherWatchKey));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(defaultNamespace),
someDataCenter)).thenReturn(
watchKeysMap);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
assertWatchKeys(watchKeysMap, deferredResult);
}
@Test
public void testPollNotificationWithDefaultNamespaceAsFile() throws Exception {
String namespace = String.format("%s.%s", defaultNamespace, "properties");
when(namespaceUtil.filterNamespaceName(namespace)).thenReturn(defaultNamespace);
String someWatchKey = "someKey";
String anotherWatchKey = "anotherKey";
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey, anotherWatchKey));
String notificationAsString =
transformApolloConfigNotificationsToString(namespace, someNotificationId);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(defaultNamespace),
someDataCenter)).thenReturn(
watchKeysMap);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
assertWatchKeys(watchKeysMap, deferredResult);
}
@Test
public void testPollNotificationWithMultipleNamespaces() throws Exception {
String defaultNamespaceAsFile = defaultNamespace + ".properties";
String somePublicNamespaceAsFile = somePublicNamespace + ".xml";
when(namespaceUtil.filterNamespaceName(defaultNamespaceAsFile)).thenReturn(defaultNamespace);
when(namespaceUtil.filterNamespaceName(somePublicNamespaceAsFile)).thenReturn(somePublicNamespaceAsFile);
when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespaceAsFile)).thenReturn(somePublicNamespaceAsFile);
String someWatchKey = "someKey";
String anotherWatchKey = "anotherKey";
String somePublicWatchKey = "somePublicWatchKey";
String somePublicFileWatchKey = "somePublicFileWatchKey";
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey, anotherWatchKey));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(somePublicWatchKey)));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespaceAsFile,
Lists.newArrayList(somePublicFileWatchKey)));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespaceAsFile, someNotificationId,
somePublicNamespace, someNotificationId, somePublicNamespaceAsFile,
someNotificationId);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace, somePublicNamespaceAsFile),
someDataCenter)).thenReturn(
watchKeysMap);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
assertWatchKeys(watchKeysMap, deferredResult);
verify(watchKeysUtil, times(1)).assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace, somePublicNamespaceAsFile),
someDataCenter);
}
@Test
public void testPollNotificationWithMultipleNamespaceWithNotificationIdOutDated()
throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, somePublicNamespace);
String yetAnotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, defaultCluster, somePublicNamespace);
long notificationId = someNotificationId + 1;
long yetAnotherNotificationId = someNotificationId;
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(anotherWatchKey, yetAnotherWatchKey)));
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace), someDataCenter)).thenReturn(
watchKeysMap);
ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
when(someReleaseMessage.getId()).thenReturn(notificationId);
when(someReleaseMessage.getMessage()).thenReturn(anotherWatchKey);
ReleaseMessage yetAnotherReleaseMessage = mock(ReleaseMessage.class);
when(yetAnotherReleaseMessage.getId()).thenReturn(yetAnotherNotificationId);
when(yetAnotherReleaseMessage.getMessage()).thenReturn(yetAnotherWatchKey);
when(releaseMessageService
.findLatestReleaseMessagesGroupByMessages(Sets.newHashSet(watchKeysMap.values())))
.thenReturn(Lists.newArrayList(someReleaseMessage, yetAnotherReleaseMessage));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId,
somePublicNamespace, someNotificationId);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
ResponseEntity<List<ApolloConfigNotification>> result =
(ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(1, result.getBody().size());
assertEquals(somePublicNamespace, result.getBody().get(0).getNamespaceName());
assertEquals(notificationId, result.getBody().get(0).getNotificationId());
ApolloNotificationMessages notificationMessages = result.getBody().get(0).getMessages();
assertEquals(2, notificationMessages.getDetails().size());
assertEquals(notificationId, notificationMessages.get(anotherWatchKey).longValue());
assertEquals(yetAnotherNotificationId, notificationMessages.get(yetAnotherWatchKey).longValue());
}
@Test
public void testPollNotificationWithMultipleNamespacesAndHandleMessage() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, somePublicNamespace);
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(anotherWatchKey)));
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace), someDataCenter)).thenReturn(
watchKeysMap);
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId,
somePublicNamespace, someNotificationId);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(anotherWatchKey);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
ResponseEntity<List<ApolloConfigNotification>> response =
(ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(1, response.getBody().size());
ApolloConfigNotification notification = response.getBody().get(0);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(somePublicNamespace, notification.getNamespaceName());
assertEquals(someId, notification.getNotificationId());
ApolloNotificationMessages notificationMessages = response.getBody().get(0).getMessages();
assertEquals(1, notificationMessages.getDetails().size());
assertEquals(someId, notificationMessages.get(anotherWatchKey).longValue());
}
@Test
public void testPollNotificationWithHandleMessageInBatch() throws Exception {
String someWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, defaultNamespace);
int someBatch = 1;
int someBatchInterval = 10;
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(defaultNamespace),
someDataCenter)).thenReturn(watchKeysMap);
when(bizConfig.releaseMessageNotificationBatch()).thenReturn(someBatch);
when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(someBatchInterval);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
anotherDeferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(someWatchKey);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
//in batch mode, at most one of them should have result
assertFalse(deferredResult.hasResult() && anotherDeferredResult.hasResult());
//now both of them should have result
await().atMost(someBatchInterval * 500, TimeUnit.MILLISECONDS).untilAsserted(
() -> assertTrue(deferredResult.hasResult() && anotherDeferredResult.hasResult()));
}
@Test
public void testPollNotificationWithIncorrectCase() throws Exception {
String appIdWithIncorrectCase = someAppId.toUpperCase();
String namespaceWithIncorrectCase = defaultNamespace.toUpperCase();
String someMessage = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, defaultNamespace);
String someWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(appIdWithIncorrectCase, someCluster, defaultNamespace);
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace.toUpperCase(), someNotificationId);
when(namespaceUtil.filterNamespaceName(namespaceWithIncorrectCase)).thenReturn(namespaceWithIncorrectCase);
when(namespaceUtil.normalizeNamespace(appIdWithIncorrectCase, namespaceWithIncorrectCase)).thenReturn(defaultNamespace);
when(watchKeysUtil
.assembleAllWatchKeys(appIdWithIncorrectCase, someCluster, Sets.newHashSet(defaultNamespace),
someDataCenter)).thenReturn(watchKeysMap);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(appIdWithIncorrectCase, someCluster, notificationAsString, someDataCenter,
someClientIp);
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(someMessage);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
assertTrue(deferredResult.hasResult());
ResponseEntity<List<ApolloConfigNotification>> response =
(ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(1, response.getBody().size());
ApolloConfigNotification notification = response.getBody().get(0);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(namespaceWithIncorrectCase, notification.getNamespaceName());
assertEquals(someId, notification.getNotificationId());
ApolloNotificationMessages notificationMessages = notification.getMessages();
assertEquals(1, notificationMessages.getDetails().size());
assertEquals(someId, notificationMessages.get(someMessage).longValue());
}
private String transformApolloConfigNotificationsToString(
String namespace, long notificationId) {
List<ApolloConfigNotification> notifications =
Lists.newArrayList(assembleApolloConfigNotification(namespace, notificationId));
return gson.toJson(notifications);
}
private String transformApolloConfigNotificationsToString(String namespace, long notificationId,
String anotherNamespace,
long anotherNotificationId) {
List<ApolloConfigNotification> notifications =
Lists.newArrayList(assembleApolloConfigNotification(namespace, notificationId),
assembleApolloConfigNotification(anotherNamespace, anotherNotificationId));
return gson.toJson(notifications);
}
private String transformApolloConfigNotificationsToString(String namespace, long notificationId,
String anotherNamespace,
long anotherNotificationId,
String yetAnotherNamespace,
long yetAnotherNotificationId) {
List<ApolloConfigNotification> notifications =
Lists.newArrayList(assembleApolloConfigNotification(namespace, notificationId),
assembleApolloConfigNotification(anotherNamespace, anotherNotificationId),
assembleApolloConfigNotification(yetAnotherNamespace, yetAnotherNotificationId));
return gson.toJson(notifications);
}
private ApolloConfigNotification assembleApolloConfigNotification(String namespace,
long notificationId) {
ApolloConfigNotification notification = new ApolloConfigNotification(namespace, notificationId);
return notification;
}
private Multimap<String, String> assembleMultiMap(String key, Iterable<String> values) {
Multimap<String, String> multimap = HashMultimap.create();
multimap.putAll(key, values);
return multimap;
}
private void assertWatchKeys(Multimap<String, String> watchKeysMap, DeferredResult deferredResult) {
for (String watchKey : watchKeysMap.values()) {
Collection<DeferredResultWrapper> deferredResultWrappers = deferredResults.get(watchKey);
boolean found = false;
for (DeferredResultWrapper wrapper: deferredResultWrappers) {
if (Objects.equals(wrapper.getResult(), deferredResult)) {
found = true;
}
}
assertTrue(found);
}
}
}
| package com.ctrip.framework.apollo.configservice.controller;
import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.utils.EntityManagerUtil;
import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache;
import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil;
import com.ctrip.framework.apollo.configservice.wrapper.DeferredResultWrapper;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;
import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.context.request.async.DeferredResult;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Jason Song([email protected])
*/
@RunWith(MockitoJUnitRunner.class)
public class NotificationControllerV2Test {
private NotificationControllerV2 controller;
private String someAppId;
private String someCluster;
private String defaultCluster;
private String defaultNamespace;
private String somePublicNamespace;
private String someDataCenter;
private long someNotificationId;
private String someClientIp;
@Mock
private ReleaseMessageServiceWithCache releaseMessageService;
@Mock
private EntityManagerUtil entityManagerUtil;
@Mock
private NamespaceUtil namespaceUtil;
@Mock
private WatchKeysUtil watchKeysUtil;
@Mock
private BizConfig bizConfig;
private Gson gson;
private Multimap<String, DeferredResultWrapper> deferredResults;
@Before
public void setUp() throws Exception {
gson = new Gson();
controller = new NotificationControllerV2(
watchKeysUtil, releaseMessageService, entityManagerUtil, namespaceUtil, gson, bizConfig
);
when(bizConfig.releaseMessageNotificationBatch()).thenReturn(100);
when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(5);
someAppId = "someAppId";
someCluster = "someCluster";
defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
somePublicNamespace = "somePublicNamespace";
someDataCenter = "someDC";
someNotificationId = 1;
someClientIp = "someClientIp";
when(namespaceUtil.filterNamespaceName(defaultNamespace)).thenReturn(defaultNamespace);
when(namespaceUtil.filterNamespaceName(somePublicNamespace)).thenReturn(somePublicNamespace);
when(namespaceUtil.normalizeNamespace(someAppId, defaultNamespace)).thenReturn(defaultNamespace);
when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespace)).thenReturn(somePublicNamespace);
deferredResults =
(Multimap<String, DeferredResultWrapper>) ReflectionTestUtils.getField(controller, "deferredResults");
}
@Test
public void testPollNotificationWithDefaultNamespace() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = "anotherKey";
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey, anotherWatchKey));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(defaultNamespace),
someDataCenter)).thenReturn(
watchKeysMap);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
assertWatchKeys(watchKeysMap, deferredResult);
}
@Test
public void testPollNotificationWithDefaultNamespaceAsFile() throws Exception {
String namespace = String.format("%s.%s", defaultNamespace, "properties");
when(namespaceUtil.filterNamespaceName(namespace)).thenReturn(defaultNamespace);
String someWatchKey = "someKey";
String anotherWatchKey = "anotherKey";
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey, anotherWatchKey));
String notificationAsString =
transformApolloConfigNotificationsToString(namespace, someNotificationId);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(defaultNamespace),
someDataCenter)).thenReturn(
watchKeysMap);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
assertWatchKeys(watchKeysMap, deferredResult);
}
@Test
public void testPollNotificationWithMultipleNamespaces() throws Exception {
String defaultNamespaceAsFile = defaultNamespace + ".properties";
String somePublicNamespaceAsFile = somePublicNamespace + ".xml";
when(namespaceUtil.filterNamespaceName(defaultNamespaceAsFile)).thenReturn(defaultNamespace);
when(namespaceUtil.filterNamespaceName(somePublicNamespaceAsFile)).thenReturn(somePublicNamespaceAsFile);
when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespaceAsFile)).thenReturn(somePublicNamespaceAsFile);
String someWatchKey = "someKey";
String anotherWatchKey = "anotherKey";
String somePublicWatchKey = "somePublicWatchKey";
String somePublicFileWatchKey = "somePublicFileWatchKey";
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey, anotherWatchKey));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(somePublicWatchKey)));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespaceAsFile,
Lists.newArrayList(somePublicFileWatchKey)));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespaceAsFile, someNotificationId,
somePublicNamespace, someNotificationId, somePublicNamespaceAsFile,
someNotificationId);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace, somePublicNamespaceAsFile),
someDataCenter)).thenReturn(
watchKeysMap);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
assertWatchKeys(watchKeysMap, deferredResult);
verify(watchKeysUtil, times(1)).assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace, somePublicNamespaceAsFile),
someDataCenter);
}
@Test
public void testPollNotificationWithMultipleNamespaceWithNotificationIdOutDated()
throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, somePublicNamespace);
String yetAnotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, defaultCluster, somePublicNamespace);
long notificationId = someNotificationId + 1;
long yetAnotherNotificationId = someNotificationId;
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(anotherWatchKey, yetAnotherWatchKey)));
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace), someDataCenter)).thenReturn(
watchKeysMap);
ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
when(someReleaseMessage.getId()).thenReturn(notificationId);
when(someReleaseMessage.getMessage()).thenReturn(anotherWatchKey);
ReleaseMessage yetAnotherReleaseMessage = mock(ReleaseMessage.class);
when(yetAnotherReleaseMessage.getId()).thenReturn(yetAnotherNotificationId);
when(yetAnotherReleaseMessage.getMessage()).thenReturn(yetAnotherWatchKey);
when(releaseMessageService
.findLatestReleaseMessagesGroupByMessages(Sets.newHashSet(watchKeysMap.values())))
.thenReturn(Lists.newArrayList(someReleaseMessage, yetAnotherReleaseMessage));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId,
somePublicNamespace, someNotificationId);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
ResponseEntity<List<ApolloConfigNotification>> result =
(ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(1, result.getBody().size());
assertEquals(somePublicNamespace, result.getBody().get(0).getNamespaceName());
assertEquals(notificationId, result.getBody().get(0).getNotificationId());
ApolloNotificationMessages notificationMessages = result.getBody().get(0).getMessages();
assertEquals(2, notificationMessages.getDetails().size());
assertEquals(notificationId, notificationMessages.get(anotherWatchKey).longValue());
assertEquals(yetAnotherNotificationId, notificationMessages.get(yetAnotherWatchKey).longValue());
}
@Test
public void testPollNotificationWithMultipleNamespacesAndHandleMessage() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, somePublicNamespace);
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(anotherWatchKey)));
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace), someDataCenter)).thenReturn(
watchKeysMap);
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId,
somePublicNamespace, someNotificationId);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(anotherWatchKey);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
ResponseEntity<List<ApolloConfigNotification>> response =
(ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(1, response.getBody().size());
ApolloConfigNotification notification = response.getBody().get(0);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(somePublicNamespace, notification.getNamespaceName());
assertEquals(someId, notification.getNotificationId());
ApolloNotificationMessages notificationMessages = response.getBody().get(0).getMessages();
assertEquals(1, notificationMessages.getDetails().size());
assertEquals(someId, notificationMessages.get(anotherWatchKey).longValue());
}
@Test
public void testPollNotificationWithHandleMessageInBatch() throws Exception {
String someWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, defaultNamespace);
int someBatch = 1;
int someBatchInterval = 10;
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(defaultNamespace),
someDataCenter)).thenReturn(watchKeysMap);
when(bizConfig.releaseMessageNotificationBatch()).thenReturn(someBatch);
when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(someBatchInterval);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
anotherDeferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(someWatchKey);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
//in batch mode, at most one of them should have result
assertFalse(deferredResult.hasResult() && anotherDeferredResult.hasResult());
//now both of them should have result
await().atMost(someBatchInterval * 500, TimeUnit.MILLISECONDS).untilAsserted(
() -> assertTrue(deferredResult.hasResult() && anotherDeferredResult.hasResult()));
}
@Test
public void testPollNotificationWithIncorrectCase() throws Exception {
String appIdWithIncorrectCase = someAppId.toUpperCase();
String namespaceWithIncorrectCase = defaultNamespace.toUpperCase();
String someMessage = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, defaultNamespace);
String someWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(appIdWithIncorrectCase, someCluster, defaultNamespace);
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace.toUpperCase(), someNotificationId);
when(namespaceUtil.filterNamespaceName(namespaceWithIncorrectCase)).thenReturn(namespaceWithIncorrectCase);
when(namespaceUtil.normalizeNamespace(appIdWithIncorrectCase, namespaceWithIncorrectCase)).thenReturn(defaultNamespace);
when(watchKeysUtil
.assembleAllWatchKeys(appIdWithIncorrectCase, someCluster, Sets.newHashSet(defaultNamespace),
someDataCenter)).thenReturn(watchKeysMap);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(appIdWithIncorrectCase, someCluster, notificationAsString, someDataCenter,
someClientIp);
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(someMessage);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
assertTrue(deferredResult.hasResult());
ResponseEntity<List<ApolloConfigNotification>> response =
(ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(1, response.getBody().size());
ApolloConfigNotification notification = response.getBody().get(0);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(namespaceWithIncorrectCase, notification.getNamespaceName());
assertEquals(someId, notification.getNotificationId());
ApolloNotificationMessages notificationMessages = notification.getMessages();
assertEquals(1, notificationMessages.getDetails().size());
assertEquals(someId, notificationMessages.get(someMessage).longValue());
}
private String transformApolloConfigNotificationsToString(
String namespace, long notificationId) {
List<ApolloConfigNotification> notifications =
Lists.newArrayList(assembleApolloConfigNotification(namespace, notificationId));
return gson.toJson(notifications);
}
private String transformApolloConfigNotificationsToString(String namespace, long notificationId,
String anotherNamespace,
long anotherNotificationId) {
List<ApolloConfigNotification> notifications =
Lists.newArrayList(assembleApolloConfigNotification(namespace, notificationId),
assembleApolloConfigNotification(anotherNamespace, anotherNotificationId));
return gson.toJson(notifications);
}
private String transformApolloConfigNotificationsToString(String namespace, long notificationId,
String anotherNamespace,
long anotherNotificationId,
String yetAnotherNamespace,
long yetAnotherNotificationId) {
List<ApolloConfigNotification> notifications =
Lists.newArrayList(assembleApolloConfigNotification(namespace, notificationId),
assembleApolloConfigNotification(anotherNamespace, anotherNotificationId),
assembleApolloConfigNotification(yetAnotherNamespace, yetAnotherNotificationId));
return gson.toJson(notifications);
}
private ApolloConfigNotification assembleApolloConfigNotification(String namespace,
long notificationId) {
ApolloConfigNotification notification = new ApolloConfigNotification(namespace, notificationId);
return notification;
}
private Multimap<String, String> assembleMultiMap(String key, Iterable<String> values) {
Multimap<String, String> multimap = HashMultimap.create();
multimap.putAll(key, values);
return multimap;
}
private void assertWatchKeys(Multimap<String, String> watchKeysMap, DeferredResult deferredResult) {
for (String watchKey : watchKeysMap.values()) {
Collection<DeferredResultWrapper> deferredResultWrappers = deferredResults.get(watchKey);
boolean found = false;
for (DeferredResultWrapper wrapper: deferredResultWrappers) {
if (Objects.equals(wrapper.getResult(), deferredResult)) {
found = true;
}
}
assertTrue(found);
}
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/EnvUtils.java | package com.ctrip.framework.apollo.core.enums;
import com.ctrip.framework.apollo.core.utils.StringUtils;
public final class EnvUtils {
public static Env transformEnv(String envName) {
if (StringUtils.isBlank(envName)) {
return Env.UNKNOWN;
}
switch (envName.trim().toUpperCase()) {
case "LPT":
return Env.LPT;
case "FAT":
case "FWS":
return Env.FAT;
case "UAT":
return Env.UAT;
case "PRO":
case "PROD": //just in case
return Env.PRO;
case "DEV":
return Env.DEV;
case "LOCAL":
return Env.LOCAL;
case "TOOLS":
return Env.TOOLS;
default:
return Env.UNKNOWN;
}
}
}
| package com.ctrip.framework.apollo.core.enums;
import com.ctrip.framework.apollo.core.utils.StringUtils;
public final class EnvUtils {
public static Env transformEnv(String envName) {
if (StringUtils.isBlank(envName)) {
return Env.UNKNOWN;
}
switch (envName.trim().toUpperCase()) {
case "LPT":
return Env.LPT;
case "FAT":
case "FWS":
return Env.FAT;
case "UAT":
return Env.UAT;
case "PRO":
case "PROD": //just in case
return Env.PRO;
case "DEV":
return Env.DEV;
case "LOCAL":
return Env.LOCAL;
case "TOOLS":
return Env.TOOLS;
default:
return Env.UNKNOWN;
}
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/controller/ReleaseControllerTest.java | package com.ctrip.framework.apollo.adminservice.controller;
import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.message.MessageSender;
import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.repository.ReleaseRepository;
import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.biz.service.ReleaseService;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.HashMap;
import java.util.Map;
import static org.mockito.Mockito.*;
public class ReleaseControllerTest extends AbstractControllerTest {
private static final Gson GSON = new Gson();
@Autowired
ReleaseRepository releaseRepository;
@Test
@Sql(scripts = "/controller/test-release.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testReleaseBuild() {
String appId = "someAppId";
AppDTO app =
restTemplate.getForObject("http://localhost:" + port + "/apps/" + appId, AppDTO.class);
ClusterDTO cluster = restTemplate.getForObject(
"http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/default",
ClusterDTO.class);
NamespaceDTO namespace =
restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId()
+ "/clusters/" + cluster.getName() + "/namespaces/application", NamespaceDTO.class);
Assert.assertEquals("someAppId", app.getAppId());
Assert.assertEquals("default", cluster.getName());
Assert.assertEquals("application", namespace.getNamespaceName());
ItemDTO[] items =
restTemplate.getForObject(
"http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/"
+ cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/items",
ItemDTO[].class);
Assert.assertEquals(3, items.length);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
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<>(parameters, headers);
ResponseEntity<ReleaseDTO> response = restTemplate.postForEntity(
"http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName()
+ "/namespaces/" + namespace.getNamespaceName() + "/releases",
entity, ReleaseDTO.class);
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
ReleaseDTO release = response.getBody();
Assert.assertEquals("someReleaseName", release.getName());
Assert.assertEquals("someComment", release.getComment());
Assert.assertEquals("someAppId", release.getAppId());
Assert.assertEquals("default", release.getClusterName());
Assert.assertEquals("application", release.getNamespaceName());
Map<String, String> configurations = new HashMap<>();
configurations.put("k1", "v1");
configurations.put("k2", "v2");
configurations.put("k3", "v3");
Assert.assertEquals(GSON.toJson(configurations), release.getConfigurations());
}
@Test
public void testMessageSendAfterBuildRelease() throws Exception {
String someAppId = "someAppId";
String someNamespaceName = "someNamespace";
String someCluster = "someCluster";
String someName = "someName";
String someComment = "someComment";
String someUserName = "someUser";
NamespaceService someNamespaceService = mock(NamespaceService.class);
ReleaseService someReleaseService = mock(ReleaseService.class);
MessageSender someMessageSender = mock(MessageSender.class);
Namespace someNamespace = mock(Namespace.class);
ReleaseController releaseController = new ReleaseController(someReleaseService, someNamespaceService, someMessageSender, null);
when(someNamespaceService.findOne(someAppId, someCluster, someNamespaceName))
.thenReturn(someNamespace);
releaseController
.publish(someAppId, someCluster, someNamespaceName, someName, someComment, "test", false);
verify(someMessageSender, times(1))
.sendMessage(Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, someNamespaceName),
Topics.APOLLO_RELEASE_TOPIC);
}
}
| package com.ctrip.framework.apollo.adminservice.controller;
import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.message.MessageSender;
import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.repository.ReleaseRepository;
import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.biz.service.ReleaseService;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.HashMap;
import java.util.Map;
import static org.mockito.Mockito.*;
public class ReleaseControllerTest extends AbstractControllerTest {
private static final Gson GSON = new Gson();
@Autowired
ReleaseRepository releaseRepository;
@Test
@Sql(scripts = "/controller/test-release.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testReleaseBuild() {
String appId = "someAppId";
AppDTO app =
restTemplate.getForObject("http://localhost:" + port + "/apps/" + appId, AppDTO.class);
ClusterDTO cluster = restTemplate.getForObject(
"http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/default",
ClusterDTO.class);
NamespaceDTO namespace =
restTemplate.getForObject("http://localhost:" + port + "/apps/" + app.getAppId()
+ "/clusters/" + cluster.getName() + "/namespaces/application", NamespaceDTO.class);
Assert.assertEquals("someAppId", app.getAppId());
Assert.assertEquals("default", cluster.getName());
Assert.assertEquals("application", namespace.getNamespaceName());
ItemDTO[] items =
restTemplate.getForObject(
"http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/"
+ cluster.getName() + "/namespaces/" + namespace.getNamespaceName() + "/items",
ItemDTO[].class);
Assert.assertEquals(3, items.length);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
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<>(parameters, headers);
ResponseEntity<ReleaseDTO> response = restTemplate.postForEntity(
"http://localhost:" + port + "/apps/" + app.getAppId() + "/clusters/" + cluster.getName()
+ "/namespaces/" + namespace.getNamespaceName() + "/releases",
entity, ReleaseDTO.class);
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
ReleaseDTO release = response.getBody();
Assert.assertEquals("someReleaseName", release.getName());
Assert.assertEquals("someComment", release.getComment());
Assert.assertEquals("someAppId", release.getAppId());
Assert.assertEquals("default", release.getClusterName());
Assert.assertEquals("application", release.getNamespaceName());
Map<String, String> configurations = new HashMap<>();
configurations.put("k1", "v1");
configurations.put("k2", "v2");
configurations.put("k3", "v3");
Assert.assertEquals(GSON.toJson(configurations), release.getConfigurations());
}
@Test
public void testMessageSendAfterBuildRelease() throws Exception {
String someAppId = "someAppId";
String someNamespaceName = "someNamespace";
String someCluster = "someCluster";
String someName = "someName";
String someComment = "someComment";
String someUserName = "someUser";
NamespaceService someNamespaceService = mock(NamespaceService.class);
ReleaseService someReleaseService = mock(ReleaseService.class);
MessageSender someMessageSender = mock(MessageSender.class);
Namespace someNamespace = mock(Namespace.class);
ReleaseController releaseController = new ReleaseController(someReleaseService, someNamespaceService, someMessageSender, null);
when(someNamespaceService.findOne(someAppId, someCluster, someNamespaceName))
.thenReturn(someNamespace);
releaseController
.publish(someAppId, someCluster, someNamespaceName, someName, someComment, "test", false);
verify(someMessageSender, times(1))
.sendMessage(Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, someNamespaceName),
Topics.APOLLO_RELEASE_TOPIC);
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-common/src/main/java/com/ctrip/framework/apollo/common/constants/ReleaseOperation.java | package com.ctrip.framework.apollo.common.constants;
/**
* @author Jason Song([email protected])
*/
public interface ReleaseOperation {
int NORMAL_RELEASE = 0;
int ROLLBACK = 1;
int GRAY_RELEASE = 2;
int APPLY_GRAY_RULES = 3;
int GRAY_RELEASE_MERGE_TO_MASTER = 4;
int MASTER_NORMAL_RELEASE_MERGE_TO_GRAY = 5;
int MATER_ROLLBACK_MERGE_TO_GRAY = 6;
int ABANDON_GRAY_RELEASE = 7;
int GRAY_RELEASE_DELETED_AFTER_MERGE = 8;
}
| package com.ctrip.framework.apollo.common.constants;
/**
* @author Jason Song([email protected])
*/
public interface ReleaseOperation {
int NORMAL_RELEASE = 0;
int ROLLBACK = 1;
int GRAY_RELEASE = 2;
int APPLY_GRAY_RULES = 3;
int GRAY_RELEASE_MERGE_TO_MASTER = 4;
int MASTER_NORMAL_RELEASE_MERGE_TO_GRAY = 5;
int MATER_ROLLBACK_MERGE_TO_GRAY = 6;
int ABANDON_GRAY_RELEASE = 7;
int GRAY_RELEASE_DELETED_AFTER_MERGE = 8;
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/config/ConfigTest.java | package com.ctrip.framework.apollo.portal.config;
import com.ctrip.framework.apollo.portal.AbstractUnitTest;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.core.env.ConfigurableEnvironment;
import static org.mockito.Mockito.when;
public class ConfigTest extends AbstractUnitTest{
@Mock
private ConfigurableEnvironment environment;
@InjectMocks
private PortalConfig config;
@Test
public void testGetNotExistValue() {
String testKey = "key";
String testDefaultValue = "value";
when(environment.getProperty(testKey, testDefaultValue)).thenReturn(testDefaultValue);
Assert.assertEquals(testDefaultValue, config.getValue(testKey, testDefaultValue));
}
@Test
public void testGetArrayProperty() {
String testKey = "key";
String testValue = "a,b,c";
when(environment.getProperty(testKey)).thenReturn(testValue);
String[] result = config.getArrayProperty(testKey, null);
Assert.assertEquals(3, result.length);
Assert.assertEquals("a", result[0]);
Assert.assertEquals("b", result[1]);
Assert.assertEquals("c", result[2]);
}
@Test
public void testGetBooleanProperty() {
String testKey = "key";
String testValue = "true";
when(environment.getProperty(testKey)).thenReturn(testValue);
boolean result = config.getBooleanProperty(testKey, false);
Assert.assertTrue(result);
}
@Test
public void testGetIntProperty() {
String testKey = "key";
String testValue = "1024";
when(environment.getProperty(testKey)).thenReturn(testValue);
int result = config.getIntProperty(testKey, 0);
Assert.assertEquals(1024, result);
}
}
| package com.ctrip.framework.apollo.portal.config;
import com.ctrip.framework.apollo.portal.AbstractUnitTest;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.core.env.ConfigurableEnvironment;
import static org.mockito.Mockito.when;
public class ConfigTest extends AbstractUnitTest{
@Mock
private ConfigurableEnvironment environment;
@InjectMocks
private PortalConfig config;
@Test
public void testGetNotExistValue() {
String testKey = "key";
String testDefaultValue = "value";
when(environment.getProperty(testKey, testDefaultValue)).thenReturn(testDefaultValue);
Assert.assertEquals(testDefaultValue, config.getValue(testKey, testDefaultValue));
}
@Test
public void testGetArrayProperty() {
String testKey = "key";
String testValue = "a,b,c";
when(environment.getProperty(testKey)).thenReturn(testValue);
String[] result = config.getArrayProperty(testKey, null);
Assert.assertEquals(3, result.length);
Assert.assertEquals("a", result[0]);
Assert.assertEquals("b", result[1]);
Assert.assertEquals("c", result[2]);
}
@Test
public void testGetBooleanProperty() {
String testKey = "key";
String testValue = "true";
when(environment.getProperty(testKey)).thenReturn(testValue);
boolean result = config.getBooleanProperty(testKey, false);
Assert.assertTrue(result);
}
@Test
public void testGetIntProperty() {
String testKey = "key";
String testValue = "1024";
when(environment.getProperty(testKey)).thenReturn(testValue);
int result = config.getIntProperty(testKey, 0);
Assert.assertEquals(1024, result);
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java | package com.ctrip.framework.apollo.biz.entity;
import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* @author Jason Song([email protected])
*/
@Entity
@Table(name = "ReleaseHistory")
@SQLDelete(sql = "Update ReleaseHistory set isDeleted = 1 where id = ?")
@Where(clause = "isDeleted = 0")
public class ReleaseHistory extends BaseEntity {
@Column(name = "AppId", nullable = false)
private String appId;
@Column(name = "ClusterName", nullable = false)
private String clusterName;
@Column(name = "NamespaceName", nullable = false)
private String namespaceName;
@Column(name = "BranchName", nullable = false)
private String branchName;
@Column(name = "ReleaseId")
private long releaseId;
@Column(name = "PreviousReleaseId")
private long previousReleaseId;
@Column(name = "Operation")
private int operation;
@Column(name = "OperationContext", nullable = false)
private String operationContext;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public String getNamespaceName() {
return namespaceName;
}
public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}
public String getBranchName() {
return branchName;
}
public void setBranchName(String branchName) {
this.branchName = branchName;
}
public long getReleaseId() {
return releaseId;
}
public void setReleaseId(long releaseId) {
this.releaseId = releaseId;
}
public long getPreviousReleaseId() {
return previousReleaseId;
}
public void setPreviousReleaseId(long previousReleaseId) {
this.previousReleaseId = previousReleaseId;
}
public int getOperation() {
return operation;
}
public void setOperation(int operation) {
this.operation = operation;
}
public String getOperationContext() {
return operationContext;
}
public void setOperationContext(String operationContext) {
this.operationContext = operationContext;
}
public String toString() {
return toStringHelper().add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).add("branchName", branchName)
.add("releaseId", releaseId).add("previousReleaseId", previousReleaseId)
.add("operation", operation).toString();
}
}
| package com.ctrip.framework.apollo.biz.entity;
import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* @author Jason Song([email protected])
*/
@Entity
@Table(name = "ReleaseHistory")
@SQLDelete(sql = "Update ReleaseHistory set isDeleted = 1 where id = ?")
@Where(clause = "isDeleted = 0")
public class ReleaseHistory extends BaseEntity {
@Column(name = "AppId", nullable = false)
private String appId;
@Column(name = "ClusterName", nullable = false)
private String clusterName;
@Column(name = "NamespaceName", nullable = false)
private String namespaceName;
@Column(name = "BranchName", nullable = false)
private String branchName;
@Column(name = "ReleaseId")
private long releaseId;
@Column(name = "PreviousReleaseId")
private long previousReleaseId;
@Column(name = "Operation")
private int operation;
@Column(name = "OperationContext", nullable = false)
private String operationContext;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public String getNamespaceName() {
return namespaceName;
}
public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}
public String getBranchName() {
return branchName;
}
public void setBranchName(String branchName) {
this.branchName = branchName;
}
public long getReleaseId() {
return releaseId;
}
public void setReleaseId(long releaseId) {
this.releaseId = releaseId;
}
public long getPreviousReleaseId() {
return previousReleaseId;
}
public void setPreviousReleaseId(long previousReleaseId) {
this.previousReleaseId = previousReleaseId;
}
public int getOperation() {
return operation;
}
public void setOperation(int operation) {
this.operation = operation;
}
public String getOperationContext() {
return operationContext;
}
public void setOperationContext(String operationContext) {
this.operationContext = operationContext;
}
public String toString() {
return toStringHelper().add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).add("branchName", branchName)
.add("releaseId", releaseId).add("previousReleaseId", previousReleaseId)
.add("operation", operation).toString();
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/ConfigServiceApplication.java | package com.ctrip.framework.apollo.configservice;
import com.ctrip.framework.apollo.biz.ApolloBizConfig;
import com.ctrip.framework.apollo.common.ApolloCommonConfig;
import com.ctrip.framework.apollo.metaservice.ApolloMetaServiceConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Spring boot application entry point
*
* @author Jason Song([email protected])
*/
@EnableAspectJAutoProxy
@EnableAutoConfiguration
@Configuration
@EnableTransactionManagement
@PropertySource(value = {"classpath:configservice.properties"})
@ComponentScan(basePackageClasses = {ApolloCommonConfig.class,
ApolloBizConfig.class,
ConfigServiceApplication.class,
ApolloMetaServiceConfig.class})
public class ConfigServiceApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
| package com.ctrip.framework.apollo.configservice;
import com.ctrip.framework.apollo.biz.ApolloBizConfig;
import com.ctrip.framework.apollo.common.ApolloCommonConfig;
import com.ctrip.framework.apollo.metaservice.ApolloMetaServiceConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Spring boot application entry point
*
* @author Jason Song([email protected])
*/
@EnableAspectJAutoProxy
@EnableAutoConfiguration
@Configuration
@EnableTransactionManagement
@PropertySource(value = {"classpath:configservice.properties"})
@ComponentScan(basePackageClasses = {ApolloCommonConfig.class,
ApolloBizConfig.class,
ConfigServiceApplication.class,
ApolloMetaServiceConfig.class})
public class ConfigServiceApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserRole.java | package com.ctrip.framework.apollo.portal.entity.po;
import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* @author Jason Song([email protected])
*/
@Entity
@Table(name = "UserRole")
@SQLDelete(sql = "Update UserRole set isDeleted = 1 where id = ?")
@Where(clause = "isDeleted = 0")
public class UserRole extends BaseEntity {
@Column(name = "UserId", nullable = false)
private String userId;
@Column(name = "RoleId", nullable = false)
private long roleId;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public long getRoleId() {
return roleId;
}
public void setRoleId(long roleId) {
this.roleId = roleId;
}
}
| package com.ctrip.framework.apollo.portal.entity.po;
import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* @author Jason Song([email protected])
*/
@Entity
@Table(name = "UserRole")
@SQLDelete(sql = "Update UserRole set isDeleted = 1 where id = ?")
@Where(clause = "isDeleted = 0")
public class UserRole extends BaseEntity {
@Column(name = "UserId", nullable = false)
private String userId;
@Column(name = "RoleId", nullable = false)
private long roleId;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public long getRoleId() {
return roleId;
}
public void setRoleId(long roleId) {
this.roleId = roleId;
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-configservice/src/test/resources/integration-test/test-release-public-default-override.sql | INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, NamespaceName, Configurations)
VALUES (994, 'TEST-RELEASE-KEY5', 'INTEGRATION-TEST-DEFAULT-OVERRIDE-PUBLIC','First Release','someAppId', 'default', 'somePublicNamespace', '{"k1":"override-v1"}');
| INSERT INTO RELEASE (id, ReleaseKey, Name, Comment, AppId, ClusterName, NamespaceName, Configurations)
VALUES (994, 'TEST-RELEASE-KEY5', 'INTEGRATION-TEST-DEFAULT-OVERRIDE-PUBLIC','First Release','someAppId', 'default', 'somePublicNamespace', '{"k1":"override-v1"}');
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/SpringInjector.java | package com.ctrip.framework.apollo.spring.util;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.spring.config.ConfigPropertySourceFactory;
import com.ctrip.framework.apollo.spring.property.PlaceholderHelper;
import com.ctrip.framework.apollo.spring.property.SpringValueRegistry;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Singleton;
public class SpringInjector {
private static volatile Injector s_injector;
private static final Object lock = new Object();
private static Injector getInjector() {
if (s_injector == null) {
synchronized (lock) {
if (s_injector == null) {
try {
s_injector = Guice.createInjector(new SpringModule());
} catch (Throwable ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to initialize Apollo Spring 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 %s!", clazz.getName()), ex);
}
}
private static class SpringModule extends AbstractModule {
@Override
protected void configure() {
bind(PlaceholderHelper.class).in(Singleton.class);
bind(ConfigPropertySourceFactory.class).in(Singleton.class);
bind(SpringValueRegistry.class).in(Singleton.class);
}
}
}
| package com.ctrip.framework.apollo.spring.util;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.spring.config.ConfigPropertySourceFactory;
import com.ctrip.framework.apollo.spring.property.PlaceholderHelper;
import com.ctrip.framework.apollo.spring.property.SpringValueRegistry;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Singleton;
public class SpringInjector {
private static volatile Injector s_injector;
private static final Object lock = new Object();
private static Injector getInjector() {
if (s_injector == null) {
synchronized (lock) {
if (s_injector == null) {
try {
s_injector = Guice.createInjector(new SpringModule());
} catch (Throwable ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to initialize Apollo Spring 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 %s!", clazz.getName()), ex);
}
}
private static class SpringModule extends AbstractModule {
@Override
protected void configure() {
bind(PlaceholderHelper.class).in(Singleton.class);
bind(ConfigPropertySourceFactory.class).in(Singleton.class);
bind(SpringValueRegistry.class).in(Singleton.class);
}
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-portal/src/main/resources/static/img/secret.png | PNG
IHDR X IDATx^
\eyϹ$#4Q$u
ݳ$Bɘ={A\
II퐀ɞ
4ZHm) S"cɞ!`͞s38{?Ϟ{%KI B`r:~H@@dǭ],khʱk:!fJ:DA_K=D0퐃p}ƞ H@zFmI]6W~k?IDǂ :&]<Š,lQ}/
T='3@O^ YC{ HGO8<g |(\BAbܾH Hm`ylΤ5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ig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java | package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
import com.ctrip.framework.apollo.portal.entity.po.UserPO;
import com.ctrip.framework.apollo.portal.spi.LogoutHandler;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.UserService;
import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@RestController
public class UserInfoController {
private final UserInfoHolder userInfoHolder;
private final LogoutHandler logoutHandler;
private final UserService userService;
public UserInfoController(
final UserInfoHolder userInfoHolder,
final LogoutHandler logoutHandler,
final UserService userService) {
this.userInfoHolder = userInfoHolder;
this.logoutHandler = logoutHandler;
this.userService = userService;
}
@PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@PostMapping("/users")
public void createOrUpdateUser(@RequestBody UserPO user) {
if (StringUtils.isContainEmpty(user.getUsername(), user.getPassword())) {
throw new BadRequestException("Username and password can not be empty.");
}
if (userService instanceof SpringSecurityUserService) {
((SpringSecurityUserService) userService).createOrUpdate(user);
} else {
throw new UnsupportedOperationException("Create or update user operation is unsupported");
}
}
@GetMapping("/user")
public UserInfo getCurrentUserName() {
return userInfoHolder.getUser();
}
@GetMapping("/user/logout")
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
logoutHandler.logout(request, response);
}
@GetMapping("/users")
public List<UserInfo> searchUsersByKeyword(@RequestParam(value = "keyword") String keyword,
@RequestParam(value = "offset", defaultValue = "0") int offset,
@RequestParam(value = "limit", defaultValue = "10") int limit) {
return userService.searchUsers(keyword, offset, limit);
}
@GetMapping("/users/{userId}")
public UserInfo getUserByUserId(@PathVariable String userId) {
return userService.findByUserId(userId);
}
}
| package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
import com.ctrip.framework.apollo.portal.entity.po.UserPO;
import com.ctrip.framework.apollo.portal.spi.LogoutHandler;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.UserService;
import com.ctrip.framework.apollo.portal.spi.springsecurity.SpringSecurityUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@RestController
public class UserInfoController {
private final UserInfoHolder userInfoHolder;
private final LogoutHandler logoutHandler;
private final UserService userService;
public UserInfoController(
final UserInfoHolder userInfoHolder,
final LogoutHandler logoutHandler,
final UserService userService) {
this.userInfoHolder = userInfoHolder;
this.logoutHandler = logoutHandler;
this.userService = userService;
}
@PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@PostMapping("/users")
public void createOrUpdateUser(@RequestBody UserPO user) {
if (StringUtils.isContainEmpty(user.getUsername(), user.getPassword())) {
throw new BadRequestException("Username and password can not be empty.");
}
if (userService instanceof SpringSecurityUserService) {
((SpringSecurityUserService) userService).createOrUpdate(user);
} else {
throw new UnsupportedOperationException("Create or update user operation is unsupported");
}
}
@GetMapping("/user")
public UserInfo getCurrentUserName() {
return userInfoHolder.getUser();
}
@GetMapping("/user/logout")
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
logoutHandler.logout(request, response);
}
@GetMapping("/users")
public List<UserInfo> searchUsersByKeyword(@RequestParam(value = "keyword") String keyword,
@RequestParam(value = "offset", defaultValue = "0") int offset,
@RequestParam(value = "limit", defaultValue = "10") int limit) {
return userService.searchUsers(keyword, offset, limit);
}
@GetMapping("/users/{userId}")
public UserInfo getUserByUserId(@PathVariable String userId) {
return userService.findByUserId(userId);
}
}
| -1 |
apolloconfig/apollo | 3,602 | Allow users to inject customized instance via ApolloInjectorCustomizer | ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| nobodyiam | 2021-03-13T11:14:58Z | 2021-03-13T11:19:34Z | d05979590d99ae142445c104003d7c5a05804e32 | 1f5b3648fb6fbb1fa9833b04fe9d7ed32eee9932 | Allow users to inject customized instance via ApolloInjectorCustomizer. ## What's the purpose of this PR
Allow users to inject customized instances via ApolloInjectorCustomizer
## Which issue(s) this PR fixes:
Fixes #3573
## Brief changelog
1. Add ApolloInjectorCustomizer
2. Load customized instances in DefaultInjector
Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Read the [Contributing Guide](https://github.com/ctripcorp/apollo/blob/master/CONTRIBUTING.md) before making this pull request.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit tests to verify the code.
- [x] Run `mvn clean test` to make sure this pull request doesn't break anything.
| ./doc/images/gray-release/abandon-gray-release.png | PNG
IHDR a8Y IDATxřI9G$ 9&'9}>mg0DDQD9
+mN3贈fYV_Uں6QXX4b
" " " " " " " " " O H@@8M'J$ܯj " " " " " " " " " " " " " " " " " " ]DqUHD4G8@hnn7Zee555eqIU4=yyy֣GٳBܫJ,;&I`@ oҥǭ[nL<gmf%%%6l0 Wi4~9}Txl'b
khh[$Qc4O'"shV~Y>}r*3*M03VUU9/??y.
\Db˶l"ѯs*& /O^W(:F̙36}38âν,ׯ_ooM:Ս" " " A ~~x)t>>Yy@)@\u%G!dSnj3f̰c+`nݺ?rH;S?SUܟ~۴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