Skip to content

Commit

Permalink
Merge pull request #56 from embulk/use-docker-for-test
Browse files Browse the repository at this point in the history
Use Docker for unit test and test on Travis CI
  • Loading branch information
sakama authored Dec 17, 2018
2 parents ddb7237 + 88865e8 commit 99017e7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ build/
/classpath/
/.gradle
/pkg/
es-data
out
17 changes: 4 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ language: java
jdk:
- oraclejdk8

env:
global:
- ES_HOST=localhost
- ES_PORT=9200
- ES_INDEX=embulk
- ES_INDEX_TYPE=embulk

before_install:
- wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.3/elasticsearch-2.3.3.tar.gz
- tar zxvf elasticsearch-2.3.3.tar.gz
- ./elasticsearch-2.3.3/bin/elasticsearch &
services:
- docker

before_script:
- echo "Wait Elasticsearch wakeup"
- sleep 10
- docker-compose up -d
- docker-compose ps

script:
- ./gradlew gem
Expand Down
52 changes: 11 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,48 +95,18 @@ $ ./gradlew bintrayUpload # release embulk-output-elasticsearch to Bintray maven

## Test

```
$ ./gradlew test # -t to watch change of files and rebuild continuously
```

To run unit tests, we need to configure the following environment variables.
Firstly install Docker and Docker compose then `docker-compose up -d`,
so that an MongoDB server will be locally launched then you can run tests with `./gradlew test`.

When environment variables are not set, skip almost test cases.
```sh
$ docker-compose up -d
Creating network "embulk-output-elasticsearch_default" with the default driver
Creating embulk-output-elasticsearch_server ... done

```
ES_HOST
ES_PORT(optional, if needed, default: 9300)
ES_INDEX
ES_INDEX_TYPE
```
$ docker-compose ps
Name Command State Ports
------------------------------------------------------------------------------------------------------------------------------
embulk-output-elasticsearch_server /docker-entrypoint.sh elas ... Up 0.0.0.0:19200->9200/tcp, 0.0.0.0:19300->9300/tcp

If you're using Mac OS X El Capitan and GUI Applications(IDE), like as follows.
```
$ vi ~/Library/LaunchAgents/environment.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.startup</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>
launchctl setenv ES_HOST example.com
launchctl setenv ES_PORT 9300
launchctl setenv ES_INDEX embulk
launchctl setenv ES_INDEX_TYPE embulk
</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
$ launchctl load ~/Library/LaunchAgents/environment.plist
$ launchctl getenv ES_INDEX //try to get value.
Then start your applications.
$ ./gradlew test # -t to watch change of files and rebuild continuously
```
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.1'
services:
elasticsearch:
container_name: embulk-output-elasticsearch_server
image: elasticsearch:5
ports:
- 19200:9200
- 19300:9300
volumes:
- ./es-data:/usr/share/elasticsearch/data/
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,19 @@ public class ElasticsearchTestUtils
public static String ES_INDEX2;
public static String ES_ALIAS;

/*
* This test case requires environment variables
* ES_HOST
* ES_INDEX
* ES_INDEX_TYPE
*/
public void initializeConstant()
{
ES_HOST = System.getenv("ES_HOST") != null ? System.getenv("ES_HOST") : "";
ES_PORT = System.getenv("ES_PORT") != null ? Integer.valueOf(System.getenv("ES_PORT")) : 9200;
ES_HOST = "localhost";
ES_PORT = 19200;

ES_INDEX = System.getenv("ES_INDEX");
ES_INDEX = "embulk";
ES_INDEX2 = ES_INDEX + "_02";
ES_ALIAS = ES_INDEX + "_alias";
ES_INDEX_TYPE = System.getenv("ES_INDEX_TYPE");
ES_INDEX_TYPE = "embulk";
ES_ID = "id";
ES_BULK_ACTIONS = System.getenv("ES_BULK_ACTIONS") != null ? Integer.valueOf(System.getenv("ES_BULK_ACTIONS")) : 1000;
ES_BULK_SIZE = System.getenv("ES_BULK_SIZE") != null ? Integer.valueOf(System.getenv("ES_BULK_SIZE")) : 5242880;
ES_CONCURRENT_REQUESTS = System.getenv("ES_CONCURRENT_REQUESTS") != null ? Integer.valueOf(System.getenv("ES_CONCURRENT_REQUESTS")) : 5;

assumeNotNull(ES_HOST, ES_INDEX, ES_INDEX_TYPE);
ES_BULK_ACTIONS = 1000;
ES_BULK_SIZE = 5242880;
ES_CONCURRENT_REQUESTS = 5;

ES_NODES = Arrays.asList(ImmutableMap.of("host", ES_HOST, "port", ES_PORT));

Expand Down

0 comments on commit 99017e7

Please sign in to comment.