* fix performance test travis ci build

* support configurable performance parameters
This commit is contained in:
weiping 2018-10-26 17:17:43 +08:00 коммит произвёл GitHub
Родитель 32ca118495
Коммит bef0c2477d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 92 добавлений и 60 удалений

Просмотреть файл

@ -2,18 +2,24 @@ language: java
jdk:
- oraclejdk8
install: true
before_script:
- chmod +x ./src/libs/integration-test-setup.sh
- ./src/libs/integration-test-setup.sh > src/test/resources/application.properties
- cat src/test/resources/application.properties
script:
- mvn clean package
- set -o pipefail
- mvn -P travis-ci-test clean cobertura:cobertura-integration-test | grep -v "DEBUG"
- if [ "$TRAVIS_BRANCH" = "master" ]; then mvn -P performance-test clean verify; fi
after_success:
- bash <(curl -s https://codecov.io/bash)
- chmod +x ./src/libs/integration-test-setup.sh
- ./src/libs/integration-test-setup.sh > src/test/resources/application.properties
- cat src/test/resources/application.properties
jobs:
include:
- stage: test
script:
- mvn clean package
- set -o pipefail
- mvn -P travis-ci-test clean cobertura:cobertura-integration-test | grep -v "DEBUG"
- stage: performance-test
script:
- mvn -P performance-test clean verify
if: branch = master AND type != pull_request
- stage: code-coverage
script:
- bash <(curl -s https://codecov.io/bash)

15
pom.xml
Просмотреть файл

@ -325,12 +325,6 @@
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/**Test.java</include>
<include>**/**IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
@ -412,12 +406,19 @@
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/PerformanceCompare.java</include>
<include>PerformanceCompare.java</include>
</includes>
</configuration>
</plugin>

Просмотреть файл

@ -15,12 +15,14 @@ import com.microsoft.azure.spring.data.cosmosdb.performance.service.SdkService;
import com.microsoft.azure.spring.data.cosmosdb.performance.utils.Constants;
import com.microsoft.azure.spring.data.cosmosdb.performance.utils.DatabaseUtils;
import com.microsoft.azure.spring.data.cosmosdb.performance.utils.PerfDataProvider;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
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.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@ -29,23 +31,31 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static com.microsoft.azure.spring.data.cosmosdb.performance.utils.FunctionUtils.*;
import static org.assertj.core.api.Assertions.assertThat;
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = PerfConfiguration.class)
public class PerformanceCompare {
@Value("${perf.recursive.times:10}")
private int recurTimes;
@Value("${perf.batch.size:3}")
private int batchSize;
@Value("${perf.acceptance.percentage:10}")
private int acceptanceDiffPercentage;
private float acceptanceDiff;
@Autowired
private DocumentClient documentClient;
@Autowired
private PerfPersonRepository repository;
private static final int TIMES = 100;
private static final int BATCH_SIZE = 10;
private static final float ACCEPTANCE_DIFF = 0.1f;
private static boolean hasInit = false;
private static SdkService sdkService;
private static PerformanceReport report = new PerformanceReport();
@ -61,6 +71,10 @@ public class PerformanceCompare {
sdkService = new SdkService(documentClient, Constants.PERF_DATABASE_NAME, Constants.SDK_COLLECTION_NAME);
hasInit = true;
}
acceptanceDiff = (float) acceptanceDiffPercentage / 100;
log.info("Running performance test for {} time(s), batch size {} and acceptance diff {}.",
recurTimes, batchSize, acceptanceDiff);
}
@After
@ -76,124 +90,128 @@ public class PerformanceCompare {
@Test
public void saveOneRecordTest() {
final List<PerfPerson> personList = PerfDataProvider.getPerfData(TIMES);
final List<PerfPerson> personList = PerfDataProvider.getPerfData(recurTimes);
final long springCost = applyInputListFunc(personList, repository::save);
final long sdkCost = applyInputListFunc(personList, sdkService::save);
verifyResult(OperationType.SAVE_ONE, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.SAVE_ONE, springCost, sdkCost, acceptanceDiff);
}
@Test
public void saveMultipleRecordsTest() {
final List<Iterable<PerfPerson>> personList = PerfDataProvider.getMultiPerfData(TIMES, BATCH_SIZE);
final List<Iterable<PerfPerson>> personList = PerfDataProvider.getMultiPerfData(recurTimes, batchSize);
final long springCost = acceptInputListFunc(personList, repository::saveAll);
final long sdkCost = acceptInputListFunc(personList, sdkService::saveAll);
verifyResult(OperationType.SAVE_ALL, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.SAVE_ALL, springCost, sdkCost, acceptanceDiff);
}
@Test
public void deleteOneRecordTest() {
final List<PerfPerson> personList = prepareListData(TIMES);
final List<PerfPerson> personList = prepareListData(recurTimes);
final long springCost = acceptInputListFunc(personList, repository::delete);
final long sdkCost = acceptInputListFunc(personList, sdkService::delete);
verifyResult(OperationType.DELETE_ONE, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.DELETE_ONE, springCost, sdkCost, acceptanceDiff);
}
@Test
public void deleteAllRecordsTest() {
final List<Iterable<PerfPerson>> personList = prepareListBatchData(TIMES, BATCH_SIZE);
final List<Iterable<PerfPerson>> personList = prepareListBatchData(recurTimes, batchSize);
final long springCost = acceptInputListFunc(personList, repository::deleteAll);
final long sdkCost = acceptInputListFunc(personList, sdkService::deleteAll);
verifyResult(OperationType.DELETE_ALL, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.DELETE_ALL, springCost, sdkCost, acceptanceDiff);
}
@Test
public void findByIdTest() {
final List<String> idList = prepareListData(TIMES).stream().map(PerfPerson::getId).collect(Collectors.toList());
final List<String> idList = prepareListData(recurTimes).stream().map(PerfPerson::getId)
.collect(Collectors.toList());
final long springCost = applyInputListFunc(idList, repository::findById);
final long sdkCost = applyInputListFunc(idList, sdkService::findById);
verifyResult(OperationType.FIND_BY_ID, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.FIND_BY_ID, springCost, sdkCost, acceptanceDiff);
}
@Test
public void findByMultipleIdsTest() {
final List<Iterable<String>> idList = listBatchIds(TIMES, BATCH_SIZE);
final List<Iterable<String>> idList = listBatchIds(recurTimes, batchSize);
final long springCost = acceptInputListFunc(idList, repository::findAllById);
final long sdkCost = acceptInputListFunc(idList, sdkService::findAllById);
verifyResult(OperationType.FIND_BY_IDS, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.FIND_BY_IDS, springCost, sdkCost, acceptanceDiff);
}
@Test
public void findAllTest() {
prepareListData(TIMES);
prepareListData(recurTimes);
final long springCost = getSupplier(TIMES, repository::findAll);
final long sdkCost = getSupplier(TIMES, sdkService::findAll);
final long springCost = getSupplier(recurTimes, repository::findAll);
final long sdkCost = getSupplier(recurTimes, sdkService::findAll);
verifyResult(OperationType.FIND_ALL, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.FIND_ALL, springCost, sdkCost, acceptanceDiff);
}
@Test
public void deleteAllTest() {
final long springCost = getSupplier(TIMES, this::springDeleteAll);
final long sdkCost = getSupplier(TIMES, sdkService::deleteAll);
final long springCost = getSupplier(recurTimes, this::springDeleteAll);
final long sdkCost = getSupplier(recurTimes, sdkService::deleteAll);
verifyResult(OperationType.DELETE_ALL, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.DELETE_ALL, springCost, sdkCost, acceptanceDiff);
}
@Test
public void findBySortingTest() {
prepareListData(recurTimes);
final Sort sort = new Sort(Sort.Direction.ASC, "name");
final List<Sort> sortList = buildSortList(sort, TIMES);
final List<Sort> sortList = buildSortList(sort, recurTimes);
final long springCost = applyInputListFunc(sortList, repository::findAll);
final long sdkCost = applyInputListFunc(sortList, sdkService::searchDocuments);
verifyResult(OperationType.FIND_BY_SORT, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.FIND_BY_SORT, springCost, sdkCost, acceptanceDiff);
}
@Test
public void findByPagingTest() {
prepareListData(TIMES);
int pageSize = TIMES / 2;
prepareListData(recurTimes);
int pageSize = recurTimes / 2;
pageSize = pageSize >= 1 ? pageSize : 1;
final long springCost = runConsumerForTimes(TIMES, pageSize, this::queryTwoPages);
final long sdkCost = runConsumerForTimes(TIMES, pageSize, sdkService::queryTwoPages);
final long springCost = runConsumerForTimes(recurTimes, pageSize, this::queryTwoPages);
final long sdkCost = runConsumerForTimes(recurTimes, pageSize, sdkService::queryTwoPages);
verifyResult(OperationType.FIND_BY_PAGING, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.FIND_BY_PAGING, springCost, sdkCost, acceptanceDiff);
}
@Test
public void findByFieldTest() {
final List<PerfPerson> data = prepareListData(TIMES);
final List<PerfPerson> data = prepareListData(recurTimes);
final String name = data.get(TIMES / 2).getName();
final String name = data.get(recurTimes / 2).getName();
final long springCost = runFunctionForTimes(TIMES, name, repository::findByName);
final long sdkCost = runConsumerForTimes(TIMES, name, sdkService::findByName);
final long springCost = runFunctionForTimes(recurTimes, name, repository::findByName);
final long sdkCost = runConsumerForTimes(recurTimes, name, sdkService::findByName);
verifyResult(OperationType.FIND_BY_FIELD, springCost, sdkCost, ACCEPTANCE_DIFF);
verifyResult(OperationType.FIND_BY_FIELD, springCost, sdkCost, acceptanceDiff);
}
@Test
public void countTest() {
final long springCost = getSupplier(TIMES, repository::count);
final long sdkCost = getSupplier(TIMES, sdkService::count);
prepareListData(recurTimes);
report.addItem(new PerfItem(OperationType.COUNT, springCost, sdkCost, TIMES));
assertPerf(springCost, sdkCost, ACCEPTANCE_DIFF);
final long springCost = getSupplier(recurTimes, repository::count);
final long sdkCost = getSupplier(recurTimes, sdkService::count);
verifyResult(OperationType.COUNT, springCost, sdkCost, acceptanceDiff);
}
/**
@ -210,7 +228,7 @@ public class PerformanceCompare {
}
private void verifyResult(OperationType type, long timeCostSpring, long timeCostSdk, float acceptanceDiff) {
report.addItem(new PerfItem(type, timeCostSpring, timeCostSdk, TIMES));
report.addItem(new PerfItem(type, timeCostSpring, timeCostSdk, recurTimes));
assertPerf(timeCostSpring, timeCostSdk, acceptanceDiff);
}

Просмотреть файл

@ -1,4 +1,11 @@
cosmosdb.uri=${DOCUMENTDB_URI}
cosmosdb.key=${DOCUMENTDB_KEY}
#You can also use connection string instead of uri and key to connect to cosmos DB
#cosmosdb.connection-string=${DOCUMENTDB_CONNECTION_STRING}
# Performance test configurations
perf.recursive.times=10
perf.batch.size=3
perf.acceptance.percentage=10