Skip to content

Commit

Permalink
Wasabi integration test automation running in Vagrant (#238)
Browse files Browse the repository at this point in the history
* Feature to enable integration test running in Vagrant.

* Fixed readme

* Fixed readme

* Incorporated Nilesh's review feedback.

* Use ${basedir} instead of relative path to copy *main-all.jar.

* 1. Updated create_keyspace to use #!/usr/bin/env bash
2. Updated maven-resources-plugin to use 3.0.0
3. Commented maven-filtering dependency in maven-resources-plugin in
parent pom as it should be automatically figured out the right version.

* Need to update maven-resources-plugin version to 3.0.0 in swagger-ui as
well.

* Revert maven-resources-plugin version back to 2.7.
  • Loading branch information
jcwuzoegiver committed May 10, 2017
1 parent ddfa1d1 commit 8d27e62
Show file tree
Hide file tree
Showing 15 changed files with 689 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modules/functional-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ The tests use [TestNG](http://testng.org/doc/) and are implemented using
[rest-assured](https://github.com/jayway/rest-assured/wiki/Usage) and
[Gson](https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/index.html).

#Running Integration Test in Vagrant

Prerequisite:
* cd [workspace]/wasabi. mvn clean install
* Install Oracle VM VirtualBox (version 5.1.18 or higher) and Vagrant (version 1.9.3 or higher).

Mac installation instructions with brew
```shell
# install vagrant
% brew cask install vagrant
# install virtualbox
% brew cask install virtualbox
% brew cask install vagrant-manager
# install vagrant's omnibus
% vagrant plugin install vagrant-omnibus
```

To run all integration tests defined in testng.xml, simply do the following.
* cd [workspace]/wasabi/modules/functional-test
* vagrant up (this step will install dependencies (jdk, Cassandra, MySQL), install Wasabi app, create Cassandra tables, start up Wasabi app, run integration tests, stops Wasabi app and generate Jacoco file for code coverage)
* Test output will be saved in [workspace]/wasabi/modules/functional-test/target/integration-test.out
* vagrant destroy (this will destroy the VM)

**NOTE:** jacoco-it.exec will be stored at [workspace]/wasabi/modules/functional-test/target/jacoco

#Checklist

Expand Down
21 changes: 21 additions & 0 deletions modules/functional-test/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Vagrant.configure("2") do |config|

config.vm.box = 'bento/centos-7.2'
config.vm.provision "shell", :path => "provision.sh"
config.vm.provision "shell", :path => "target/scripts/migration.sh"
config.vm.provision "shell", :path => "target/scripts/server-start.sh"
config.vm.provision "shell", :path => "target/scripts/run-it.sh"
config.vm.provision "shell", :path => "target/scripts/server-stop.sh"

config.vm.define :wasabiosit do |dev|
dev.vm.hostname = "wasabi.os.it"
dev.vm.boot_timeout = 3000

dev.vm.provider "virtualbox" do |v|
v.name = "wasabi.os.it.vbox"
v.memory = 4096
v.cpus = 4
v.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
end
end
126 changes: 126 additions & 0 deletions modules/functional-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,132 @@
</execution>
</executions>
</plugin>
<!-- The following plugins are for running integration tests in Vagrant -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.intuit.wasabi</groupId>
<artifactId>wasabi-repository-datastax</artifactId>
<version>${version}</version>
<type>jar</type>
<includes>com/intuit/wasabi/repository/impl/cassandra/migration/*.*</includes>
<outputDirectory>./target/mutation</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-main-resource</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${basedir}/../../modules/main/target/</directory>
<includes>
<include>*-all.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>filter-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/scripts</outputDirectory>
<resources>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
<includes>
<include>**/server-start.sh</include>
<include>**/cassandra_migration_rc.sh</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-jacoco-runtime-resource</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco.version}</version>
<classifier>runtime</classifier>
<type>jar</type>
</artifactItem>
</artifactItems>
<outputDirectory>./target</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-cassandra-migration-resource</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.builtamont</groupId>
<artifactId>cassandra-migration</artifactId>
<version>${cassandra.migration.version}</version>
<classifier>jar-with-dependencies</classifier>
<type>jar</type>
</artifactItem>
</artifactItems>
<outputDirectory>./target</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

<resources>
Expand Down
61 changes: 61 additions & 0 deletions modules/functional-test/provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
###############################################################################
# Copyright 2017 Intuit
#
# 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.
###############################################################################
#!/usr/bin/env bash

exec > >(tee ./provision.log|logger -t provision -s 2>/dev/console)

sudo yum -y install wget
sudo yum -y install vim

# install apache
yum -y install httpd
sudo service httpd start

# install Oracle JDK
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-x64.rpm"
sudo yum -y localinstall jdk-8u92-linux-x64.rpm

cat <<EOF | sudo tee -a /etc/yum.repos.d/datastax.repo
[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0
EOF

sudo yum -y install dsc21
sudo service cassandra start
sudo systemctl enable cassandra.service

# install mysql
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
sudo yum -y update
sudo yum -y install mysql-server
sudo systemctl start mysqld

# create MySQL db
MYSQL_HOST="localhost"
MYSQL_DBNAME="wasabi"

mysql -s -N -h $MYSQL_HOST --execute="create database $MYSQL_DBNAME;"
mysql -s -N -h $MYSQL_HOST --execute="create user 'readwrite'@'localhost' identified by 'readwrite';"
mysql -s -N -h $MYSQL_HOST --execute="grant all privileges on wasabi.* to 'readwrite'@'localhost' identified by 'readwrite';"
mysql -s -N -h $MYSQL_HOST --execute="flush privileges;"

# install runit
curl -s https://packagecloud.io/install/repositories/imeyer/runit/script.rpm.sh | sudo bash
sudo yum -y install runit-2.1.2-3.el7.centos.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
###############################################################################
# Copyright 2017 Intuit
#
# 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.
###############################################################################
#!/usr/bin/env bash

export CASSANDRA_KEYSPACE=${cassandra.experiments.keyspaceName}
export CASSANDRA_KEYSPACE_PREFIX=${cassandra.keyspace.prefix}

export MIGRATION_SCRIPT_1=/vagrant/target/mutation/${wasabi.cassandra.migration.resource.path}
export CASSANDRA_MIGRATION=/vagrant/target/cassandra-migration-${cassandra.migration.version}-jar-with-dependencies.jar
export CQLSH_HOST=localhost
export CASSANDRA_REPLICATION=1

echo CASSANDRA_KEYSPACE $CASSANDRA_KEYSPACE
echo MIGRATION_SCRIPT_1 $MIGRATION_SCRIPT_1
echo CASSANDRA_MIGRATION $CASSANDRA_MIGRATION
echo CASSANDRA_KEYSPACE_PREFIX $CASSANDRA_KEYSPACE_PREFIX
echo CQLSH_HOST $CQLSH_HOST
echo CASSANDRA_REPLICATION $CASSANDRA_REPLICATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
###############################################################################
# Copyright 2017 Intuit
#
# 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.
###############################################################################
#!/usr/bin/env bash

APPLICATION_INSTRUMENT="-javaagent:/vagrant/target/org.jacoco.agent-${jacoco.version}-runtime.jar=destfile=/vagrant/target/jacoco/jacoco-it.exec,append=false"
CONSOLE_LOG=wasabi-os-console.log
MAIN_JAR=/vagrant/target/wasabi-main-*-all.jar

JAVA_OPTIONS="-server -Xmx4096m \
${APPLICATION_INSTRUMENT} \
-Dlogback.configurationFile=./logback.xml \
-Djava.util.logging.config.file=./logging.properties"


java ${JAVA_OPTIONS} -jar ${MAIN_JAR} 1>>${CONSOLE_LOG} 2>&1 &
39 changes: 39 additions & 0 deletions modules/functional-test/src/main/scripts/create_keyspace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
###############################################################################
# Copyright 2017 Intuit
#
# 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.
###############################################################################
#!/usr/bin/env bash

echo "Creating Keyspace ${CASSANDRA_KEYSPACE_PREFIX}_experiments if it not exits"
echo "cqlsh " \
"-e \"CREATE KEYSPACE IF NOT EXISTS ${CASSANDRA_KEYSPACE_PREFIX}_experiments WITH replication = {'class' : 'NetworkTopologyStrategy', 'datacenter1' : ${CASSANDRA_REPLICATION:-1}};\"" \
"--username=${CQLSH_USERNAME}" \
"--password=\"${CQLSH_PASSWORD}\"" \
"${CQLSH_HOST:-localhost}" \
"${CASSANDRA_PORT:-9042}"

cqlsh \
-e "CREATE KEYSPACE IF NOT EXISTS ${CASSANDRA_KEYSPACE_PREFIX}_experiments WITH replication = {'class' : 'NetworkTopologyStrategy', 'datacenter1' : ${CASSANDRA_REPLICATION:-1}};" \
--username=${CQLSH_USERNAME} \
--password="${CQLSH_PASSWORD}" \
${CQLSH_HOST:-localhost} \
${CASSANDRA_PORT:-9042}


if [ $? -ne 0 ]; then
echo "failed to execute the create keyspace command. Please contact administrator."
exit 1;
fi

echo "Done creating keyspace"
29 changes: 29 additions & 0 deletions modules/functional-test/src/main/scripts/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--
Copyright 2017 Intuit
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.
-->
<configuration scan="true" scanPeriod="30 seconds">

<contextName>wasabi-intuit-main</contextName>
<jmxConfigurator/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
Loading

0 comments on commit 8d27e62

Please sign in to comment.