Commit 55a0e1b8 authored by nobodyiam's avatar nobodyiam

upgrade spring boot to 2.0.5 and spring cloud to Finchley.SR1

parent 425de29e
......@@ -22,17 +22,15 @@
<!-- end of apollo -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>
spring-cloud-starter-archaius
</artifactId>
<artifactId>spring-cloud-starter-netflix-archaius</artifactId>
<groupId>org.springframework.cloud</groupId>
</exclusion>
<exclusion>
<artifactId>spring-cloud-starter-ribbon</artifactId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<groupId>org.springframework.cloud</groupId>
</exclusion>
<exclusion>
......
......@@ -24,7 +24,7 @@ public class AdminServiceHealthIndicator implements HealthIndicator {
}
private int check() {
PageRequest pageable = new PageRequest(0, 1);
PageRequest pageable = PageRequest.of(0, 1);
appService.findAll(pageable);
return 0;
}
......
......@@ -183,7 +183,7 @@ public class InstanceConfigController {
@RequestParam("clusterName") String clusterName,
@RequestParam("namespaceName") String namespaceName) {
Page<Instance> instances = instanceService.findInstancesByNamespace(appId, clusterName,
namespaceName, new PageRequest(0, 1));
namespaceName, PageRequest.of(0, 1));
return instances.getTotalElements();
}
}
......@@ -3,3 +3,4 @@ spring.application.name= apollo-adminservice
ctrip.appid= 100003172
server.port= 8090
logging.file= /opt/logs/100003172/apollo-adminservice.log
spring.jmx.default-domain = apollo-adminservice
......@@ -2,6 +2,8 @@ eureka:
instance:
hostname: ${hostname:localhost}
preferIpAddress: true
status-page-url-path: /info
health-check-url-path: /health
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8080/eureka/
......@@ -9,15 +11,7 @@ eureka:
enabled: true
eurekaServiceUrlPollIntervalSeconds: 60
endpoints:
health:
sensitive: false
management:
security:
enabled: false
health:
status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
......@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s
declare -i total_time=0
printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "Coyote")" != "" ]];
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=1
......
......@@ -5,10 +5,10 @@ import com.ctrip.framework.apollo.AdminServiceTestConfiguration;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
......@@ -16,14 +16,13 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = AdminServiceTestConfiguration.class)
@WebIntegrationTest(randomPort = true)
@SpringBootTest(classes = AdminServiceTestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public abstract class AbstractControllerTest {
@Autowired
private HttpMessageConverters httpMessageConverters;
RestTemplate restTemplate = new TestRestTemplate();
protected RestTemplate restTemplate = (new TestRestTemplate()).getRestTemplate();
@PostConstruct
private void postConstruct() {
......
......@@ -53,7 +53,7 @@ public class AppControllerTest extends AbstractControllerTest {
Assert.assertEquals(dto.getAppId(), result.getAppId());
Assert.assertTrue(result.getId() > 0);
App savedApp = appRepository.findOne(result.getId());
App savedApp = appRepository.findById(result.getId()).orElse(null);
Assert.assertEquals(dto.getAppId(), savedApp.getAppId());
Assert.assertNotNull(savedApp.getDataChangeCreatedTime());
}
......@@ -69,7 +69,7 @@ public class AppControllerTest extends AbstractControllerTest {
Assert.assertEquals(dto.getAppId(), first.getAppId());
Assert.assertTrue(first.getId() > 0);
App savedApp = appRepository.findOne(first.getId());
App savedApp = appRepository.findById(first.getId()).orElse(null);
Assert.assertEquals(dto.getAppId(), savedApp.getAppId());
Assert.assertNotNull(savedApp.getDataChangeCreatedTime());
......@@ -108,7 +108,7 @@ public class AppControllerTest extends AbstractControllerTest {
restTemplate.delete("http://localhost:{port}/apps/{appId}?operator={operator}", port, app.getAppId(), "test");
App deletedApp = appRepository.findOne(app.getId());
App deletedApp = appRepository.findById(app.getId()).orElse(null);
Assert.assertNull(deletedApp);
}
......
......@@ -56,7 +56,7 @@ public class ControllerExceptionTest {
@Test
public void testFindEmpty() {
when(appService.findAll(any(Pageable.class))).thenReturn(new ArrayList<App>());
Pageable pageable = new PageRequest(0, 10);
Pageable pageable = PageRequest.of(0, 10);
List<AppDTO> appDTOs = appController.find(null, pageable);
Assert.assertNotNull(appDTOs);
Assert.assertEquals(0, appDTOs.size());
......@@ -68,7 +68,7 @@ public class ControllerExceptionTest {
@Test
public void testFindByName() {
Pageable pageable = new PageRequest(0, 10);
Pageable pageable = PageRequest.of(0, 10);
List<AppDTO> appDTOs = appController.find("unexist", pageable);
Assert.assertNotNull(appDTOs);
Assert.assertEquals(0, appDTOs.size());
......
......@@ -20,6 +20,7 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.test.util.ReflectionTestUtils;
......@@ -47,7 +48,6 @@ public class InstanceConfigControllerTest {
@Mock
private InstanceService instanceService;
@Mock
private Pageable pageable;
@Before
......@@ -55,6 +55,8 @@ public class InstanceConfigControllerTest {
instanceConfigController = new InstanceConfigController();
ReflectionTestUtils.setField(instanceConfigController, "releaseService", releaseService);
ReflectionTestUtils.setField(instanceConfigController, "instanceService", instanceService);
pageable = PageRequest.of(0, 2);
}
@Test
......@@ -230,7 +232,6 @@ public class InstanceConfigControllerTest {
String someIp = "someIp";
long someInstanceId = 1;
long anotherInstanceId = 2;
Pageable pageable = mock(Pageable.class);
Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName,
someNamespaceName, someIp);
......@@ -270,7 +271,6 @@ public class InstanceConfigControllerTest {
String someIp = "someIp";
long someInstanceId = 1;
long anotherInstanceId = 2;
Pageable pageable = mock(Pageable.class);
Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName,
someNamespaceName, someIp);
......@@ -352,4 +352,4 @@ public class InstanceConfigControllerTest {
instanceConfig.setReleaseDeliveryTime(releaseDeliveryTime);
return instanceConfig;
}
}
\ No newline at end of file
}
......@@ -11,7 +11,7 @@ import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.jdbc.Sql;
......@@ -47,7 +47,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets itemSet = new ItemChangeSets();
itemSet.setDataChangeLastModifiedBy("created");
RestTemplate createdTemplate = new TestRestTemplate();
RestTemplate createdTemplate = (new TestRestTemplate()).getRestTemplate();
createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3;
......@@ -96,7 +96,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets createChangeSet = new ItemChangeSets();
createChangeSet.setDataChangeLastModifiedBy("created");
RestTemplate createdRestTemplate = new TestRestTemplate();
RestTemplate createdRestTemplate = (new TestRestTemplate()).getRestTemplate();
createdRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3;
......@@ -123,7 +123,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets updateChangeSet = new ItemChangeSets();
updateChangeSet.setDataChangeLastModifiedBy("updated");
RestTemplate updatedRestTemplate = new TestRestTemplate();
RestTemplate updatedRestTemplate = (new TestRestTemplate()).getRestTemplate();
updatedRestTemplate.setMessageConverters(restTemplate.getMessageConverters());
int updatedSize = 2;
......@@ -170,7 +170,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets createChangeSet = new ItemChangeSets();
createChangeSet.setDataChangeLastModifiedBy("created");
RestTemplate createdTemplate = new TestRestTemplate();
RestTemplate createdTemplate = (new TestRestTemplate()).getRestTemplate();
createdTemplate.setMessageConverters(restTemplate.getMessageConverters());
int createdSize = 3;
......@@ -196,7 +196,7 @@ public class ItemSetControllerTest extends AbstractControllerTest {
ItemChangeSets deleteChangeSet = new ItemChangeSets();
deleteChangeSet.setDataChangeLastModifiedBy("deleted");
RestTemplate deletedTemplate = new TestRestTemplate();
RestTemplate deletedTemplate = (new TestRestTemplate()).getRestTemplate();
deletedTemplate.setMessageConverters(restTemplate.getMessageConverters());
int deletedSize = 1;
......
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true
......
eureka:
instance:
hostname: ${hostname:localhost}
preferIpAddress: true
status-page-url-path: /info
health-check-url-path: /health
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8090/eureka/
healthcheck:
enabled: true
endpoints:
health:
sensitive: false
management:
security:
enabled: false
health:
status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
......@@ -6,6 +6,7 @@ import com.ctrip.framework.apollo.portal.PortalApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
......@@ -24,7 +25,7 @@ public class ApolloApplication {
* Common
*/
ConfigurableApplicationContext commonContext =
new SpringApplicationBuilder(ApolloApplication.class).web(false).run(args);
new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args);
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
/**
......
......@@ -6,6 +6,7 @@ import com.ctrip.framework.apollo.portal.PortalApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
......@@ -24,7 +25,7 @@ public class LocalApolloApplication {
* Common
*/
ConfigurableApplicationContext commonContext =
new SpringApplicationBuilder(ApolloApplication.class).web(false).run(args);
new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args);
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
/**
......
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true
......
......@@ -21,7 +21,7 @@
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- end of eureka -->
<dependency>
......
......@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;
......@@ -18,7 +19,7 @@ import javax.persistence.Table;
@Table(name = "Instance")
public class Instance {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private long id;
......
......@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
......@@ -19,7 +20,7 @@ import javax.persistence.Table;
@Table(name = "InstanceConfig")
public class InstanceConfig {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private long id;
......
......@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;
......@@ -18,7 +19,7 @@ import javax.persistence.Table;
@Table(name = "ReleaseMessage")
public class ReleaseMessage {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private long id;
......
......@@ -88,7 +88,7 @@ public class DatabaseMessageSender implements MessageSender {
private void cleanMessage(Long id) {
boolean hasMore = true;
//double check in case the release message is rolled back
ReleaseMessage releaseMessage = releaseMessageRepository.findOne(id);
ReleaseMessage releaseMessage = releaseMessageRepository.findById(id).orElse(null);
if (releaseMessage == null) {
return;
}
......@@ -96,7 +96,7 @@ public class DatabaseMessageSender implements MessageSender {
List<ReleaseMessage> messages = releaseMessageRepository.findFirst100ByMessageAndIdLessThanOrderByIdAsc(
releaseMessage.getMessage(), releaseMessage.getId());
releaseMessageRepository.delete(messages);
releaseMessageRepository.deleteAll(messages);
hasMore = messages.size() == 100;
messages.forEach(toRemove -> Tracer.logEvent(
......
......@@ -31,7 +31,7 @@ public class AppService {
@Transactional
public void delete(long id, String operator) {
App app = appRepository.findOne(id);
App app = appRepository.findById(id).orElse(null);
if (app == null) {
return;
}
......
......@@ -40,7 +40,7 @@ public class ClusterService {
}
public Cluster findOne(long clusterId) {
return clusterRepository.findOne(clusterId);
return clusterRepository.findById(clusterId).orElse(null);
}
public List<Cluster> findParentClusters(String appId) {
......@@ -85,7 +85,7 @@ public class ClusterService {
@Transactional
public void delete(long id, String operator) {
Cluster cluster = clusterRepository.findOne(id);
Cluster cluster = clusterRepository.findById(id).orElse(null);
if (cluster == null) {
throw new BadRequestException("cluster not exist");
}
......
......@@ -41,7 +41,7 @@ public class InstanceService {
}
public List<Instance> findInstancesByIds(Set<Long> instanceIds) {
Iterable<Instance> instances = instanceRepository.findAll(instanceIds);
Iterable<Instance> instances = instanceRepository.findAllById(instanceIds);
if (instances == null) {
return Collections.emptyList();
}
......@@ -159,7 +159,7 @@ public class InstanceService {
@Transactional
public InstanceConfig updateInstanceConfig(InstanceConfig instanceConfig) {
InstanceConfig existedInstanceConfig = instanceConfigRepository.findOne(instanceConfig.getId());
InstanceConfig existedInstanceConfig = instanceConfigRepository.findById(instanceConfig.getId()).orElse(null);
Preconditions.checkArgument(existedInstanceConfig != null, String.format(
"Instance config %d doesn't exist", instanceConfig.getId()));
......
......@@ -38,7 +38,7 @@ public class ItemService {
@Transactional
public Item delete(long id, String operator) {
Item item = itemRepository.findOne(id);
Item item = itemRepository.findById(id).orElse(null);
if (item == null) {
throw new IllegalArgumentException("item not exist. ID:" + id);
}
......@@ -81,7 +81,7 @@ public class ItemService {
}
public Item findOne(long itemId) {
Item item = itemRepository.findOne(itemId);
Item item = itemRepository.findById(itemId).orElse(null);
return item;
}
......@@ -147,7 +147,7 @@ public class ItemService {
@Transactional
public Item update(Item item) {
checkItemValueLength(item.getNamespaceId(), item.getValue());
Item managedItem = itemRepository.findOne(item.getId());
Item managedItem = itemRepository.findById(item.getId()).orElse(null);
BeanUtils.copyEntityProperties(item, managedItem);
managedItem = itemRepository.save(managedItem);
......
......@@ -67,7 +67,7 @@ public class NamespaceService {
public Namespace findOne(Long namespaceId) {
return namespaceRepository.findOne(namespaceId);
return namespaceRepository.findById(namespaceId).orElse(null);
}
public Namespace findOne(String appId, String clusterName, String namespaceName) {
......
......@@ -64,7 +64,7 @@ public class ReleaseService {
private ItemSetService itemSetService;
public Release findOne(long releaseId) {
return releaseRepository.findOne(releaseId);
return releaseRepository.findById(releaseId).orElse(null);
}
......@@ -73,7 +73,7 @@ public class ReleaseService {
}
public List<Release> findByReleaseIds(Set<Long> releaseIds) {
Iterable<Release> releases = releaseRepository.findAll(releaseIds);
Iterable<Release> releases = releaseRepository.findAllById(releaseIds);
if (releases == null) {
return Collections.emptyList();
}
......@@ -397,7 +397,7 @@ public class ReleaseService {
String clusterName = release.getClusterName();
String namespaceName = release.getNamespaceName();
PageRequest page = new PageRequest(0, 2);
PageRequest page = PageRequest.of(0, 2);
List<Release> twoLatestActiveReleases = findActiveReleases(appId, clusterName, namespaceName, page);
if (twoLatestActiveReleases == null || twoLatestActiveReleases.size() < 2) {
throw new BadRequestException(String.format(
......
package com.ctrip.framework.apollo.biz;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
......@@ -10,8 +10,7 @@ import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
@Rollback
@Transactional
@WebIntegrationTest(randomPort = true)
@SpringApplicationConfiguration(classes = BizTestConfiguration.class)
@SpringBootTest(classes = BizTestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public abstract class AbstractIntegrationTest {
}
......@@ -77,4 +77,4 @@ public class BizConfigTest {
assertEquals(someValidValue, bizConfig.checkInt(someValidValue, Integer.MIN_VALUE, Integer.MAX_VALUE,
someDefaultValue));
}
}
\ No newline at end of file
}
......@@ -51,7 +51,7 @@ public class AppRepositoryTest extends AbstractIntegrationTest{
Assert.assertEquals(1, appRepository.count());
appRepository.delete(app.getId());
appRepository.deleteById(app.getId());
Assert.assertEquals(0, appRepository.count());
}
......
......@@ -119,7 +119,7 @@ public class InstanceServiceTest extends AbstractIntegrationTest {
String someConfigClusterName = "someConfigClusterName";
String someConfigNamespaceName = "someConfigNamespaceName";
Date someValidDate = new Date();
Pageable pageable = new PageRequest(0, 10);
Pageable pageable = PageRequest.of(0, 10);
String someReleaseKey = "someReleaseKey";
Calendar calendar = Calendar.getInstance();
......@@ -165,7 +165,7 @@ public class InstanceServiceTest extends AbstractIntegrationTest {
someConfigNamespaceName, someReleaseKey, someValidDate);
Page<Instance> result = instanceService.findInstancesByNamespace(someConfigAppId,
someConfigClusterName, someConfigNamespaceName, new PageRequest(0, 10));
someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
assertEquals(Lists.newArrayList(someInstance, anotherInstance), result.getContent());
}
......@@ -197,9 +197,9 @@ public class InstanceServiceTest extends AbstractIntegrationTest {
someConfigNamespaceName, someReleaseKey, someValidDate);
Page<Instance> result = instanceService.findInstancesByNamespaceAndInstanceAppId(someAppId,
someConfigAppId, someConfigClusterName, someConfigNamespaceName, new PageRequest(0, 10));
someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
Page<Instance> anotherResult = instanceService.findInstancesByNamespaceAndInstanceAppId(anotherAppId,
someConfigAppId, someConfigClusterName, someConfigNamespaceName, new PageRequest(0, 10));
someConfigAppId, someConfigClusterName, someConfigNamespaceName, PageRequest.of(0, 10));
assertEquals(Lists.newArrayList(someInstance), result.getContent());
assertEquals(Lists.newArrayList(anotherInstance), anotherResult.getContent());
......
......@@ -28,7 +28,7 @@ public class NamespaceBranchServiceTest extends AbstractIntegrationTest {
private String testNamespace = "application";
private String testBranchName = "child-cluster";
private String operator = "apollo";
private Pageable pageable = new PageRequest(0, 10);
private Pageable pageable = PageRequest.of(0, 10);
@Test
@Sql(scripts = "/sql/namespace-branch-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
......
......@@ -64,19 +64,19 @@ public class NamespaceServiceIntegrationTest extends AbstractIntegrationTest {
namespaceService.deleteNamespace(namespace, testUser);
List<Item> items = itemService.findItemsWithoutOrdered(testApp, testCluster, testPrivateNamespace);
List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace);
List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster);
InstanceConfig instanceConfig = instanceConfigRepository.findOne(1L);
InstanceConfig instanceConfig = instanceConfigRepository.findById(1L).orElse(null);
List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster,
testPrivateNamespace,
new PageRequest(0, 10));
PageRequest.of(0, 10));
List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster,
testPrivateNamespace,
new PageRequest(0, 10));
PageRequest.of(0, 10));
Page<ReleaseHistory> releaseHistories =
releaseHistoryService
.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
assertEquals(0, items.size());
assertEquals(0, commits.size());
......
......@@ -38,7 +38,7 @@ public class NamespaceServiceTest extends AbstractUnitTest {
@Test(expected = BadRequestException.class)
public void testFindPublicAppNamespaceWithWrongNamespace() {
Pageable page = new PageRequest(0, 10);
Pageable page = PageRequest.of(0, 10);
when(appNamespaceService.findPublicNamespaceByName(testPublicAppNamespace)).thenReturn(null);
......@@ -59,7 +59,7 @@ public class NamespaceServiceTest extends AbstractUnitTest {
MockBeanFactory.mockNamespace("app2", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
Pageable page = new PageRequest(0, 10);
Pageable page = PageRequest.of(0, 10);
when(namespaceRepository.findByNamespaceName(testPublicAppNamespace, page))
.thenReturn(Arrays.asList(firstParentNamespace, secondParentNamespace));
......
......@@ -36,7 +36,7 @@ public class ReleaseCreationTest extends AbstractIntegrationTest {
private String testApp = "test";
private String testNamespace = "application";
private String operator = "apollo";
private Pageable pageable = new PageRequest(0, 10);
private Pageable pageable = PageRequest.of(0, 10);
@Test
@Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
......
......@@ -9,6 +9,7 @@ import com.ctrip.framework.apollo.biz.entity.Release;
import com.ctrip.framework.apollo.biz.repository.ReleaseRepository;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import java.util.Optional;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
......@@ -65,13 +66,13 @@ public class ReleaseServiceTest extends AbstractUnitTest {
secondRelease.setNamespaceName(namespaceName);
secondRelease.setAbandoned(false);
pageRequest = new PageRequest(0, 2);
pageRequest = PageRequest.of(0, 2);
}
@Test(expected = BadRequestException.class)
public void testNamespaceNotExist() {
when(releaseRepository.findOne(releaseId)).thenReturn(firstRelease);
when(releaseRepository.findById(releaseId)).thenReturn(Optional.of(firstRelease));
releaseService.rollback(releaseId, user);
}
......@@ -79,7 +80,7 @@ public class ReleaseServiceTest extends AbstractUnitTest {
@Test(expected = BadRequestException.class)
public void testHasNoRelease() {
when(releaseRepository.findOne(releaseId)).thenReturn(firstRelease);
when(releaseRepository.findById(releaseId)).thenReturn(Optional.of(firstRelease));
when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId,
clusterName,
namespaceName,
......@@ -92,7 +93,7 @@ public class ReleaseServiceTest extends AbstractUnitTest {
@Test
public void testRollback() {
when(releaseRepository.findOne(releaseId)).thenReturn(firstRelease);
when(releaseRepository.findById(releaseId)).thenReturn(Optional.of(firstRelease));
when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId,
clusterName,
namespaceName,
......@@ -166,7 +167,7 @@ public class ReleaseServiceTest extends AbstractUnitTest {
List<Release> someReleases = Lists.newArrayList(someRelease, anotherRelease);
Set<Long> someReleaseIds = Sets.newHashSet(someReleaseId, anotherReleaseId);
when(releaseRepository.findAll(someReleaseIds)).thenReturn(someReleases);
when(releaseRepository.findAllById(someReleaseIds)).thenReturn(someReleases);
List<Release> result = releaseService.findByReleaseIds(someReleaseIds);
......
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true
......
......@@ -6,7 +6,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.ConfigFileChangeListener;
import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.model.ConfigFileChangeEvent;
......
......@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.internals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
......@@ -12,11 +11,9 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.Apollo;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
......
......@@ -20,7 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
......@@ -36,7 +36,7 @@ public class BootstrapConfigTest {
private static final String FX_APOLLO_NAMESPACE = "FX.apollo";
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithConditionalOnProperty.class)
@SpringBootTest(classes = ConfigurationWithConditionalOnProperty.class)
@DirtiesContext
public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOn extends
AbstractSpringIntegrationTest {
......@@ -90,7 +90,7 @@ public class BootstrapConfigTest {
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithConditionalOnProperty.class)
@SpringBootTest(classes = ConfigurationWithConditionalOnProperty.class)
@DirtiesContext
public static class TestWithBootstrapEnabledAndNamespacesAndConditionalOn extends
AbstractSpringIntegrationTest {
......@@ -132,7 +132,7 @@ public class BootstrapConfigTest {
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithConditionalOnProperty.class)
@SpringBootTest(classes = ConfigurationWithConditionalOnProperty.class)
@DirtiesContext
public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOnFailed extends
AbstractSpringIntegrationTest {
......@@ -168,7 +168,7 @@ public class BootstrapConfigTest {
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithoutConditionalOnProperty.class)
@SpringBootTest(classes = ConfigurationWithoutConditionalOnProperty.class)
@DirtiesContext
public static class TestWithBootstrapEnabledAndDefaultNamespacesAndConditionalOff extends
AbstractSpringIntegrationTest {
......@@ -202,7 +202,7 @@ public class BootstrapConfigTest {
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithConditionalOnProperty.class)
@SpringBootTest(classes = ConfigurationWithConditionalOnProperty.class)
@DirtiesContext
public static class TestWithBootstrapDisabledAndDefaultNamespacesAndConditionalOn extends
AbstractSpringIntegrationTest {
......@@ -234,7 +234,7 @@ public class BootstrapConfigTest {
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(ConfigurationWithoutConditionalOnProperty.class)
@SpringBootTest(classes = ConfigurationWithoutConditionalOnProperty.class)
@DirtiesContext
public static class TestWithBootstrapDisabledAndDefaultNamespacesAndConditionalOff extends
AbstractSpringIntegrationTest {
......
......@@ -30,17 +30,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-spectator</artifactId>
<!-- duplicated with spring-security-core -->
<exclusions>
<exclusion>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
......
package com.ctrip.framework.apollo.common.controller;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
......
......@@ -3,7 +3,7 @@ package com.ctrip.framework.apollo.common.controller;
import com.google.common.collect.Lists;
import com.google.gson.GsonBuilder;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
......
package com.ctrip.framework.apollo.common.controller;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.MimeMappings;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.MimeMappings;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.http.MediaType;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter implements EmbeddedServletContainerCustomizer {
public class WebMvcConfig implements WebMvcConfigurer, WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
PageableHandlerMethodArgumentResolver pageResolver =
new PageableHandlerMethodArgumentResolver();
pageResolver.setFallbackPageable(new PageRequest(0, 10));
pageResolver.setFallbackPageable(PageRequest.of(0, 10));
argumentResolvers.add(pageResolver);
}
......@@ -32,9 +32,9 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter implements EmbeddedSer
}
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
public void customize(TomcatServletWebServerFactory factory) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("html", "text/html;charset=utf-8");
container.setMimeMappings(mappings );
factory.setMimeMappings(mappings );
}
}
package com.ctrip.framework.apollo.common.customize;
import org.apache.catalina.connector.Connector;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http11.Http11NioProtocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Component
public class TomcatContainerCustomizer implements EmbeddedServletContainerCustomizer {
private static final Logger logger = LoggerFactory.getLogger(TomcatContainerCustomizer.class);
private static final String TOMCAT_ACCEPTOR_COUNT = "server.tomcat.accept-count";
@Autowired
private Environment environment;
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
return;
}
if (!environment.containsProperty(TOMCAT_ACCEPTOR_COUNT)) {
return;
}
TomcatEmbeddedServletContainerFactory tomcat =
(TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof Http11NioProtocol) {
Http11NioProtocol http = (Http11NioProtocol) handler;
int acceptCount = Integer.parseInt(environment.getProperty(TOMCAT_ACCEPTOR_COUNT));
http.setBacklog(acceptCount);
logger.info("Setting tomcat accept count to {}", acceptCount);
}
}
});
}
}
......@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
......@@ -20,7 +21,7 @@ import javax.persistence.PreUpdate;
public abstract class BaseEntity {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private long id;
......
spring.http.converters.preferred-json-mapper=gson
# DataSource
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.validationInterval=5000
spring.datasource.initSQL=set names utf8mb4
spring.datasource.hikari.connectionInitSql=set names utf8mb4
# Naming strategy
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.globally_quoted_identifiers=true
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
# Tomcat configuration
server.tomcat.accept-count=5000
# Increase tomcat header size for longer GET query parameter, should be n * 1024
server.tomcat.maxHttpHeaderSize=10240
server.max-http-header-size=10240
# Spring Boot 2.0
management.endpoints.web.base-path=/
_ _ _
/ \ _ __ ___ | | | ___
/ _ \ | '_ \ / _ \| | |/ _ \
/ ___ \| |_) | (_) | | | (_) |
/_/ \_\ .__/ \___/|_|_|\___/
|_|
:: Spring Boot :: ${spring-boot.formatted-version}
......@@ -23,16 +23,14 @@
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<exclusions>
<exclusion>
<artifactId>
spring-cloud-starter-archaius
</artifactId>
<artifactId>spring-cloud-starter-netflix-archaius</artifactId>
<groupId>org.springframework.cloud</groupId>
</exclusion>
<exclusion>
<artifactId>spring-cloud-starter-ribbon</artifactId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<groupId>org.springframework.cloud</groupId>
</exclusion>
<exclusion>
......
......@@ -24,7 +24,7 @@ public class ConfigServiceHealthIndicator implements HealthIndicator {
}
private int check() {
PageRequest pageable = new PageRequest(0, 1);
PageRequest pageable = PageRequest.of(0, 1);
appService.findAll(pageable);
return 0;
}
......
package com.ctrip.framework.apollo.configservice;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* Entry point for traditional web app
......
......@@ -186,7 +186,7 @@ public class AppNamespaceServiceWithCache implements InitializingBean {
}
List<List<Long>> partitionIds = Lists.partition(ids, 500);
for (List<Long> toRebuild : partitionIds) {
Iterable<AppNamespace> appNamespaces = appNamespaceRepository.findAll(toRebuild);
Iterable<AppNamespace> appNamespaces = appNamespaceRepository.findAllById(toRebuild);
if (appNamespaces == null) {
continue;
......
......@@ -2,6 +2,8 @@ eureka:
instance:
hostname: ${hostname:localhost}
preferIpAddress: true
status-page-url-path: /info
health-check-url-path: /health
server:
peerEurekaNodesUpdateIntervalMs: 60000
enableSelfPreservation: false
......@@ -12,13 +14,7 @@ eureka:
enabled: true
eurekaServiceUrlPollIntervalSeconds: 60
endpoints:
health:
sensitive: false
management:
security:
enabled: false
health:
status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
......@@ -2,4 +2,5 @@
spring.application.name= apollo-configservice
ctrip.appid= 100003171
server.port= 8080
logging.file= /opt/logs/100003171/apollo-configservice.log
\ No newline at end of file
logging.file= /opt/logs/100003171/apollo-configservice.log
spring.jmx.default-domain = apollo-configservice
......@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s
declare -i total_time=0
printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "Coyote")" != "" ]];
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=1
......
......@@ -14,9 +14,9 @@ import com.ctrip.framework.apollo.biz.utils.ReleaseKeyGenerator;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
......@@ -36,8 +36,7 @@ import javax.annotation.PostConstruct;
* @author Jason Song(song_s@ctrip.com)
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = AbstractBaseIntegrationTest.TestConfiguration.class)
@WebIntegrationTest(randomPort = true)
@SpringBootTest(classes = AbstractBaseIntegrationTest.TestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public abstract class AbstractBaseIntegrationTest {
@Autowired
private ReleaseMessageRepository releaseMessageRepository;
......@@ -46,7 +45,7 @@ public abstract class AbstractBaseIntegrationTest {
private Gson gson = new Gson();
RestTemplate restTemplate = new TestRestTemplate();
protected RestTemplate restTemplate = (new TestRestTemplate()).getRestTemplate();
@PostConstruct
private void postConstruct() {
......@@ -57,7 +56,7 @@ public abstract class AbstractBaseIntegrationTest {
int port;
protected String getHostUrl() {
return "http://localhost:" + port;
return "localhost:" + port;
}
@Configuration
......
......@@ -72,7 +72,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
public void testQueryConfigAsProperties() throws Exception {
ResponseEntity<String> response =
restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace);
String result = response.getBody();
......@@ -96,12 +96,12 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response =
restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}", String.class,
.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}", String.class,
getHostUrl(), someAppId, someDefaultCluster, ConfigConsts.NAMESPACE_APPLICATION, grayClientIp);
ResponseEntity<String> anotherResponse =
restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}", String.class,
.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}", String.class,
getHostUrl(), someAppId, someDefaultCluster, ConfigConsts.NAMESPACE_APPLICATION, nonGrayClientIp);
String result = response.getBody();
......@@ -123,7 +123,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response =
restTemplate
.getForEntity(
"{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
"http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC);
......@@ -140,7 +140,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
public void testQueryConfigAsJson() throws Exception {
ResponseEntity<String> response =
restTemplate
.getForEntity("{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}", String.class,
.getForEntity("http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace);
Map<String, String> configs = gson.fromJson(response.getBody(), mapResponseType);
......@@ -155,7 +155,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
public void testQueryConfigAsJsonWithIncorrectCase() throws Exception {
ResponseEntity<String> response =
restTemplate
.getForEntity("{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}", String.class,
.getForEntity("http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace.toUpperCase());
Map<String, String> configs = gson.fromJson(response.getBody(), mapResponseType);
......@@ -172,7 +172,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response =
restTemplate
.getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
"http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC);
......@@ -191,7 +191,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response =
restTemplate
.getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
"http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}",
String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), someDC);
......@@ -219,14 +219,14 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response =
restTemplate
.getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
"http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, grayClientIp);
ResponseEntity<String> anotherResponse =
restTemplate
.getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
"http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, nonGrayClientIp);
......@@ -260,14 +260,14 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> response =
restTemplate
.getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
"http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), grayClientIp);
ResponseEntity<String> anotherResponse =
restTemplate
.getForEntity(
"{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
"http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}",
String.class,
getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), nonGrayClientIp);
......@@ -290,7 +290,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
public void testConfigChanged() throws Exception {
ResponseEntity<String> response =
restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace);
String result = response.getBody();
......@@ -312,7 +312,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> anotherResponse =
restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace);
assertEquals(response.getBody(), anotherResponse.getBody());
......@@ -325,7 +325,7 @@ public class ConfigFileControllerIntegrationTest extends AbstractBaseIntegration
ResponseEntity<String> newResponse =
restTemplate
.getForEntity("{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}", String.class,
getHostUrl(), someAppId, someCluster, someNamespace);
result = newResponse.getBody();
......
......@@ -57,7 +57,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop);
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, defaultNamespace);
......@@ -76,7 +76,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
periodicSendMessage(executorService, assembleKey(someAppId, someCluster, defaultNamespace), stop);
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, defaultNamespace + ".properties");
......@@ -98,7 +98,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, namespace);
......@@ -115,7 +115,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespaceWithNotificationIdNull() throws Exception {
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, defaultNamespace);
......@@ -132,7 +132,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
public void testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated() throws Exception {
long someOutDatedNotificationId = 1;
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, defaultNamespace, someOutDatedNotificationId);
......@@ -153,7 +153,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, somePublicNamespace);
......@@ -177,7 +177,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, somePublicNamespace, someDC);
......@@ -201,7 +201,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
ResponseEntity<ApolloConfigNotification> result = restTemplate
.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&dataCenter={dataCenter}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, somePublicNamespace + ".properties", someDC);
......@@ -220,7 +220,7 @@ public class NotificationControllerIntegrationTest extends AbstractBaseIntegrati
public void testPollNotificationWithPublicNamespaceWithNotificationIdOutDated() throws Exception {
long someOutDatedNotificationId = 1;
ResponseEntity<ApolloConfigNotification> result = restTemplate.getForEntity(
"{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}",
"http://{baseurl}/notifications?appId={appId}&cluster={clusterName}&namespace={namespace}&notificationId={notificationId}",
ApolloConfigNotification.class,
getHostUrl(), someAppId, someCluster, somePublicNamespace, someOutDatedNotificationId);
......
......@@ -133,7 +133,7 @@ public class AppNamespaceServiceWithCacheTest {
// Add 1 private namespace and 1 public namespace
when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0)).thenReturn(Lists
.newArrayList(somePrivateAppNamespace, somePublicAppNamespace));
when(appNamespaceRepository.findAll(Lists.newArrayList(somePrivateNamespaceId,
when(appNamespaceRepository.findAllById(Lists.newArrayList(somePrivateNamespaceId,
somePublicNamespaceId))).thenReturn(Lists.newArrayList(somePrivateAppNamespace,
somePublicAppNamespace));
......@@ -165,7 +165,7 @@ public class AppNamespaceServiceWithCacheTest {
when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(somePublicNamespaceId))
.thenReturn(Lists.newArrayList(anotherPrivateAppNamespace, yetAnotherPrivateAppNamespace,
anotherPublicAppNamespace));
when(appNamespaceRepository.findAll(appNamespaceIds)).thenReturn(allAppNamespaces);
when(appNamespaceRepository.findAllById(appNamespaceIds)).thenReturn(allAppNamespaces);
scanIntervalTimeUnit.sleep(sleepInterval);
......@@ -213,7 +213,7 @@ public class AppNamespaceServiceWithCacheTest {
(somePublicAppNamespace.getDataChangeLastModifiedTime(), 1));
// Delete 1 private and 1 public
when(appNamespaceRepository.findAll(appNamespaceIds)).thenReturn(Lists.newArrayList
when(appNamespaceRepository.findAllById(appNamespaceIds)).thenReturn(Lists.newArrayList
(somePrivateAppNamespaceNew, yetAnotherPrivateAppNamespaceNew, somePublicAppNamespaceNew));
scanIntervalTimeUnit.sleep(sleepInterval);
......
......@@ -64,4 +64,4 @@ public class CaseInsensitiveMapWrapperTest {
verify(someMap, times(1)).remove(someKey.toLowerCase());
}
}
\ No newline at end of file
}
spring.datasource.url = jdbc:h2:mem:~/apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true
spring.jpa.properties.hibernate.show_sql=false
......
......@@ -2,20 +2,15 @@ eureka:
instance:
hostname: ${hostname:localhost}
preferIpAddress: true
status-page-url-path: /info
health-check-url-path: /health
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8080/eureka/
healthcheck:
enabled: true
endpoints:
health:
sensitive: false
management:
security:
enabled: false
health:
status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
......@@ -16,7 +16,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
......@@ -26,7 +26,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* Create by zhangzheng on 8/16/18 Email:zhangzheng@youzan.com
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = TestConfiguration.class)
@SpringBootTest(classes = TestConfiguration.class)
public class ApolloMockServerSpringIntegrationTest {
private static final String otherNamespace = "otherNamespace";
......
......@@ -7,6 +7,7 @@ import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;
......@@ -18,7 +19,7 @@ import javax.persistence.Table;
@Table(name = "ConsumerAudit")
public class ConsumerAudit {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private long id;
......
......@@ -109,7 +109,7 @@ public class ConsumerService {
}
public Consumer getConsumerByConsumerId(long consumerId) {
return consumerRepository.findOne(consumerId);
return consumerRepository.findById(consumerId).orElse(null);
}
public List<ConsumerRole> assignNamespaceRoleToConsumer(String token, String appId, String namespaceName) {
......@@ -177,7 +177,7 @@ public class ConsumerService {
@Transactional
public void createConsumerAudits(Iterable<ConsumerAudit> consumerAudits) {
consumerAuditRepository.save(consumerAudits);
consumerAuditRepository.saveAll(consumerAudits);
}
@Transactional
......
......@@ -11,7 +11,7 @@ import com.ctrip.framework.apollo.tracer.Tracer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
......
......@@ -7,7 +7,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
......
......@@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriTemplateHandler;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler;
import java.net.SocketTimeoutException;
......@@ -36,7 +36,7 @@ public class RetryableRestTemplate {
private Logger logger = LoggerFactory.getLogger(RetryableRestTemplate.class);
private UriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
private UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory();
private RestTemplate restTemplate;
......
......@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
......@@ -16,7 +17,7 @@ import javax.persistence.Table;
public class UserPO {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private long id;
@Column(name = "Username", nullable = false)
......
......@@ -77,7 +77,7 @@ public class FavoriteService {
public void deleteFavorite(long favoriteId) {
Favorite favorite = favoriteRepository.findOne(favoriteId);
Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null);
checkUserOperatePermission(favorite);
......@@ -85,7 +85,7 @@ public class FavoriteService {
}
public void adjustFavoriteToFirst(long favoriteId) {
Favorite favorite = favoriteRepository.findOne(favoriteId);
Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null);
checkUserOperatePermission(favorite);
......
......@@ -22,13 +22,12 @@ import java.util.Collections;
import java.util.EventListener;
import java.util.Map;
import javax.servlet.Filter;
import org.apache.tomcat.jdbc.pool.DataSource;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletListenerRegistrationBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
......@@ -38,13 +37,13 @@ import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.security.authentication.encoding.LdapShaPasswordEncoder;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
import org.springframework.security.provisioning.JdbcUserDetailsManager;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
......
......@@ -4,7 +4,7 @@ import com.ctrip.framework.apollo.openapi.filter.ConsumerAuthenticationFilter;
import com.ctrip.framework.apollo.openapi.util.ConsumerAuditUtil;
import com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......
......@@ -7,8 +7,8 @@ import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
......
......@@ -60,7 +60,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
rolePermission.setDataChangeLastModifiedBy(createdRole.getDataChangeLastModifiedBy());
return rolePermission;
});
rolePermissionRepository.save(rolePermissions);
rolePermissionRepository.saveAll(rolePermissions);
}
return createdRole;
......@@ -93,7 +93,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
return userRole;
});
userRoleRepository.save(toCreate);
userRoleRepository.saveAll(toCreate);
return toAssignUserIds;
}
......@@ -114,7 +114,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
userRole.setDataChangeLastModifiedBy(operatorUserId);
}
userRoleRepository.save(existedUserRoles);
userRoleRepository.saveAll(existedUserRoles);
}
/**
......@@ -218,7 +218,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
targetId);
}
Iterable<Permission> results = permissionRepository.save(permissions);
Iterable<Permission> results = permissionRepository.saveAll(permissions);
return FluentIterable.from(results).toSet();
}
......
......@@ -4,7 +4,9 @@ spring:
profiles:
active: ${apollo_profile}
resources:
cache-period: 3600
cache:
cachecontrol:
max-age: 3600
server:
port: 8080
......@@ -13,12 +15,7 @@ logging:
path: /opt/logs/100003173
file: ${logging.path}/apollo-portal.log
endpoints:
health:
sensitive: false
management:
security:
enabled: false
health:
status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
......
......@@ -99,7 +99,7 @@ declare -i max_counter=48 # 48*5=240s
declare -i total_time=0
printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "Coyote")" != "" ]];
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=1
......
......@@ -72,4 +72,4 @@ public class ConsumerAuthenticationFilterTest {
verify(consumerAuditUtil, never()).audit(eq(request), anyLong());
verify(filterChain, never()).doFilter(request, response);
}
}
\ No newline at end of file
}
......@@ -16,6 +16,7 @@ import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.UserService;
import com.ctrip.framework.apollo.portal.util.RoleUtils;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
......@@ -97,10 +98,10 @@ public class ConsumerServiceTest extends AbstractUnitTest {
long someConsumerId = 1;
Consumer someConsumer = mock(Consumer.class);
when(consumerRepository.findOne(someConsumerId)).thenReturn(someConsumer);
when(consumerRepository.findById(someConsumerId)).thenReturn(Optional.of(someConsumer));
assertEquals(someConsumer, consumerService.getConsumerByConsumerId(someConsumerId));
verify(consumerRepository, times(1)).findOne(someConsumerId);
verify(consumerRepository, times(1)).findById(someConsumerId);
}
@Test
......@@ -131,7 +132,7 @@ public class ConsumerServiceTest extends AbstractUnitTest {
Date generationTime = new Date();
Consumer consumer = mock(Consumer.class);
when(consumerRepository.findOne(someConsumerId)).thenReturn(consumer);
when(consumerRepository.findById(someConsumerId)).thenReturn(Optional.of(consumer));
when(consumer.getAppId()).thenReturn(someConsumerAppId);
when(consumerService.generateToken(someConsumerAppId, generationTime, someTokenSalt))
.thenReturn(someToken);
......
......@@ -88,4 +88,4 @@ public class ConsumerAuditUtilTest {
assertEquals(someConsumerId, audit.getConsumerId());
}
}
\ No newline at end of file
}
......@@ -76,4 +76,4 @@ public class ConsumerAuthUtilTest {
consumerAuthUtil.retrieveConsumerId(request);
}
}
\ No newline at end of file
}
......@@ -3,9 +3,9 @@ package com.ctrip.framework.apollo.portal;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
......@@ -13,11 +13,10 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = PortalApplication.class)
@WebIntegrationTest(randomPort = true)
@SpringBootTest(classes = PortalApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public abstract class AbstractIntegrationTest {
RestTemplate restTemplate = new TestRestTemplate();
protected RestTemplate restTemplate = (new TestRestTemplate()).getRestTemplate();
@PostConstruct
private void postConstruct() {
......
......@@ -35,7 +35,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
Favorite favorite = instanceOfFavorite(testUser, testApp);
favoriteService.addFavorite(favorite);
List<Favorite> createdFavorites = favoriteService.search(testUser, testApp, new PageRequest(0, 10));
List<Favorite> createdFavorites = favoriteService.search(testUser, testApp, PageRequest.of(0, 10));
Assert.assertEquals(1, createdFavorites.size());
......@@ -57,7 +57,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByUserId() {
List<Favorite> favorites = favoriteService.search(testUser, null, new PageRequest(0, 10));
List<Favorite> favorites = favoriteService.search(testUser, null, PageRequest.of(0, 10));
Assert.assertEquals(4, favorites.size());
}
......@@ -65,7 +65,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByAppId() {
List<Favorite> favorites = favoriteService.search(null, "test0621-04", new PageRequest(0, 10));
List<Favorite> favorites = favoriteService.search(null, "test0621-04", PageRequest.of(0, 10));
Assert.assertEquals(3, favorites.size());
}
......@@ -73,7 +73,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchByAppIdAndUserId() {
List<Favorite> favorites = favoriteService.search(testUser, "test0621-04", new PageRequest(0, 10));
List<Favorite> favorites = favoriteService.search(testUser, "test0621-04", PageRequest.of(0, 10));
Assert.assertEquals(1, favorites.size());
}
......@@ -81,7 +81,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
@Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testSearchWithErrorParams() {
favoriteService.search(null, null, new PageRequest(0, 10));
favoriteService.search(null, null, PageRequest.of(0, 10));
}
@Test
......@@ -90,7 +90,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
public void testDeleteFavorite() {
long legalFavoriteId = 21L;
favoriteService.deleteFavorite(legalFavoriteId);
Assert.assertNull(favoriteRepository.findOne(legalFavoriteId));
Assert.assertNull(favoriteRepository.findById(legalFavoriteId).orElse(null));
}
@Test(expected = BadRequestException.class)
......@@ -99,7 +99,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
public void testDeleteFavoriteFail() {
long anotherPersonFavoriteId = 23L;
favoriteService.deleteFavorite(anotherPersonFavoriteId);
Assert.assertNull(favoriteRepository.findOne(anotherPersonFavoriteId));
Assert.assertNull(favoriteRepository.findById(anotherPersonFavoriteId).orElse(null));
}
@Test(expected = BadRequestException.class)
......@@ -117,7 +117,7 @@ public class FavoriteServiceTest extends AbstractIntegrationTest {
long toAdjustFavoriteId = 20;
favoriteService.adjustFavoriteToFirst(toAdjustFavoriteId);
List<Favorite> favorites = favoriteService.search(testUser, null, new PageRequest(0, 10));
List<Favorite> favorites = favoriteService.search(testUser, null, PageRequest.of(0, 10));
Favorite firstFavorite = favorites.get(0);
Favorite secondFavorite = favorites.get(1);
......
......@@ -67,7 +67,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest {
Permission created = rolePermissionService.createPermission(somePermission);
Permission createdFromDB = permissionRepository.findOne(created.getId());
Permission createdFromDB = permissionRepository.findById(created.getId()).orElse(null);
assertEquals(somePermissionType, createdFromDB.getPermissionType());
assertEquals(someTargetId, createdFromDB.getTargetId());
......@@ -103,7 +103,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest {
FluentIterable.from(created).transform(BaseEntity::getId)
.toSet();
Iterable<Permission> permissionsFromDB = permissionRepository.findAll(permissionIds);
Iterable<Permission> permissionsFromDB = permissionRepository.findAllById(permissionIds);
Set<String> targetIds = Sets.newHashSet();
Set<String> permissionTypes = Sets.newHashSet();
......@@ -145,7 +145,7 @@ public class RolePermissionServiceTest extends AbstractIntegrationTest {
Role created = rolePermissionService.createRoleWithPermissions(role, permissionIds);
Role createdFromDB = roleRepository.findOne(created.getId());
Role createdFromDB = roleRepository.findById(created.getId()).orElse(null);
List<RolePermission> rolePermissions =
rolePermissionRepository.findByRoleIdIn(Sets.newHashSet(createdFromDB.getId()));
......
spring.datasource.url = jdbc:h2:mem:~/apolloportaldb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.show_sql=false
spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true
......@@ -14,14 +14,7 @@ apollo:
portal:
envs: local
endpoints:
health:
sensitive: false
management:
security:
enabled: false
health:
status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
......@@ -75,8 +75,9 @@
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>1.3.8.RELEASE</spring-boot.version>
<spring-cloud.version>1.2.3.RELEASE</spring-cloud.version>
<platform-bom.version>Cairo-SR4</platform-bom.version>
<spring-boot.version>2.0.5.RELEASE</spring-boot.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
<!-- Plugins Version -->
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
......@@ -287,18 +288,24 @@
<artifactId>h2</artifactId>
<version>1.4.191</version>
</dependency>
<!-- stick with mockito 1.x -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>
<!-- declare Spring BOMs in order -->
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>2.0.8.RELEASE</version>
<version>${platform-bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>1.2.3.RELEASE</version>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
......@@ -323,6 +330,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
......@@ -421,7 +434,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.5.RELEASE</version>
<version>1.3.8.RELEASE</version>
<executions>
<execution>
<goals>
......@@ -655,7 +668,7 @@
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>${spring-cloud.version}</version>
<exclusions>
<!-- already in java -->
......@@ -761,7 +774,7 @@
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>${spring-cloud.version}</version>
<exclusions>
<!-- already in java -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment