Start adding more integration test cases including one for JRubyStormLocal tasks

This commit is contained in:
R. Tyler Croy 2015-09-21 13:16:32 -07:00
parent 2ad81ecb40
commit 2a3f0b709a
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
3 changed files with 129 additions and 67 deletions

View File

@ -0,0 +1,52 @@
package com.github.jrubygradle.storm
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.BuildResult
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.*
/**
* Integration testing base class for common integration testing behaviors
*/
class JRubyStormIntegrationSpecification extends Specification {
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile
String pluginDependencies
def setup() {
buildFile = testProjectDir.newFile('build.gradle')
def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.json")
if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
}
pluginDependencies = pluginClasspathResource.text
}
/**
* Apply the necessary plugin configuration to integration test a Gradle build
* with the given <pre>build</pre> {@code File}
*
* @param build Temporary file representing the build.gradle
*/
void applyPluginTo(File build) {
build << """
buildscript {
dependencies {
classpath files(${pluginDependencies})
}
}
apply plugin: 'com.github.jruby-gradle.storm'
repositories {
jcenter()
}
"""
}
}

View File

@ -3,55 +3,82 @@ package com.github.jrubygradle.storm
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.BuildResult
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.*
/**
*/
class JRubyStormLocalIntegrationSpec extends Specification {
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile
String pluginDependencies
def setup() {
buildFile = testProjectDir.newFile('build.gradle')
def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.json")
if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
}
pluginDependencies = pluginClasspathResource.text
}
class JRubyStormLocalIntegrationSpec extends JRubyStormIntegrationSpecification {
def "executing runJRubyStorm with no topology should error"() {
given:
buildFile << """
buildscript {
dependencies {
classpath files(${pluginDependencies})
}
}
apply plugin: 'com.github.jruby-gradle.storm'
repositories {
jcenter()
mavenLocal()
}
jrubyStorm {
}
"""
applyPluginTo(buildFile)
buildFile << "jrubyStorm { topology 'foo.rb' }"
when:
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('runJRubyStorm')
.build()
.buildAndFail()
then:
result.task(":runJRubyStorm").outcome == TaskOutcome.FAILURE
result.task(":runJRubyStorm").outcome == TaskOutcome.FAILED
}
def "running in local mode with a basic topology"() {
given:
applyPluginTo(buildFile)
buildFile << "jrubyStorm { topology 'topo.rb' }"
File topologyFile = testProjectDir.newFile('topo.rb')
topologyFile << """
require 'red_storm'
class HelloWorldSpout < RedStorm::DSL::Spout
on_init {@words = ["hello", "world"]}
on_send {@words.shift unless @words.empty?}
end
class HelloWorldBolt < RedStorm::DSL::Bolt
on_receive :emit => false do |tuple|
puts tuple
end
end
class HelloWorldTopology < RedStorm::DSL::Topology
spout HelloWorldSpout do
output_fields :word
end
bolt HelloWorldBolt do
source HelloWorldSpout, :global
end
configure do
debug false
max_task_parallelism 4
num_workers 1
max_spout_pending 1000
end
on_submit do
Thread.start {
sleep 20
cluster.shutdown
}
end
end
"""
when: 'runJRubyStorm is invoked'
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('runJRubyStorm')
.build()
then: 'the task should succeed'
result.task(":runJRubyStorm").outcome == TaskOutcome.SUCCESS
and: "it should have logged hello world"
result.standardOutput.contains('{"word"=>"hello"}')
result.standardOutput.contains('{"word"=>"world"}')
}
}

View File

@ -1,49 +1,32 @@
package com.github.jrubygradle.storm
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.BuildResult
import org.gradle.api.artifacts.Dependency
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.*
/** Integration tests which actually execute Gradle via the GradleTestKit */
class JRubyStormTestKitSpec extends Specification {
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile
String pluginDependencies
class JRubyStormTestKitSpec extends JRubyStormIntegrationSpecification {
def "executing the task without a topolgoy should error"() {
given:
applyPluginTo(buildFile)
buildFile << 'jrubyStorm { }'
def setup() {
buildFile = testProjectDir.newFile('build.gradle')
def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.json")
when:
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('jrubyStorm')
.buildAndFail()
if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
}
pluginDependencies = pluginClasspathResource.text
then:
result.task(":jrubyStorm").outcome == TaskOutcome.FAILED
}
def "executing the assemble task produces a jar artifact"() {
given:
applyPluginTo(buildFile)
buildFile << """
buildscript {
dependencies {
classpath files(${pluginDependencies})
}
}
apply plugin: 'com.github.jruby-gradle.storm'
repositories {
jcenter()
mavenLocal()
}
jrubyStorm {
}
"""