Monday, March 5, 2012

run multiple jetty in gradle


Background:
I have a selenium test suite for end-to-end web testing.
Currently, it is running on jenkins box but it is taking so long to finish all the tests.
So, next step is to parallelize the selenium tests.
As a first step, I need to start multiple jetty servers using different port.

With Gradle jetty plugin, I camp up how to run the multiple jetty servers before tests.

// start multiple jetties before test
//
// useful for parallel web end-to-end testing
//
import org.gradle.api.plugins.jetty.JettyRun
apply plugin: 'java'
apply plugin: 'jetty'
repositories {
mavenCentral()
}
// configuration for each jetty server
def jettyConfigs = [
[port:8001],
[port:8002]
]
def jettyMultiRunTasks = []
// create jetty tasks and assign them
jettyConfigs.eachWithIndex {jettyConfig, index ->
jettyMultiRunTasks << task("jettyMultiRun-${index}", type: JettyRun) {
httpPort = jettyConfig.port
daemon = true
// more configuration to specify each jetty to use different env...
}
}
test {
// start jetties before running tests
dependsOn(jettyMultiRunTasks)
// more test options such as maxParallelForks, etc.
}
view raw build.gradle hosted with ❤ by GitHub

2 comments:

Anonymous said...

Nice! This is cool...

Anonymous said...

Really cool! Gradle is a breath of air, especially
after ugly boileplating with maven xml.

Cool hack of jetty.
Thanks!