Git Product home page Git Product logo

bilberry's Introduction

gradle-elastic-plugin

an ElasticSearch gradle plugin for integration tests with ElasticSearch

Build Status Download

Using

Plugin setup with gradle >= 2.1:

    plugins {
        id "ajk.gradle.elastic" version "0.0.10"
    }

Plugin setup with gradle < 2.1:

    buildscript {
        repositories {
            jcenter()
            maven { url "http://dl.bintray.com/amirk/maven" }
        }
        dependencies {
            classpath("ajk.gradle.elastic:gradle-elastic-plugin:0.0.10")
        }
    }

    apply plugin: 'ajk.gradle.elastic'

Starting and stopping ElasticSearch during the integration tests

    task integrationTests(type: Test) {
        reports {
            html.destination "$buildDir/reports/integration-tests"
        }

        include "**/*IT.*"

        doFirst {
            startElastic {
				elasticVersion = "1.5.2"
                httpPort = 9200
				transportPort = 9300
				dataDir = file("$buildDir/elastic")
				logsDir = file("$buildDir/elastic/logs")
            }
        }
    
        doLast {
            stopElastic {
                httpPort = 9200
            }
        }
    }
    
    gradle.taskGraph.afterTask { Task task, TaskState taskState ->
        if (task.name == "integrationTests") {
            stopElastic {
                httpPort = 9200
            }
        }
    }

    test {
        include '**/*Test.*'
        exclude '**/*IT.*'
    }

The above example shows a task called integrationTests which runs all the tests in the project with the IT suffix. The reports for these tests are placed in the buildDir/reports/integration-tests directory - just to separate them from regular tests. But the important part here is in the doFirst and doLast.

In the doFirst ElasticSearch is started. All the values in the example above are the default values, so if these values work for you they can be ommitted:

    doFirst {
        startElastic {}
    }

In the doLast ElasticSearch is stopped. Note that ElasticSearch is also stopped in the gradle.taskGraph.afterTask section - this is to catch any crashes during the integration tests and make sure that ElasticSearch is stopped in the build clean-up phase.

Lastly the regular test task is configured to exclude the tests with the IT suffix - we only wanted to run these in the integration tests phase, not with the regular tests.

More information

This plugin installs ElasticSearch locally at project.rootDir/gradle/tools/elastic. In addition, the ElasticSearch head plugin is also installed. This plugin provides a nice web-based UI for ElasticSearch, which I find useful. To access the UI start ElasticSearch with this plugin, the go to http://localhost:9200/_plugin/head.

References

bilberry's People

Contributors

amirkibbar avatar gesellix avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.