Skip to content

Commit

Permalink
Refactor integration tests Spring Boot profiles by database
Browse files Browse the repository at this point in the history
 * Remove 'ci' profile
 * Split common database settings into a 'db' profile
 * Add new 'db-mysql' and 'db-hsql-mem' profiles
 * Update IntegrationTest ProfilesResolver to load one of the new profiles (default to in-memory HSQL)
 * Run MySQL tests during PR verification build on Travis
  • Loading branch information
mprimi committed Nov 14, 2017
1 parent c7967fd commit dd0b52a
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 51 deletions.
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,14 @@ configure(javaProjects) {
minHeapSize = "256m"
maxHeapSize = "2g"

// If the project is running on a CI server
if (System.getenv("CI") != null) {
systemProperty "CI", System.getenv("CI")
// Environment properties to be forwarded to the test runtime
[
"CI",
"INTEGRATION_TEST_DB",
].each { envVariableName ->
if (System.getenv(envVariableName) != null) {
systemProperty envVariableName, System.getenv(envVariableName)
}
}

reports.html.destination = file("${reporting.baseDir}/test/${task.name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
*/
package com.netflix.genie.web.controllers;

import com.google.common.collect.Sets;
import org.springframework.test.context.ActiveProfilesResolver;

import java.util.Set;

/**
* A class to switch the active profiles for integration tests based on environment variables.
*
Expand All @@ -27,21 +30,29 @@
*/
public class IntegrationTestActiveProfilesResolver implements ActiveProfilesResolver {

private static final String DB_SELECTOR_ENV_VARIABLE_NAME = "INTEGRATION_TEST_DB";
private static final String MYSQL = "mysql";
private static final String HSQL_MEM = "hsql-mem";
private final Set<String> knownDatabaseProfiles = Sets.newHashSet(
MYSQL,
HSQL_MEM
);

/**
* {@inheritDoc}
*/
@Override
public String[] resolve(final Class<?> testClass) {
final boolean isCI = Boolean.valueOf(System.getProperty("CI", "false"));
final boolean isTravis = Boolean.valueOf(System.getProperty("TRAVIS", "false"));
final String integrationTestDatabase = System.getProperty(DB_SELECTOR_ENV_VARIABLE_NAME, HSQL_MEM);

final String[] activeProfiles;
if (isCI || isTravis) {
activeProfiles = new String[]{"ci"};
} else {
activeProfiles = new String[]{"integration"};
if (!knownDatabaseProfiles.contains(integrationTestDatabase)) {
throw new IllegalStateException("Unknown database profile: " + integrationTestDatabase);
}

return activeProfiles;
return new String[] {
"integration",
"db",
"db-" + integrationTestDatabase,
};
}
}
23 changes: 23 additions & 0 deletions genie-web/src/test/resources/application-db-hsql-mem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
##
#
# Copyright 2017 Netflix, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##

spring:
datasource:
url: jdbc:hsqldb:mem:genie-int-db;shutdown=true
username: SA
password:
25 changes: 25 additions & 0 deletions genie-web/src/test/resources/application-db-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
##
#
# Copyright 2017 Netflix, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##

spring:
datasource:
url: jdbc:mysql://127.0.0.1/genie
username: root
password:
tomcat:
validation-query: select 0;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##
#
# Copyright 2016 Netflix, Inc.
# Copyright 2017 Netflix, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,37 +16,12 @@
#
##

endpoints:
health:
time-to-live: 1

genie:
data:
service:
retry:
noOfRetries: 2
initialInterval: 10
maxInterval: 10
health:
maxCpuLoadPercent: 100
jobs:
clusters:
loadBalancers:
script:
enabled: true
dir:
location: "file:///tmp/"

spring:
datasource:
url: jdbc:mysql://127.0.0.1/genie
username: root
password:
tomcat:
min-idle: 5
max-idle: 20
max-active: 40
validation-query: select 0;
test-on-borrow: true
test-on-connect: true
test-on-return: true
Expand Down
14 changes: 0 additions & 14 deletions genie-web/src/test/resources/application-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,3 @@ genie:
location: "file:///tmp/"
archive:
location: /archive/location

spring:
jpa:
hibernate:
ddl-auto: none
naming:
strategy: org.hibernate.cfg.ImprovedNamingStrategy
datasource:
url: jdbc:hsqldb:mem:genie-int-db;shutdown=true
username: SA
password:
tomcat:
max-active: 5
jdbc-interceptors: org.apache.tomcat.jdbc.pool.interceptor.QueryTimeoutInterceptor
5 changes: 5 additions & 0 deletions travis/buildViaTravis.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash
# This script will build the project.

# Stop at the first error
set -e

if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]"
./gradlew build asciidoc coveralls dockerBuildAllImages
# Re-run genie-web integration tests with MySQL...
INTEGRATION_TEST_DB=mysql ./gradlew genie-web:integrationTests
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then
echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'
./gradlew -Prelease.travisci=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" snapshot coveralls publishGhPages dockerPush
Expand Down

0 comments on commit dd0b52a

Please sign in to comment.