Merge pull request #33 from rtyler/five-zero-fixes
Better integration testing and a bug fix
This commit is contained in:
commit
48d3f248ba
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
#Tue Sep 16 15:17:56 PDT 2014
|
||||
#Mon Sep 21 11:21:40 PDT 2015
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
|
||||
|
|
|
@ -42,11 +42,6 @@ case "`uname`" in
|
|||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
|
@ -114,6 +109,7 @@ fi
|
|||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
"""
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package com.github.jrubygradle.storm
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import spock.lang.*
|
||||
|
||||
/**
|
||||
*/
|
||||
class JRubyStormLocalIntegrationSpec extends JRubyStormIntegrationSpecification {
|
||||
def "executing runJRubyStorm with no topology should error"() {
|
||||
given:
|
||||
applyPluginTo(buildFile)
|
||||
buildFile << "jrubyStorm { topology 'foo.rb' }"
|
||||
|
||||
when:
|
||||
BuildResult result = GradleRunner.create()
|
||||
.withProjectDir(testProjectDir.root)
|
||||
.withArguments('runJRubyStorm')
|
||||
.buildAndFail()
|
||||
|
||||
then:
|
||||
result.task(":runJRubyStorm").outcome == TaskOutcome.FAILED
|
||||
}
|
||||
|
||||
File createHelloWorldTopology() {
|
||||
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
|
||||
"""
|
||||
return topologyFile
|
||||
}
|
||||
|
||||
def "running in local mode with a basic topology"() {
|
||||
given:
|
||||
applyPluginTo(buildFile)
|
||||
File topo = createHelloWorldTopology()
|
||||
buildFile << "jrubyStorm { topology '${topo.absolutePath}' }"
|
||||
|
||||
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"}')
|
||||
}
|
||||
|
||||
@Issue('https://github.com/jruby-gradle/jruby-gradle-storm-plugin/issues/29')
|
||||
def "JRubyStormLocal tasks should not require a parent task"() {
|
||||
given:
|
||||
applyPluginTo(buildFile)
|
||||
File topo = createHelloWorldTopology()
|
||||
|
||||
buildFile << """
|
||||
import com.github.jrubygradle.storm.JRubyStormLocal
|
||||
task run(type: JRubyStormLocal) {
|
||||
topology '${topo.absolutePath}'
|
||||
}
|
||||
"""
|
||||
|
||||
when: 'the run task is invoked'
|
||||
BuildResult result = GradleRunner.create()
|
||||
.withProjectDir(testProjectDir.root)
|
||||
.withArguments('run')
|
||||
.build()
|
||||
|
||||
then: 'the task should succeed'
|
||||
result.task(":run").outcome == TaskOutcome.SUCCESS
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
}
|
||||
"""
|
||||
|
|
|
@ -56,6 +56,12 @@ class JRubyStormLocal extends JavaExec implements JRubyExecTraits {
|
|||
if (parentTask) {
|
||||
super.classpath parentTask.localConfiguration
|
||||
}
|
||||
else {
|
||||
/* make sure we always have some form of valid classpath set, see
|
||||
* also: https://github.com/jruby-gradle/jruby-gradle-storm-plugin/issues/29
|
||||
*/
|
||||
super.classpath project.configurations.findByName(getConfiguration())
|
||||
}
|
||||
|
||||
prepareDependencies(project)
|
||||
super.exec()
|
||||
|
|
Loading…
Reference in New Issue