diff --git a/.gitignore b/.gitignore index 1c0b6bb..0fdf3cc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ build/ /classpath/ /.gradle /pkg/ +es-data +out diff --git a/.travis.yml b/.travis.yml index 6a5a39d..7d631bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 0250c43..2ae0c55 100644 --- a/README.md +++ b/README.md @@ -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 - - - - - Label - my.startup - ProgramArguments - - sh - -c - - launchctl setenv ES_HOST example.com - launchctl setenv ES_PORT 9300 - launchctl setenv ES_INDEX embulk - launchctl setenv ES_INDEX_TYPE embulk - - - RunAtLoad - - - - -$ 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 ``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1d094e6 --- /dev/null +++ b/docker-compose.yml @@ -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/ diff --git a/src/test/java/org/embulk/output/elasticsearch/ElasticsearchTestUtils.java b/src/test/java/org/embulk/output/elasticsearch/ElasticsearchTestUtils.java index 747dbad..06c4dfb 100644 --- a/src/test/java/org/embulk/output/elasticsearch/ElasticsearchTestUtils.java +++ b/src/test/java/org/embulk/output/elasticsearch/ElasticsearchTestUtils.java @@ -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));