From e993793dd0037df6987dd8da39c7da1387df4be2 Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Wed, 15 Aug 2012 07:11:06 -0700 Subject: [PATCH 01/18] Initial commit --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..9444d9e --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +vertx-junit-annotations +======================= + +A JUnit test Runner for vert.x \ No newline at end of file From 90df0ebdfb2d2c6342275b3a7ce611c310a3832f Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Wed, 15 Aug 2012 21:26:18 +0100 Subject: [PATCH 02/18] initial commit --- .gitignore | 7 + build.gradle | 62 ++++++ gradle.properties | 25 +++ gradle/setup.gradle | 5 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 39860 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 164 +++++++++++++++ gradlew.bat | 90 +++++++++ settings.gradle | 2 + .../junit/CountDownLatchDoneHandler.java | 40 ++++ .../org/vertx/testing/junit/Deployer.java | 187 ++++++++++++++++++ .../junit/VertxConfigurableJUnit4Runner.java | 122 ++++++++++++ .../org/vertx/testing/junit/VertxRule.java | 48 +++++ .../testing/junit/annotations/Module.java | 42 ++++ .../testing/junit/annotations/Modules.java | 38 ++++ .../testing/junit/annotations/Verticle.java | 46 +++++ .../testing/junit/annotations/Verticles.java | 38 ++++ .../junit/annotations/VertxConfig.java | 40 ++++ .../support/VerticleManagerSupport.java | 31 +++ .../vertx/testing/support/VertxSupport.java | 31 +++ .../vertx/testing/support/VertxTestBase.java | 48 +++++ .../vertx/testing/support/package-info.java | 20 ++ .../testing/junit/ModuleAnnotationTest.java | 111 +++++++++++ .../testing/junit/QueueReplyHandler.java | 50 +++++ .../vertx/testing/junit/SimpleEchoTest.java | 82 ++++++++ .../testing/junit/VerticleAnnotationTest.java | 105 ++++++++++ src/test/mods/test.echo0-v1.0/echo0.js | 25 +++ src/test/mods/test.echo0-v1.0/mod.json | 3 + src/test/mods/test.echo1-v1.0/echo1.js | 25 +++ src/test/mods/test.echo1-v1.0/mod.json | 3 + src/test/mods/test.echo2-v1.0/echo2.js | 25 +++ src/test/mods/test.echo2-v1.0/mod.json | 3 + src/test/resources/test_client.js | 44 +++++ src/test/resources/test_verticle0.js | 25 +++ src/test/resources/test_verticle1.js | 25 +++ src/test/resources/test_verticle2.js | 25 +++ 36 files changed, 1643 insertions(+) create mode 100644 .gitignore create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/setup.gradle create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 src/main/java/org/vertx/testing/junit/CountDownLatchDoneHandler.java create mode 100644 src/main/java/org/vertx/testing/junit/Deployer.java create mode 100644 src/main/java/org/vertx/testing/junit/VertxConfigurableJUnit4Runner.java create mode 100644 src/main/java/org/vertx/testing/junit/VertxRule.java create mode 100644 src/main/java/org/vertx/testing/junit/annotations/Module.java create mode 100644 src/main/java/org/vertx/testing/junit/annotations/Modules.java create mode 100644 src/main/java/org/vertx/testing/junit/annotations/Verticle.java create mode 100644 src/main/java/org/vertx/testing/junit/annotations/Verticles.java create mode 100644 src/main/java/org/vertx/testing/junit/annotations/VertxConfig.java create mode 100644 src/main/java/org/vertx/testing/support/VerticleManagerSupport.java create mode 100644 src/main/java/org/vertx/testing/support/VertxSupport.java create mode 100644 src/main/java/org/vertx/testing/support/VertxTestBase.java create mode 100644 src/main/java/org/vertx/testing/support/package-info.java create mode 100644 src/test/java/org/vertx/testing/junit/ModuleAnnotationTest.java create mode 100644 src/test/java/org/vertx/testing/junit/QueueReplyHandler.java create mode 100644 src/test/java/org/vertx/testing/junit/SimpleEchoTest.java create mode 100644 src/test/java/org/vertx/testing/junit/VerticleAnnotationTest.java create mode 100644 src/test/mods/test.echo0-v1.0/echo0.js create mode 100644 src/test/mods/test.echo0-v1.0/mod.json create mode 100644 src/test/mods/test.echo1-v1.0/echo1.js create mode 100644 src/test/mods/test.echo1-v1.0/mod.json create mode 100644 src/test/mods/test.echo2-v1.0/echo2.js create mode 100644 src/test/mods/test.echo2-v1.0/mod.json create mode 100644 src/test/resources/test_client.js create mode 100644 src/test/resources/test_verticle0.js create mode 100644 src/test/resources/test_verticle1.js create mode 100644 src/test/resources/test_verticle2.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bacb4d --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.classpath +.gradle +.project +.settings +.springBeans +bin +build diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..40cc6f1 --- /dev/null +++ b/build.gradle @@ -0,0 +1,62 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply from: 'gradle/setup.gradle' +apply plugin: 'java' + +defaultTasks = ['assemble'] + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +repositories { + mavenCentral() +} + +dependencies { + compile "junit:junit:$junitVersion" + compile "org.vert-x:vertx-core:$vertxVersion" + compile "org.vert-x:vertx-platform:$vertxVersion" + + testCompile "org.vert-x:vertx-lang-java:$vertxVersion" + testCompile "org.vert-x:vertx-lang-rhino:$vertxVersion" + testCompile "org.mozilla:rhino:$rhinoVersion" + +} + +test { + // Some vert.x properties + systemProperty 'vertx.test.timeout', 15 + systemProperty 'vertx.mods', "$projectDir/src/test/mods" + systemProperty 'vertx.version', "$project.version" + + // Show output + testLogging.showStandardStreams = true +} + +test.dependsOn testClasses + +task collectDeps(type: Copy) { + group = 'vert.x' + description = 'conveniently collect dependencies for other IDEs' + destinationDir = file("build/deps") + into("compile") { + from configurations.compile + } + into("test") { + from configurations.testCompile + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..1e8ebcc --- /dev/null +++ b/gradle.properties @@ -0,0 +1,25 @@ +# +# Copyright 2011 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +version=1.0 +group=org.vert-x +modulename=test-annotations +gradleVersion=1.0 + +vertxVersion=1.2.3.final +rhinoVersion=1.7R4 +springVersion=3.1.2.RELEASE + +junitVersion=4.10 \ No newline at end of file diff --git a/gradle/setup.gradle b/gradle/setup.gradle new file mode 100644 index 0000000..da1fcd7 --- /dev/null +++ b/gradle/setup.gradle @@ -0,0 +1,5 @@ + +task wrapper(type: Wrapper, description: "Create a Gradle self-download wrapper") { + group = 'Project Setup' + gradleVersion = rootProject.gradleVersion +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..e3b3376e6002f9d44543761c8d3dcd199eff1d82 GIT binary patch literal 39860 zcma&Ob980fwl1EEZQHh;if!A@ij9hG+o{-g#kOr56;$}L-?`_#yZ1dm%+|(g^N&8~ zY-6mi_tEtY1!)jaXdoa+NFWr9iSIyP7w}&{Ul-KZkQG%Cq?42rV*mkC_?uw8FYp!4 zmjKq+K>hE6vVwAwVxr0_^s-|2vJ>Mn(scB*aMEHn)J%HKuZ91ZR5O&$NoBNhQBW`$p(i(iA}KR+U3 z=VohTXJ|soL~m?k=;Y)RB@5lhh#0(W!KOvy$`Amv9Fo&ZU{6HPD`+EZ10^Y0-jxZ1 zu#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bKn9L7KjUC;(p zbj|2zufnu1X`FmhXPcn=2>s9r zgk}4K@L7gD1BPxU`c83#nQ`Ix%!Eb=#ApZyY1RVW7W8e*2wT)6F>C>whPkO3-Awd7 zbO \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" +APP_HOME="`pwd -P`" +cd "$SAVED" + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..28b1d3a --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +// Gradle Settings + diff --git a/src/main/java/org/vertx/testing/junit/CountDownLatchDoneHandler.java b/src/main/java/org/vertx/testing/junit/CountDownLatchDoneHandler.java new file mode 100644 index 0000000..4b3dff2 --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/CountDownLatchDoneHandler.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit; + +import java.util.concurrent.CountDownLatch; + +import org.vertx.java.core.Handler; + + +/** + * @author swilliams + * + */ +public class CountDownLatchDoneHandler implements Handler { + + public final CountDownLatch latch; + + CountDownLatchDoneHandler(final CountDownLatch latch) { + this.latch = latch; + } + + @Override + public void handle(T event) { + latch.countDown(); + } + +} \ No newline at end of file diff --git a/src/main/java/org/vertx/testing/junit/Deployer.java b/src/main/java/org/vertx/testing/junit/Deployer.java new file mode 100644 index 0000000..3b0b3c2 --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/Deployer.java @@ -0,0 +1,187 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.runner.Description; +import org.vertx.java.core.json.JsonObject; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.testing.junit.annotations.Module; +import org.vertx.testing.junit.annotations.Modules; +import org.vertx.testing.junit.annotations.Verticle; +import org.vertx.testing.junit.annotations.Verticles; + + +/** + * @author swilliams + * + */ +public class Deployer { + + private final File modDir; + + private final VerticleManager manager; + + Deployer(VerticleManager manager, File modDir) { + this.manager = manager; + this.modDir = modDir; + } + + public void deploy(Description description) { + final Modules amodules = description.getAnnotation(Modules.class); + final Module amodule = description.getAnnotation(Module.class); + final Verticles verticles = description.getAnnotation(Verticles.class); + final Verticle verticle = description.getAnnotation(Verticle.class); + + deployModules(amodules); + deployModule(amodule); + deployVerticles(verticles); + deployVerticle(verticle); + } + + + private void deployVerticles(Verticles verticles) { + + if (verticles == null) { + return; + } + + final CountDownLatch latch = new CountDownLatch(verticles.value().length); + for (Verticle v : verticles.value()) { + JsonObject config = getJsonConfig(v.jsonConfig()); + + URL[] urls = findVerticleURLs(v); + manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, new CountDownLatchDoneHandler(latch)); + } + + await(latch); + } + + private void deployVerticle(Verticle v) { + if (v == null) { + return; + } + + final CountDownLatch latch = new CountDownLatch(1); + JsonObject config = getJsonConfig(v.jsonConfig()); + URL[] urls = findVerticleURLs(v); + manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, new CountDownLatchDoneHandler(latch)); + + await(latch); + } + + private void deployModules(Modules amodules) { + if (amodules == null) { + return; + } + + final CountDownLatch latch = new CountDownLatch(amodules.value().length); + + for (Module m : amodules.value()) { + JsonObject config = getJsonConfig(m.jsonConfig()); + manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); + } + + await(latch); + } + + private void deployModule(Module m) { + if (m == null) { + return; + } + + final CountDownLatch latch = new CountDownLatch(1); + + JsonObject config = getJsonConfig(m.jsonConfig()); + manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); + + await(latch); + } + + private URL[] findVerticleURLs(Verticle v) { + Set urlSet = new HashSet(); + + if (v.urls().length > 0) { + for (String path : v.urls()) { + try { + + URL url = new File(path).toURI().toURL(); + urlSet.add(url); + + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + try { + // contortions to get parent + URL url = getClass().getClassLoader().getResource(v.main()); + url = Paths.get(url.toURI()).getParent().toUri().toURL(); + urlSet.add(url); + + } catch (Exception e) { + e.printStackTrace(); + } + + URL[] urls = new URL[urlSet.size()]; + return urlSet.toArray(urls); + } + + private JsonObject getJsonConfig(String jsonConfig) { + JsonObject config; + + if (jsonConfig.startsWith("file:")) { + String filename = jsonConfig.replaceFirst("file:", ""); + Path json = new File(filename).toPath(); + + try { + Charset utf8 = Charset.forName("UTF-8"); + byte[] bytes = Files.readAllBytes(json); + config = new JsonObject(new String(bytes, utf8)); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + else { + config = new JsonObject(jsonConfig); + } + + return config; + } + + private void await(final CountDownLatch latch) { + try { + latch.await(30L, TimeUnit.SECONDS); + + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/src/main/java/org/vertx/testing/junit/VertxConfigurableJUnit4Runner.java b/src/main/java/org/vertx/testing/junit/VertxConfigurableJUnit4Runner.java new file mode 100644 index 0000000..9057c36 --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/VertxConfigurableJUnit4Runner.java @@ -0,0 +1,122 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit; + +import java.io.File; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CountDownLatch; + +import org.junit.rules.TestRule; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; + +import org.vertx.java.core.impl.DefaultVertx; +import org.vertx.java.core.impl.VertxInternal; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.testing.junit.annotations.VertxConfig; +import org.vertx.testing.support.VerticleManagerSupport; +import org.vertx.testing.support.VertxSupport; + + +/** + * @author swilliams + * + */ +public class VertxConfigurableJUnit4Runner extends BlockJUnit4ClassRunner { + + private final Set classCache = new HashSet(); + + private VertxInternal vertx; + + private VerticleManager verticleManager; + + private Deployer deployer; + + public VertxConfigurableJUnit4Runner(Class klass) throws InitializationError { + super(klass); + } + + @Override + public void run(RunNotifier notifier) { + + VertxConfig vertxConfig = getDescription().getAnnotation(VertxConfig.class); + if (vertxConfig != null) { + this.vertx = new DefaultVertx(vertxConfig.port(), vertxConfig.hostname()); + } + else { + this.vertx = new DefaultVertx(); + } + + this.verticleManager = new VerticleManager(vertx); + + String vertxMods = System.getProperty("vertx.mods"); + File currentModDir = new File(vertxMods); + if (!currentModDir.exists()) { + throw new RuntimeException("vert.mods dir doesn't exist! " + vertxMods); + } + + this.deployer = new Deployer(verticleManager, currentModDir); + deployer.deploy(getDescription()); + + super.run(notifier); + + undeployAll(); + } + + + @Override + protected List getTestRules(Object target) { + + if (!classCache.contains(target.toString())) { + configureTarget(target); + classCache.add(target.toString()); + } + + List rules = super.getTestRules(target); + rules.add(new VertxRule(deployer)); + return rules; + } + + private void configureTarget(Object target) { + + if (target instanceof VertxSupport) { + VertxSupport support = (VertxSupport) target; + support.setVertx(vertx); + } + + if (target instanceof VerticleManagerSupport) { + VerticleManagerSupport support = (VerticleManagerSupport) target; + support.setManager(verticleManager); + } + + } + + private void undeployAll() { + CountDownLatch latch = new CountDownLatch(1); + verticleManager.undeployAll(new CountDownLatchDoneHandler(latch)); + + try { + latch.await(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/org/vertx/testing/junit/VertxRule.java b/src/main/java/org/vertx/testing/junit/VertxRule.java new file mode 100644 index 0000000..600afaf --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/VertxRule.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + + +/** + * @author swilliams + * + */ +public class VertxRule implements TestRule { + + private final Deployer deployer; + + public VertxRule(Deployer deployer) { + this.deployer = deployer; + } + + @Override + public Statement apply(final Statement base, final Description description) { + + return new Statement() { + + @Override + public void evaluate() throws Throwable { + deployer.deploy(description); + base.evaluate(); + }}; + + } + +} diff --git a/src/main/java/org/vertx/testing/junit/annotations/Module.java b/src/main/java/org/vertx/testing/junit/annotations/Module.java new file mode 100644 index 0000000..f784661 --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/annotations/Module.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * @author swilliams + * + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface Module { + + String name(); + + int instances() default 1; + + String jsonConfig() default "{}"; + +} diff --git a/src/main/java/org/vertx/testing/junit/annotations/Modules.java b/src/main/java/org/vertx/testing/junit/annotations/Modules.java new file mode 100644 index 0000000..07d36f1 --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/annotations/Modules.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * @author swilliams + * + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface Modules { + + Module[] value(); + +} diff --git a/src/main/java/org/vertx/testing/junit/annotations/Verticle.java b/src/main/java/org/vertx/testing/junit/annotations/Verticle.java new file mode 100644 index 0000000..0667aed --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/annotations/Verticle.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * @author swilliams + * + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface Verticle { + + boolean worker() default false; + + String main(); + + int instances() default 1; + + String jsonConfig() default "{}"; + + String[] urls() default {}; + +} diff --git a/src/main/java/org/vertx/testing/junit/annotations/Verticles.java b/src/main/java/org/vertx/testing/junit/annotations/Verticles.java new file mode 100644 index 0000000..a563488 --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/annotations/Verticles.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * @author swilliams + * + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface Verticles { + + Verticle[] value(); + +} diff --git a/src/main/java/org/vertx/testing/junit/annotations/VertxConfig.java b/src/main/java/org/vertx/testing/junit/annotations/VertxConfig.java new file mode 100644 index 0000000..c16fb81 --- /dev/null +++ b/src/main/java/org/vertx/testing/junit/annotations/VertxConfig.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * @author swilliams + * + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface VertxConfig { + + String hostname() default "localhost"; + + int port(); + +} diff --git a/src/main/java/org/vertx/testing/support/VerticleManagerSupport.java b/src/main/java/org/vertx/testing/support/VerticleManagerSupport.java new file mode 100644 index 0000000..ef76491 --- /dev/null +++ b/src/main/java/org/vertx/testing/support/VerticleManagerSupport.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.support; + +import org.vertx.java.deploy.impl.VerticleManager; + + +/** + * @author swilliams + * + */ +public interface VerticleManagerSupport { + + VerticleManager getManager(); + + void setManager(VerticleManager manager); + +} \ No newline at end of file diff --git a/src/main/java/org/vertx/testing/support/VertxSupport.java b/src/main/java/org/vertx/testing/support/VertxSupport.java new file mode 100644 index 0000000..6e1370a --- /dev/null +++ b/src/main/java/org/vertx/testing/support/VertxSupport.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.support; + +import org.vertx.java.core.Vertx; + + +/** + * @author swilliams + * + */ +public interface VertxSupport { + + void setVertx(Vertx vertx); + + Vertx getVertx(); + +} \ No newline at end of file diff --git a/src/main/java/org/vertx/testing/support/VertxTestBase.java b/src/main/java/org/vertx/testing/support/VertxTestBase.java new file mode 100644 index 0000000..e9a3996 --- /dev/null +++ b/src/main/java/org/vertx/testing/support/VertxTestBase.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.support; + +import org.vertx.java.core.Vertx; +import org.vertx.java.deploy.impl.VerticleManager; + + +/** + * @author swilliams + * + */ +public class VertxTestBase implements VertxSupport, VerticleManagerSupport { + + private Vertx vertx; + + private VerticleManager manager; + + public void setVertx(Vertx vertx) { + this.vertx = vertx; + } + + public Vertx getVertx() { + return vertx; + } + + public VerticleManager getManager() { + return manager; + } + + public void setManager(VerticleManager manager) { + this.manager = manager; + } + +} diff --git a/src/main/java/org/vertx/testing/support/package-info.java b/src/main/java/org/vertx/testing/support/package-info.java new file mode 100644 index 0000000..7ac5967 --- /dev/null +++ b/src/main/java/org/vertx/testing/support/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author swilliams + * + */ +package org.vertx.testing.support; \ No newline at end of file diff --git a/src/test/java/org/vertx/testing/junit/ModuleAnnotationTest.java b/src/test/java/org/vertx/testing/junit/ModuleAnnotationTest.java new file mode 100644 index 0000000..50d1fbb --- /dev/null +++ b/src/test/java/org/vertx/testing/junit/ModuleAnnotationTest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.vertx.testing.junit.VertxConfigurableJUnit4Runner; +import org.vertx.testing.junit.annotations.Module; +import org.vertx.testing.junit.annotations.Modules; +import org.vertx.testing.support.VertxTestBase; + + +/** + * @author swilliams + * + */ +@RunWith(VertxConfigurableJUnit4Runner.class) +@Modules({ + @Module(name="test.echo0-v1.0") +}) +public class ModuleAnnotationTest extends VertxTestBase { + + private long timeout = 10L; + + @Before + public void setup() { + this.timeout = Long.parseLong(System.getProperty("vertx.test.timeout", "15L")); + } + + @Test + public void testModuleEcho0() { + + String QUESTION = "How now brown cow?"; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.mods.echo0", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + Assert.fail(e.getMessage()); + } + + } + + @Test + @Module(name="test.echo1-v1.0") + public void testModuleEcho1() { + String QUESTION = "Is it beer oclock yet?"; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.mods.echo1", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + Assert.fail(e.getMessage()); + } + + } + + @Test + @Modules({ + @Module(name="test.echo2-v1.0") + }) + public void testModulesEcho2() { + String QUESTION = "What ho!"; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.mods.echo2", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + Assert.fail(e.getMessage()); + } + + } + +} diff --git a/src/test/java/org/vertx/testing/junit/QueueReplyHandler.java b/src/test/java/org/vertx/testing/junit/QueueReplyHandler.java new file mode 100644 index 0000000..750abc9 --- /dev/null +++ b/src/test/java/org/vertx/testing/junit/QueueReplyHandler.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.vertx.java.core.Handler; +import org.vertx.java.core.eventbus.Message; + +/** + * @author swilliams + * + * @param + */ +final class QueueReplyHandler implements Handler> { + + private final LinkedBlockingQueue queue; + private final long timeout; + + QueueReplyHandler(LinkedBlockingQueue queue, long timeout) { + this.queue = queue; + this.timeout = timeout; + } + + @Override + public void handle(Message event) { + + try { + queue.offer(event.body, timeout, TimeUnit.SECONDS); + + } catch (InterruptedException e) { + Assert.fail(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/test/java/org/vertx/testing/junit/SimpleEchoTest.java b/src/test/java/org/vertx/testing/junit/SimpleEchoTest.java new file mode 100644 index 0000000..b26d000 --- /dev/null +++ b/src/test/java/org/vertx/testing/junit/SimpleEchoTest.java @@ -0,0 +1,82 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.vertx.java.core.Handler; +import org.vertx.java.core.eventbus.Message; +import org.vertx.testing.junit.VertxConfigurableJUnit4Runner; +import org.vertx.testing.support.VertxTestBase; + + +/** + * @author swilliams + * + */ +@RunWith(VertxConfigurableJUnit4Runner.class) +public class SimpleEchoTest extends VertxTestBase { + + private static final String QUESTION = "Hello World"; + + private static final String TEST_ADDRESS = "vertx.test.echo"; + + @Before + public void setup() { + Assert.assertNotNull(super.getVertx()); + + getVertx().eventBus().registerHandler(TEST_ADDRESS, new Handler>() { + @Override + public void handle(Message event) { + if (QUESTION.equals(event.body)) { + event.reply(event.body); + } + else { + event.reply("huh?"); + } + }}); + + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + // + } + } + + @Test + public void test() { + + final long timeout = 10L; + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send(TEST_ADDRESS, QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + // + } + } + +} diff --git a/src/test/java/org/vertx/testing/junit/VerticleAnnotationTest.java b/src/test/java/org/vertx/testing/junit/VerticleAnnotationTest.java new file mode 100644 index 0000000..2195427 --- /dev/null +++ b/src/test/java/org/vertx/testing/junit/VerticleAnnotationTest.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.testing.junit; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.vertx.testing.junit.VertxConfigurableJUnit4Runner; +import org.vertx.testing.junit.annotations.Verticle; +import org.vertx.testing.junit.annotations.Verticles; +import org.vertx.testing.support.VertxTestBase; + + +/** + * @author swilliams + * + */ +@RunWith(VertxConfigurableJUnit4Runner.class) +@Verticle(main="test_verticle0.js") +public class VerticleAnnotationTest extends VertxTestBase { + + private long timeout = 10L; + + @Before + public void setup() { + this.timeout = Long.parseLong(System.getProperty("vertx.test.timeout", "15L")); + } + + @Test + public void testVerticle0() { + String QUESTION = "I say, anyone for cricket?"; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.echo0", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + // + } + } + + @Test + @Verticle(main="test_verticle1.js") + public void testVerticle1() { + String QUESTION = "Oh no. Not penalties again..."; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.echo1", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + // + } + } + + @Test + @Verticles({ + @Verticle(main="test_verticle2.js") + }) + public void testVerticles2() { + String QUESTION = "Smashing fun, what!"; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.echo2", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + // + } + } + +} diff --git a/src/test/mods/test.echo0-v1.0/echo0.js b/src/test/mods/test.echo0-v1.0/echo0.js new file mode 100644 index 0000000..341f3b4 --- /dev/null +++ b/src/test/mods/test.echo0-v1.0/echo0.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; +var address = 'vertx.test.mods.echo0'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); + diff --git a/src/test/mods/test.echo0-v1.0/mod.json b/src/test/mods/test.echo0-v1.0/mod.json new file mode 100644 index 0000000..35371e4 --- /dev/null +++ b/src/test/mods/test.echo0-v1.0/mod.json @@ -0,0 +1,3 @@ +{ + "main":"echo0.js" +} \ No newline at end of file diff --git a/src/test/mods/test.echo1-v1.0/echo1.js b/src/test/mods/test.echo1-v1.0/echo1.js new file mode 100644 index 0000000..fdd1d78 --- /dev/null +++ b/src/test/mods/test.echo1-v1.0/echo1.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; +var address = 'vertx.test.mods.echo1'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); + diff --git a/src/test/mods/test.echo1-v1.0/mod.json b/src/test/mods/test.echo1-v1.0/mod.json new file mode 100644 index 0000000..4b020d7 --- /dev/null +++ b/src/test/mods/test.echo1-v1.0/mod.json @@ -0,0 +1,3 @@ +{ + "main":"echo1.js" +} \ No newline at end of file diff --git a/src/test/mods/test.echo2-v1.0/echo2.js b/src/test/mods/test.echo2-v1.0/echo2.js new file mode 100644 index 0000000..93d107a --- /dev/null +++ b/src/test/mods/test.echo2-v1.0/echo2.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; +var address = 'vertx.test.mods.echo2'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); + diff --git a/src/test/mods/test.echo2-v1.0/mod.json b/src/test/mods/test.echo2-v1.0/mod.json new file mode 100644 index 0000000..b4b5d8b --- /dev/null +++ b/src/test/mods/test.echo2-v1.0/mod.json @@ -0,0 +1,3 @@ +{ + "main":"echo2.js" +} \ No newline at end of file diff --git a/src/test/resources/test_client.js b/src/test/resources/test_client.js new file mode 100644 index 0000000..37cc2a8 --- /dev/null +++ b/src/test/resources/test_client.js @@ -0,0 +1,44 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('test_utils.js') +load('vertx.js') + +var tu = new TestUtils(); +var eb = vertx.eventBus; + +function testSpring() { + var msg = { + body: 'this is the body' + } + + eb.send("test", msg, function(msg) { + tu.azzert(msg.status == 'ok'); + tu.testComplete( ); + }); +} + +tu.registerTests(this); + +var config = {springConfig: 'testConfig.xml'} +var modID = vertx.deployModule('spring-v1.0', config, 1, function() { + tu.appReady(); +}); + +function vertxStop() { + tu.unregisterAll(); + tu.appStopped(); +} \ No newline at end of file diff --git a/src/test/resources/test_verticle0.js b/src/test/resources/test_verticle0.js new file mode 100644 index 0000000..f652654 --- /dev/null +++ b/src/test/resources/test_verticle0.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; + +var address = 'vertx.test.echo0'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); diff --git a/src/test/resources/test_verticle1.js b/src/test/resources/test_verticle1.js new file mode 100644 index 0000000..87c2a2a --- /dev/null +++ b/src/test/resources/test_verticle1.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; + +var address = 'vertx.test.echo1'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); diff --git a/src/test/resources/test_verticle2.js b/src/test/resources/test_verticle2.js new file mode 100644 index 0000000..df69b6a --- /dev/null +++ b/src/test/resources/test_verticle2.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; + +var address = 'vertx.test.echo2'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); From da1b88cb14ed5b6a912d801b27ab8426abb64516 Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Mon, 27 Aug 2012 14:43:28 +0100 Subject: [PATCH 03/18] move package --- gradle.properties | 2 +- .../junit/CountDownLatchDoneHandler.java | 2 +- .../test}/junit/Deployer.java | 32 +++++++++---------- .../junit/VertxConfigurableJUnit4Runner.java | 8 ++--- .../test}/junit/VertxRule.java | 2 +- .../test/junit/annotations/TestModule.java} | 4 +-- .../test/junit/annotations/TestModules.java} | 6 ++-- .../test/junit/annotations/TestVerticle.java} | 4 +-- .../junit/annotations/TestVerticles.java} | 6 ++-- .../test}/junit/annotations/VertxConfig.java | 2 +- .../support/VerticleManagerSupport.java | 2 +- .../test/junit}/support/VertxSupport.java | 2 +- .../test/junit}/support/VertxTestBase.java | 2 +- .../test/junit}/support/package-info.java | 2 +- .../test}/QueueReplyHandler.java | 6 ++-- .../test}/junit/ModuleAnnotationTest.java | 21 ++++++------ .../test}/junit/SimpleEchoTest.java | 7 ++-- .../test}/junit/VerticleAnnotationTest.java | 19 +++++------ 18 files changed, 66 insertions(+), 63 deletions(-) rename src/main/java/org/vertx/{testing => java/test}/junit/CountDownLatchDoneHandler.java (96%) rename src/main/java/org/vertx/{testing => java/test}/junit/Deployer.java (82%) rename src/main/java/org/vertx/{testing => java/test}/junit/VertxConfigurableJUnit4Runner.java (93%) rename src/main/java/org/vertx/{testing => java/test}/junit/VertxRule.java (97%) rename src/main/java/org/vertx/{testing/junit/annotations/Module.java => java/test/junit/annotations/TestModule.java} (93%) rename src/main/java/org/vertx/{testing/junit/annotations/Modules.java => java/test/junit/annotations/TestModules.java} (90%) rename src/main/java/org/vertx/{testing/junit/annotations/Verticle.java => java/test/junit/annotations/TestVerticle.java} (93%) rename src/main/java/org/vertx/{testing/junit/annotations/Verticles.java => java/test/junit/annotations/TestVerticles.java} (90%) rename src/main/java/org/vertx/{testing => java/test}/junit/annotations/VertxConfig.java (95%) rename src/main/java/org/vertx/{testing => java/test/junit}/support/VerticleManagerSupport.java (94%) rename src/main/java/org/vertx/{testing => java/test/junit}/support/VertxSupport.java (94%) rename src/main/java/org/vertx/{testing => java/test/junit}/support/VertxTestBase.java (96%) rename src/main/java/org/vertx/{testing => java/test/junit}/support/package-info.java (93%) rename src/test/java/org/vertx/{testing/junit => java/test}/QueueReplyHandler.java (87%) rename src/test/java/org/vertx/{testing => java/test}/junit/ModuleAnnotationTest.java (85%) rename src/test/java/org/vertx/{testing => java/test}/junit/SimpleEchoTest.java (91%) rename src/test/java/org/vertx/{testing => java/test}/junit/VerticleAnnotationTest.java (85%) diff --git a/gradle.properties b/gradle.properties index 1e8ebcc..a975967 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ # version=1.0 group=org.vert-x -modulename=test-annotations +modulename=vertx-junit-annotations gradleVersion=1.0 vertxVersion=1.2.3.final diff --git a/src/main/java/org/vertx/testing/junit/CountDownLatchDoneHandler.java b/src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java similarity index 96% rename from src/main/java/org/vertx/testing/junit/CountDownLatchDoneHandler.java rename to src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java index 4b3dff2..5938568 100644 --- a/src/main/java/org/vertx/testing/junit/CountDownLatchDoneHandler.java +++ b/src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit; +package org.vertx.java.test.junit; import java.util.concurrent.CountDownLatch; diff --git a/src/main/java/org/vertx/testing/junit/Deployer.java b/src/main/java/org/vertx/java/test/junit/Deployer.java similarity index 82% rename from src/main/java/org/vertx/testing/junit/Deployer.java rename to src/main/java/org/vertx/java/test/junit/Deployer.java index 3b0b3c2..800e8cd 100644 --- a/src/main/java/org/vertx/testing/junit/Deployer.java +++ b/src/main/java/org/vertx/java/test/junit/Deployer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit; +package org.vertx.java.test.junit; import java.io.File; import java.io.IOException; @@ -30,10 +30,10 @@ import org.junit.runner.Description; import org.vertx.java.core.json.JsonObject; import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.testing.junit.annotations.Module; -import org.vertx.testing.junit.annotations.Modules; -import org.vertx.testing.junit.annotations.Verticle; -import org.vertx.testing.junit.annotations.Verticles; +import org.vertx.java.test.junit.annotations.TestModule; +import org.vertx.java.test.junit.annotations.TestModules; +import org.vertx.java.test.junit.annotations.TestVerticle; +import org.vertx.java.test.junit.annotations.TestVerticles; /** @@ -52,10 +52,10 @@ public class Deployer { } public void deploy(Description description) { - final Modules amodules = description.getAnnotation(Modules.class); - final Module amodule = description.getAnnotation(Module.class); - final Verticles verticles = description.getAnnotation(Verticles.class); - final Verticle verticle = description.getAnnotation(Verticle.class); + final TestModules amodules = description.getAnnotation(TestModules.class); + final TestModule amodule = description.getAnnotation(TestModule.class); + final TestVerticles verticles = description.getAnnotation(TestVerticles.class); + final TestVerticle verticle = description.getAnnotation(TestVerticle.class); deployModules(amodules); deployModule(amodule); @@ -64,14 +64,14 @@ public void deploy(Description description) { } - private void deployVerticles(Verticles verticles) { + private void deployVerticles(TestVerticles verticles) { if (verticles == null) { return; } final CountDownLatch latch = new CountDownLatch(verticles.value().length); - for (Verticle v : verticles.value()) { + for (TestVerticle v : verticles.value()) { JsonObject config = getJsonConfig(v.jsonConfig()); URL[] urls = findVerticleURLs(v); @@ -81,7 +81,7 @@ private void deployVerticles(Verticles verticles) { await(latch); } - private void deployVerticle(Verticle v) { + private void deployVerticle(TestVerticle v) { if (v == null) { return; } @@ -94,14 +94,14 @@ private void deployVerticle(Verticle v) { await(latch); } - private void deployModules(Modules amodules) { + private void deployModules(TestModules amodules) { if (amodules == null) { return; } final CountDownLatch latch = new CountDownLatch(amodules.value().length); - for (Module m : amodules.value()) { + for (TestModule m : amodules.value()) { JsonObject config = getJsonConfig(m.jsonConfig()); manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); } @@ -109,7 +109,7 @@ private void deployModules(Modules amodules) { await(latch); } - private void deployModule(Module m) { + private void deployModule(TestModule m) { if (m == null) { return; } @@ -122,7 +122,7 @@ private void deployModule(Module m) { await(latch); } - private URL[] findVerticleURLs(Verticle v) { + private URL[] findVerticleURLs(TestVerticle v) { Set urlSet = new HashSet(); if (v.urls().length > 0) { diff --git a/src/main/java/org/vertx/testing/junit/VertxConfigurableJUnit4Runner.java b/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java similarity index 93% rename from src/main/java/org/vertx/testing/junit/VertxConfigurableJUnit4Runner.java rename to src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java index 9057c36..f087a2d 100644 --- a/src/main/java/org/vertx/testing/junit/VertxConfigurableJUnit4Runner.java +++ b/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit; +package org.vertx.java.test.junit; import java.io.File; import java.util.HashSet; @@ -29,9 +29,9 @@ import org.vertx.java.core.impl.DefaultVertx; import org.vertx.java.core.impl.VertxInternal; import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.testing.junit.annotations.VertxConfig; -import org.vertx.testing.support.VerticleManagerSupport; -import org.vertx.testing.support.VertxSupport; +import org.vertx.java.test.junit.annotations.VertxConfig; +import org.vertx.java.test.junit.support.VerticleManagerSupport; +import org.vertx.java.test.junit.support.VertxSupport; /** diff --git a/src/main/java/org/vertx/testing/junit/VertxRule.java b/src/main/java/org/vertx/java/test/junit/VertxRule.java similarity index 97% rename from src/main/java/org/vertx/testing/junit/VertxRule.java rename to src/main/java/org/vertx/java/test/junit/VertxRule.java index 600afaf..d02e0ee 100644 --- a/src/main/java/org/vertx/testing/junit/VertxRule.java +++ b/src/main/java/org/vertx/java/test/junit/VertxRule.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit; +package org.vertx.java.test.junit; import org.junit.rules.TestRule; import org.junit.runner.Description; diff --git a/src/main/java/org/vertx/testing/junit/annotations/Module.java b/src/main/java/org/vertx/java/test/junit/annotations/TestModule.java similarity index 93% rename from src/main/java/org/vertx/testing/junit/annotations/Module.java rename to src/main/java/org/vertx/java/test/junit/annotations/TestModule.java index f784661..74b5b2b 100644 --- a/src/main/java/org/vertx/testing/junit/annotations/Module.java +++ b/src/main/java/org/vertx/java/test/junit/annotations/TestModule.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit.annotations; +package org.vertx.java.test.junit.annotations; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -31,7 +31,7 @@ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) -public @interface Module { +public @interface TestModule { String name(); diff --git a/src/main/java/org/vertx/testing/junit/annotations/Modules.java b/src/main/java/org/vertx/java/test/junit/annotations/TestModules.java similarity index 90% rename from src/main/java/org/vertx/testing/junit/annotations/Modules.java rename to src/main/java/org/vertx/java/test/junit/annotations/TestModules.java index 07d36f1..ac9974d 100644 --- a/src/main/java/org/vertx/testing/junit/annotations/Modules.java +++ b/src/main/java/org/vertx/java/test/junit/annotations/TestModules.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit.annotations; +package org.vertx.java.test.junit.annotations; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -31,8 +31,8 @@ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) -public @interface Modules { +public @interface TestModules { - Module[] value(); + TestModule[] value(); } diff --git a/src/main/java/org/vertx/testing/junit/annotations/Verticle.java b/src/main/java/org/vertx/java/test/junit/annotations/TestVerticle.java similarity index 93% rename from src/main/java/org/vertx/testing/junit/annotations/Verticle.java rename to src/main/java/org/vertx/java/test/junit/annotations/TestVerticle.java index 0667aed..3f97079 100644 --- a/src/main/java/org/vertx/testing/junit/annotations/Verticle.java +++ b/src/main/java/org/vertx/java/test/junit/annotations/TestVerticle.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit.annotations; +package org.vertx.java.test.junit.annotations; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -31,7 +31,7 @@ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) -public @interface Verticle { +public @interface TestVerticle { boolean worker() default false; diff --git a/src/main/java/org/vertx/testing/junit/annotations/Verticles.java b/src/main/java/org/vertx/java/test/junit/annotations/TestVerticles.java similarity index 90% rename from src/main/java/org/vertx/testing/junit/annotations/Verticles.java rename to src/main/java/org/vertx/java/test/junit/annotations/TestVerticles.java index a563488..3da8441 100644 --- a/src/main/java/org/vertx/testing/junit/annotations/Verticles.java +++ b/src/main/java/org/vertx/java/test/junit/annotations/TestVerticles.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit.annotations; +package org.vertx.java.test.junit.annotations; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -31,8 +31,8 @@ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) -public @interface Verticles { +public @interface TestVerticles { - Verticle[] value(); + TestVerticle[] value(); } diff --git a/src/main/java/org/vertx/testing/junit/annotations/VertxConfig.java b/src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java similarity index 95% rename from src/main/java/org/vertx/testing/junit/annotations/VertxConfig.java rename to src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java index c16fb81..7449486 100644 --- a/src/main/java/org/vertx/testing/junit/annotations/VertxConfig.java +++ b/src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit.annotations; +package org.vertx.java.test.junit.annotations; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/src/main/java/org/vertx/testing/support/VerticleManagerSupport.java b/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java similarity index 94% rename from src/main/java/org/vertx/testing/support/VerticleManagerSupport.java rename to src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java index ef76491..92e224f 100644 --- a/src/main/java/org/vertx/testing/support/VerticleManagerSupport.java +++ b/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.support; +package org.vertx.java.test.junit.support; import org.vertx.java.deploy.impl.VerticleManager; diff --git a/src/main/java/org/vertx/testing/support/VertxSupport.java b/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java similarity index 94% rename from src/main/java/org/vertx/testing/support/VertxSupport.java rename to src/main/java/org/vertx/java/test/junit/support/VertxSupport.java index 6e1370a..55eb30d 100644 --- a/src/main/java/org/vertx/testing/support/VertxSupport.java +++ b/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.support; +package org.vertx.java.test.junit.support; import org.vertx.java.core.Vertx; diff --git a/src/main/java/org/vertx/testing/support/VertxTestBase.java b/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java similarity index 96% rename from src/main/java/org/vertx/testing/support/VertxTestBase.java rename to src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java index e9a3996..21aba86 100644 --- a/src/main/java/org/vertx/testing/support/VertxTestBase.java +++ b/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.support; +package org.vertx.java.test.junit.support; import org.vertx.java.core.Vertx; import org.vertx.java.deploy.impl.VerticleManager; diff --git a/src/main/java/org/vertx/testing/support/package-info.java b/src/main/java/org/vertx/java/test/junit/support/package-info.java similarity index 93% rename from src/main/java/org/vertx/testing/support/package-info.java rename to src/main/java/org/vertx/java/test/junit/support/package-info.java index 7ac5967..aa82c25 100644 --- a/src/main/java/org/vertx/testing/support/package-info.java +++ b/src/main/java/org/vertx/java/test/junit/support/package-info.java @@ -17,4 +17,4 @@ * @author swilliams * */ -package org.vertx.testing.support; \ No newline at end of file +package org.vertx.java.test.junit.support; \ No newline at end of file diff --git a/src/test/java/org/vertx/testing/junit/QueueReplyHandler.java b/src/test/java/org/vertx/java/test/QueueReplyHandler.java similarity index 87% rename from src/test/java/org/vertx/testing/junit/QueueReplyHandler.java rename to src/test/java/org/vertx/java/test/QueueReplyHandler.java index 750abc9..77944e0 100644 --- a/src/test/java/org/vertx/testing/junit/QueueReplyHandler.java +++ b/src/test/java/org/vertx/java/test/QueueReplyHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit; +package org.vertx.java.test; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -27,12 +27,12 @@ * * @param */ -final class QueueReplyHandler implements Handler> { +public class QueueReplyHandler implements Handler> { private final LinkedBlockingQueue queue; private final long timeout; - QueueReplyHandler(LinkedBlockingQueue queue, long timeout) { + public QueueReplyHandler(LinkedBlockingQueue queue, long timeout) { this.queue = queue; this.timeout = timeout; } diff --git a/src/test/java/org/vertx/testing/junit/ModuleAnnotationTest.java b/src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java similarity index 85% rename from src/test/java/org/vertx/testing/junit/ModuleAnnotationTest.java rename to src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java index 50d1fbb..e191390 100644 --- a/src/test/java/org/vertx/testing/junit/ModuleAnnotationTest.java +++ b/src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit; +package org.vertx.java.test.junit; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -23,10 +23,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.vertx.testing.junit.VertxConfigurableJUnit4Runner; -import org.vertx.testing.junit.annotations.Module; -import org.vertx.testing.junit.annotations.Modules; -import org.vertx.testing.support.VertxTestBase; +import org.vertx.java.test.QueueReplyHandler; +import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; +import org.vertx.java.test.junit.annotations.TestModule; +import org.vertx.java.test.junit.annotations.TestModules; +import org.vertx.java.test.junit.support.VertxTestBase; /** @@ -34,8 +35,8 @@ * */ @RunWith(VertxConfigurableJUnit4Runner.class) -@Modules({ - @Module(name="test.echo0-v1.0") +@TestModules({ + @TestModule(name="test.echo0-v1.0") }) public class ModuleAnnotationTest extends VertxTestBase { @@ -67,7 +68,7 @@ public void testModuleEcho0() { } @Test - @Module(name="test.echo1-v1.0") + @TestModule(name="test.echo1-v1.0") public void testModuleEcho1() { String QUESTION = "Is it beer oclock yet?"; @@ -87,8 +88,8 @@ public void testModuleEcho1() { } @Test - @Modules({ - @Module(name="test.echo2-v1.0") + @TestModules({ + @TestModule(name="test.echo2-v1.0") }) public void testModulesEcho2() { String QUESTION = "What ho!"; diff --git a/src/test/java/org/vertx/testing/junit/SimpleEchoTest.java b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java similarity index 91% rename from src/test/java/org/vertx/testing/junit/SimpleEchoTest.java rename to src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java index b26d000..c5796e9 100644 --- a/src/test/java/org/vertx/testing/junit/SimpleEchoTest.java +++ b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit; +package org.vertx.java.test.junit; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -24,8 +24,9 @@ import org.junit.runner.RunWith; import org.vertx.java.core.Handler; import org.vertx.java.core.eventbus.Message; -import org.vertx.testing.junit.VertxConfigurableJUnit4Runner; -import org.vertx.testing.support.VertxTestBase; +import org.vertx.java.test.QueueReplyHandler; +import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; +import org.vertx.java.test.junit.support.VertxTestBase; /** diff --git a/src/test/java/org/vertx/testing/junit/VerticleAnnotationTest.java b/src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java similarity index 85% rename from src/test/java/org/vertx/testing/junit/VerticleAnnotationTest.java rename to src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java index 2195427..748ec93 100644 --- a/src/test/java/org/vertx/testing/junit/VerticleAnnotationTest.java +++ b/src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.testing.junit; +package org.vertx.java.test.junit; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -23,10 +23,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.vertx.testing.junit.VertxConfigurableJUnit4Runner; -import org.vertx.testing.junit.annotations.Verticle; -import org.vertx.testing.junit.annotations.Verticles; -import org.vertx.testing.support.VertxTestBase; +import org.vertx.java.test.QueueReplyHandler; +import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; +import org.vertx.java.test.junit.annotations.TestVerticle; +import org.vertx.java.test.junit.annotations.TestVerticles; +import org.vertx.java.test.junit.support.VertxTestBase; /** @@ -34,7 +35,7 @@ * */ @RunWith(VertxConfigurableJUnit4Runner.class) -@Verticle(main="test_verticle0.js") +@TestVerticle(main="test_verticle0.js") public class VerticleAnnotationTest extends VertxTestBase { private long timeout = 10L; @@ -63,7 +64,7 @@ public void testVerticle0() { } @Test - @Verticle(main="test_verticle1.js") + @TestVerticle(main="test_verticle1.js") public void testVerticle1() { String QUESTION = "Oh no. Not penalties again..."; @@ -82,8 +83,8 @@ public void testVerticle1() { } @Test - @Verticles({ - @Verticle(main="test_verticle2.js") + @TestVerticles({ + @TestVerticle(main="test_verticle2.js") }) public void testVerticles2() { String QUESTION = "Smashing fun, what!"; From 154303163e3a99777fabd400a9a873f2d401c371 Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Mon, 27 Aug 2012 14:45:34 +0100 Subject: [PATCH 04/18] add maven stuff --- gradle/maven.gradle | 130 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 gradle/maven.gradle diff --git a/gradle/maven.gradle b/gradle/maven.gradle new file mode 100644 index 0000000..66ef01d --- /dev/null +++ b/gradle/maven.gradle @@ -0,0 +1,130 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: 'maven' +apply plugin: 'signing' + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// custom maven tasks + +task sourceJar(type: Jar) { + description = 'Builds a source jar artifact suitable for maven deployment.' + classifier = 'sources' + from sourceSets.main.java +} + +task javadocJar(type: Jar) { + description = 'Builds a javadoc jar artifact suitable for maven deployment.' + classifier = 'javadoc' + from javadoc.destinationDir +} +javadocJar.dependsOn javadoc + +build.dependsOn sourceJar, javadocJar + +artifacts { + archives sourceJar, javadocJar +} + +if (!hasProperty('sonatypeUsername')) { + ext.sonatypeUsername = '' +} +if (!hasProperty('sonatypePassword')) { + ext.sonatypePassword = '' +} + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// maven task configuration + +ext.isReleaseVersion = !version.endsWith("SNAPSHOT") + +signing { + required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") } + sign configurations.archives +} + +uploadArchives { + group 'build' + description = "Does a maven deploy of archives artifacts" + + repositories { + mavenDeployer { + configuration = configurations.archives + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: sonatypeUsername, password: sonatypePassword) + } + + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: sonatypeUsername, password: sonatypePassword) + } + + if (isReleaseVersion) { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + } + + configurePom(pom) + } + } +} + +install { + group = 'build' + description = "Does a maven install of archives artifacts to local m2 cache" + configurePom(repositories.mavenInstaller.pom) +} + + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// configuration methods + +def configurePom(def pom) { + pom.project { + name rootProject.name + description 'vert.x - Effortless asynchronous application development for the modern web and enterprise' + groupId rootProject.group + inceptionYear '2011' + packaging 'jar' + url 'http://vertx.io' + + developers { + developer { + id 'purplefox' + name 'Tim Fox' + email 'tim@tfox.org' + } + } + + scm { + connection 'scm:https://vert-x@github.com/purplefox/vert.x' + developerConnection 'scm:git@github.com:purplefox/vert.x.git' + url 'https://github.com/purplefox/vert.x' + } + + licenses { + license { + name 'The Apache Software License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution 'repo' + } + } + + properties { + setProperty('project.build.sourceEncoding', 'UTF8') + } + } +} + From fe736ec4b810a20cd0cffa6545c8bda734b18578 Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Sat, 1 Sep 2012 22:16:32 +0100 Subject: [PATCH 05/18] Many changes. Various improvements learned from usage of lib. --- build.gradle | 3 +- .../org/vertx/java/test/junit/Deployer.java | 73 ++++++++++--- .../junit/UnexpectedTestRunnerException.java | 11 ++ .../junit/VertxConfigurableJUnit4Runner.java | 78 +++++++++++-- .../org/vertx/java/test/junit/VertxRule.java | 1 - .../test/junit/annotations/VertxConfig.java | 4 +- .../junit/support}/QueueReplyHandler.java | 18 ++- .../SimpleLatchAsyncResultHandler.java | 28 +++++ .../junit/support/VerticleManagerSupport.java | 2 - .../java/test/junit/support/VertxSupport.java | 2 - .../test/junit/support/VertxTestBase.java | 103 +++++++++++++++++- .../java/test/junit/ModuleAnnotationTest.java | 2 +- .../vertx/java/test/junit/SimpleEchoTest.java | 2 +- .../test/junit/VerticleAnnotationTest.java | 2 +- src/test/resources/test_client.js | 2 +- 15 files changed, 289 insertions(+), 42 deletions(-) create mode 100644 src/main/java/org/vertx/java/test/junit/UnexpectedTestRunnerException.java rename src/{test/java/org/vertx/java/test => main/java/org/vertx/java/test/junit/support}/QueueReplyHandler.java (73%) create mode 100644 src/main/java/org/vertx/java/test/junit/support/SimpleLatchAsyncResultHandler.java diff --git a/build.gradle b/build.gradle index 40cc6f1..ad10034 100644 --- a/build.gradle +++ b/build.gradle @@ -14,8 +14,9 @@ * limitations under the License. */ -apply from: 'gradle/setup.gradle' apply plugin: 'java' +apply from: 'gradle/setup.gradle' +apply from: 'gradle/maven.gradle' defaultTasks = ['assemble'] diff --git a/src/main/java/org/vertx/java/test/junit/Deployer.java b/src/main/java/org/vertx/java/test/junit/Deployer.java index 800e8cd..6cecf86 100644 --- a/src/main/java/org/vertx/java/test/junit/Deployer.java +++ b/src/main/java/org/vertx/java/test/junit/Deployer.java @@ -26,6 +26,7 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import org.junit.runner.Description; import org.vertx.java.core.json.JsonObject; @@ -42,25 +43,25 @@ */ public class Deployer { + private final AtomicInteger deploymentCounter = new AtomicInteger(0); + private final File modDir; - + private final VerticleManager manager; - Deployer(VerticleManager manager, File modDir) { + private long shutdownTimeout; + + Deployer(VerticleManager manager, File modDir, long shutdownTimeout) { this.manager = manager; this.modDir = modDir; + this.shutdownTimeout = shutdownTimeout; } public void deploy(Description description) { - final TestModules amodules = description.getAnnotation(TestModules.class); - final TestModule amodule = description.getAnnotation(TestModule.class); - final TestVerticles verticles = description.getAnnotation(TestVerticles.class); - final TestVerticle verticle = description.getAnnotation(TestVerticle.class); - - deployModules(amodules); - deployModule(amodule); - deployVerticles(verticles); - deployVerticle(verticle); + deployModules(description.getAnnotation(TestModules.class)); + deployModule(description.getAnnotation(TestModule.class)); + deployVerticles(description.getAnnotation(TestVerticles.class)); + deployVerticle(description.getAnnotation(TestVerticle.class)); } @@ -76,6 +77,7 @@ private void deployVerticles(TestVerticles verticles) { URL[] urls = findVerticleURLs(v); manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, new CountDownLatchDoneHandler(latch)); + deploymentCounter.incrementAndGet(); } await(latch); @@ -89,7 +91,9 @@ private void deployVerticle(TestVerticle v) { final CountDownLatch latch = new CountDownLatch(1); JsonObject config = getJsonConfig(v.jsonConfig()); URL[] urls = findVerticleURLs(v); + manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, new CountDownLatchDoneHandler(latch)); + deploymentCounter.incrementAndGet(); await(latch); } @@ -104,6 +108,7 @@ private void deployModules(TestModules amodules) { for (TestModule m : amodules.value()) { JsonObject config = getJsonConfig(m.jsonConfig()); manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); + deploymentCounter.incrementAndGet(); } await(latch); @@ -118,6 +123,7 @@ private void deployModule(TestModule m) { JsonObject config = getJsonConfig(m.jsonConfig()); manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); + deploymentCounter.incrementAndGet(); await(latch); } @@ -127,24 +133,52 @@ private URL[] findVerticleURLs(TestVerticle v) { if (v.urls().length > 0) { for (String path : v.urls()) { + try { URL url = new File(path).toURI().toURL(); urlSet.add(url); } catch (Exception e) { + // TODO log something here e.printStackTrace(); } } } try { - // contortions to get parent - URL url = getClass().getClassLoader().getResource(v.main()); - url = Paths.get(url.toURI()).getParent().toUri().toURL(); - urlSet.add(url); + String main = v.main(); + if (main.indexOf(':') > -1) { + main = main.substring(main.indexOf(':') + 1); + } + + // check for class, prep for locating root URL + int parts = 0; + if (!main.endsWith(".xml")) { + parts = main.split("\\.").length; + main = main.replaceAll("\\.", "/"); + main = main + ".class"; + } + + // contortions to get parent, may not be entirely accurate... + // URL url = getClass().getClassLoader().getResource(main); + URL url = Thread.currentThread().getContextClassLoader().getResource(main); + + if (url != null) { + Path path = Paths.get(url.toURI()); + + int i = parts; + while (i > 0) { + path = path.getParent(); + i--; + } + + url = path.toUri().toURL(); + urlSet.add(url); + } } catch (Exception e) { + // TODO log something here e.printStackTrace(); } @@ -177,11 +211,16 @@ private JsonObject getJsonConfig(String jsonConfig) { private void await(final CountDownLatch latch) { try { - latch.await(30L, TimeUnit.SECONDS); + latch.await(shutdownTimeout, TimeUnit.SECONDS); } catch (InterruptedException e) { - // TODO Auto-generated catch block + // TODO log something here e.printStackTrace(); } } + + public int getDeploymentCount() { + return deploymentCounter.get(); + } + } diff --git a/src/main/java/org/vertx/java/test/junit/UnexpectedTestRunnerException.java b/src/main/java/org/vertx/java/test/junit/UnexpectedTestRunnerException.java new file mode 100644 index 0000000..042b1a0 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/UnexpectedTestRunnerException.java @@ -0,0 +1,11 @@ +package org.vertx.java.test.junit; + +public class UnexpectedTestRunnerException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public UnexpectedTestRunnerException(Exception e) { + super(e); + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java b/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java index f087a2d..399d0be 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java +++ b/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java @@ -16,6 +16,7 @@ package org.vertx.java.test.junit; import java.io.File; +import java.lang.reflect.Method; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -26,8 +27,11 @@ import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.InitializationError; +import org.vertx.java.core.Vertx; import org.vertx.java.core.impl.DefaultVertx; import org.vertx.java.core.impl.VertxInternal; +import org.vertx.java.deploy.Container; +import org.vertx.java.deploy.Verticle; import org.vertx.java.deploy.impl.VerticleManager; import org.vertx.java.test.junit.annotations.VertxConfig; import org.vertx.java.test.junit.support.VerticleManagerSupport; @@ -48,18 +52,30 @@ public class VertxConfigurableJUnit4Runner extends BlockJUnit4ClassRunner { private Deployer deployer; + private Verticle verticle; + + /** + * @param klass + * @throws InitializationError + */ public VertxConfigurableJUnit4Runner(Class klass) throws InitializationError { super(klass); } + /** + * {@inheritDoc} + */ @Override public void run(RunNotifier notifier) { + long timeout; VertxConfig vertxConfig = getDescription().getAnnotation(VertxConfig.class); if (vertxConfig != null) { + timeout = vertxConfig.shutdownTimeoutSeconds(); this.vertx = new DefaultVertx(vertxConfig.port(), vertxConfig.hostname()); } else { + timeout = 30L; this.vertx = new DefaultVertx(); } @@ -68,10 +84,10 @@ public void run(RunNotifier notifier) { String vertxMods = System.getProperty("vertx.mods"); File currentModDir = new File(vertxMods); if (!currentModDir.exists()) { - throw new RuntimeException("vert.mods dir doesn't exist! " + vertxMods); + currentModDir.mkdirs(); } - this.deployer = new Deployer(verticleManager, currentModDir); + this.deployer = new Deployer(verticleManager, currentModDir, timeout); deployer.deploy(getDescription()); super.run(notifier); @@ -80,11 +96,14 @@ public void run(RunNotifier notifier) { } + /** + * {@inheritDoc} + */ @Override protected List getTestRules(Object target) { - + if (!classCache.contains(target.toString())) { - configureTarget(target); + configureTargetTestClass(target); classCache.add(target.toString()); } @@ -93,29 +112,74 @@ protected List getTestRules(Object target) { return rules; } - private void configureTarget(Object target) { + /** + * @param target + */ + private void configureTargetTestClass(Object target) { + + if (target instanceof Verticle) { + // TODO do something clever here... + System.out.printf("Test class is a Verticle: %s %n", target.getClass().getName()); + this.verticle = (Verticle) target; + verticle.setVertx(vertx); + verticle.setContainer(new Container(verticleManager)); + try { + verticle.start(); + } catch (Exception e) { + throw new UnexpectedTestRunnerException(e); + } + } + // discover VertxSupport if (target instanceof VertxSupport) { VertxSupport support = (VertxSupport) target; support.setVertx(vertx); } + // discover VerticleManager support if (target instanceof VerticleManagerSupport) { VerticleManagerSupport support = (VerticleManagerSupport) target; support.setManager(verticleManager); } + // discover setVertx method + try { + Method setVertxMethod = target.getClass().getMethod("setVertx", Vertx.class); + setVertxMethod.invoke(target, vertx); + } catch (Exception e) { + // we can ignore this if the method isn't present + } + + // discover setVerticleManager method + try { + Method setVerticleManagerMethod = target.getClass().getMethod("setVerticleManager", VerticleManager.class); + setVerticleManagerMethod.invoke(target, verticleManager); + } catch (Exception e) { + // we can ignore this if the method isn't present + } + } + /** + * + */ private void undeployAll() { + CountDownLatch latch = new CountDownLatch(1); verticleManager.undeployAll(new CountDownLatchDoneHandler(latch)); try { latch.await(); } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + // + } + + if (verticle != null) { + try { + verticle.stop(); + } catch (Exception e) { + throw new UnexpectedTestRunnerException(e); + } } } diff --git a/src/main/java/org/vertx/java/test/junit/VertxRule.java b/src/main/java/org/vertx/java/test/junit/VertxRule.java index d02e0ee..f6df304 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxRule.java +++ b/src/main/java/org/vertx/java/test/junit/VertxRule.java @@ -42,7 +42,6 @@ public void evaluate() throws Throwable { deployer.deploy(description); base.evaluate(); }}; - } } diff --git a/src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java b/src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java index 7449486..de9532c 100644 --- a/src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java +++ b/src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java @@ -35,6 +35,8 @@ String hostname() default "localhost"; - int port(); + int port() default -1; + + long shutdownTimeoutSeconds() default 30L; } diff --git a/src/test/java/org/vertx/java/test/QueueReplyHandler.java b/src/main/java/org/vertx/java/test/junit/support/QueueReplyHandler.java similarity index 73% rename from src/test/java/org/vertx/java/test/QueueReplyHandler.java rename to src/main/java/org/vertx/java/test/junit/support/QueueReplyHandler.java index 77944e0..c8a21aa 100644 --- a/src/test/java/org/vertx/java/test/QueueReplyHandler.java +++ b/src/main/java/org/vertx/java/test/junit/support/QueueReplyHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test; +package org.vertx.java.test.junit.support; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -30,18 +30,32 @@ public class QueueReplyHandler implements Handler> { private final LinkedBlockingQueue queue; + private final long timeout; + private final TimeUnit timeUnit; + + public QueueReplyHandler(LinkedBlockingQueue queue) { + this(queue, 5000L); + } + public QueueReplyHandler(LinkedBlockingQueue queue, long timeout) { + this(queue, timeout, TimeUnit.MILLISECONDS); + } + + public QueueReplyHandler(LinkedBlockingQueue queue, long timeout, TimeUnit timeUnit) { this.queue = queue; this.timeout = timeout; + this.timeUnit = timeUnit; } @Override public void handle(Message event) { try { - queue.offer(event.body, timeout, TimeUnit.SECONDS); + if (event != null && event.body != null) { + queue.offer(event.body, timeout, timeUnit); + } } catch (InterruptedException e) { Assert.fail(e.getMessage()); diff --git a/src/main/java/org/vertx/java/test/junit/support/SimpleLatchAsyncResultHandler.java b/src/main/java/org/vertx/java/test/junit/support/SimpleLatchAsyncResultHandler.java new file mode 100644 index 0000000..12e8d20 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/support/SimpleLatchAsyncResultHandler.java @@ -0,0 +1,28 @@ +package org.vertx.java.test.junit.support; + +import java.util.concurrent.CountDownLatch; + +import org.vertx.java.core.AsyncResult; +import org.vertx.java.core.AsyncResultHandler; + +public class SimpleLatchAsyncResultHandler implements AsyncResultHandler { + + private final CountDownLatch latch; + + private volatile boolean succeeded; + + public SimpleLatchAsyncResultHandler(CountDownLatch latch) { + this.latch = latch; + } + + @Override + public void handle(AsyncResult event) { + this.succeeded = event.succeeded(); + latch.countDown(); + } + + public boolean isSucceeded() { + return succeeded; + } + +} \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java b/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java index 92e224f..042c2ba 100644 --- a/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java +++ b/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java @@ -24,8 +24,6 @@ */ public interface VerticleManagerSupport { - VerticleManager getManager(); - void setManager(VerticleManager manager); } \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java b/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java index 55eb30d..24355ed 100644 --- a/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java +++ b/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java @@ -26,6 +26,4 @@ public interface VertxSupport { void setVertx(Vertx vertx); - Vertx getVertx(); - } \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java b/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java index 21aba86..5f6fcf1 100644 --- a/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java +++ b/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java @@ -15,7 +15,16 @@ */ package org.vertx.java.test.junit.support; +import java.util.Arrays; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.vertx.java.core.Handler; import org.vertx.java.core.Vertx; +import org.vertx.java.core.eventbus.EventBus; +import org.vertx.java.core.eventbus.Message; import org.vertx.java.deploy.impl.VerticleManager; @@ -23,26 +32,110 @@ * @author swilliams * */ -public class VertxTestBase implements VertxSupport, VerticleManagerSupport { +public abstract class VertxTestBase implements VertxSupport, VerticleManagerSupport { private Vertx vertx; private VerticleManager manager; + private long awaitTimeout = 5000L; + + protected VertxTestBase() { + super(); + } + + @Override public void setVertx(Vertx vertx) { this.vertx = vertx; } - public Vertx getVertx() { + @Override + public void setManager(VerticleManager manager) { + this.manager = manager; + } + + protected Vertx getVertx() { return vertx; } - public VerticleManager getManager() { + protected EventBus getEventBus() { + return vertx.eventBus(); + } + + protected VerticleManager getManager() { return manager; } - public void setManager(VerticleManager manager) { - this.manager = manager; + protected final void setAwaitTimeout(long awaitTimeout) { + this.awaitTimeout = awaitTimeout; + } + + protected final void lightSleep(long timeout) { + try { + Thread.sleep(timeout); + } catch (InterruptedException e) { + // + } + } + + protected final void testMessageEcho(String address, String message) throws Exception { + + final long timeout = 2000L; + final TimeUnit timeUnit = TimeUnit.MILLISECONDS; + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send(address, message, new QueueReplyHandler(queue, timeout, timeUnit)); + + try { + String answer = queue.poll(timeout, timeUnit); + System.out.printf("For %s Q:%s A:%s %n", address, message, message.equals(answer)); + Assert.assertTrue(message.equals(answer)); + + } catch (InterruptedException e) { + // + } + } + + protected final > String registerHandler(String address, Handler handler) { + final CountDownLatch latch = new CountDownLatch(1); + String handlerId = vertx.eventBus().registerHandler(address, handler, new SimpleLatchAsyncResultHandler(latch)); + await(latch); + return handlerId; + } + + protected final > String registerLocalHandler(String address, Handler handler) { + final CountDownLatch latch = new CountDownLatch(1); + String handlerId = vertx.eventBus().registerLocalHandler(address, handler); + await(latch); + return handlerId; + } + + protected final void unregisterHandlers(String... handlers) { + unregisterHandlers(Arrays.asList(handlers)); + } + + protected final void unregisterHandlers(Iterable iterable) { + for (String handler : iterable) { + System.out.printf("unregisterHandler: %s %n", handler); + getVertx().eventBus().unregisterHandler(handler); + } + } + + protected final void await(CountDownLatch latch) { + await(latch, this.awaitTimeout); + } + + protected final void await(CountDownLatch latch, long timeout) { + await(latch, timeout, TimeUnit.MILLISECONDS); + } + + protected final void await(CountDownLatch latch, long timeout, TimeUnit timeUnit) { + try { + latch.await(timeout, timeUnit); + } + catch (InterruptedException e) { + // + } } } diff --git a/src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java b/src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java index e191390..e5297c3 100644 --- a/src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java +++ b/src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java @@ -23,10 +23,10 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.vertx.java.test.QueueReplyHandler; import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; import org.vertx.java.test.junit.annotations.TestModule; import org.vertx.java.test.junit.annotations.TestModules; +import org.vertx.java.test.junit.support.QueueReplyHandler; import org.vertx.java.test.junit.support.VertxTestBase; diff --git a/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java index c5796e9..bac5743 100644 --- a/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java +++ b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java @@ -24,8 +24,8 @@ import org.junit.runner.RunWith; import org.vertx.java.core.Handler; import org.vertx.java.core.eventbus.Message; -import org.vertx.java.test.QueueReplyHandler; import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; +import org.vertx.java.test.junit.support.QueueReplyHandler; import org.vertx.java.test.junit.support.VertxTestBase; diff --git a/src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java b/src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java index 748ec93..0d3f65a 100644 --- a/src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java +++ b/src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java @@ -23,10 +23,10 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.vertx.java.test.QueueReplyHandler; import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; import org.vertx.java.test.junit.annotations.TestVerticle; import org.vertx.java.test.junit.annotations.TestVerticles; +import org.vertx.java.test.junit.support.QueueReplyHandler; import org.vertx.java.test.junit.support.VertxTestBase; diff --git a/src/test/resources/test_client.js b/src/test/resources/test_client.js index 37cc2a8..fde21cb 100644 --- a/src/test/resources/test_client.js +++ b/src/test/resources/test_client.js @@ -33,7 +33,7 @@ function testSpring() { tu.registerTests(this); -var config = {springConfig: 'testConfig.xml'} +var config = {springConfig: 'applicationConfig.xml'} var modID = vertx.deployModule('spring-v1.0', config, 1, function() { tu.appReady(); }); From 108e40558ba830d58a2da0351fff35b6b78b332b Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Sun, 2 Sep 2012 16:21:10 +0100 Subject: [PATCH 06/18] Refactor --- .../test/junit/CountDownLatchDoneHandler.java | 4 +- .../org/vertx/java/test/junit/Deployer.java | 101 +-------- .../java/test/junit/DeploymentHandler.java | 51 +++++ .../test/junit/OrderAnnotationComparator.java | 34 +++ .../vertx/java/test/junit/VertxBuilder.java | 41 ++++ .../junit/VertxConfigurableJUnit4Runner.java | 186 ---------------- .../junit/VertxConfigurationJUnit4Runner.java | 79 +++++++ .../test/junit/VertxExternalResource.java | 27 +++ .../vertx/java/test/junit/VertxTestRule.java | 85 +++++++ .../test/junit/VertxTestRunnerDelegate.java | 93 ++++++++ .../test/junit/annotations/TestOrder.java | 7 + ...rtxConfig.java => VertxConfiguration.java} | 4 +- .../test/junit/support/DeploymentUtils.java | 210 ++++++++++++++++++ .../junit/support/VertxReflectionUtils.java | 65 ++++++ .../java/test/junit/ModuleMethodRuleTest.java | 105 +++++++++ ...tationTest.java => ModuleRunWithTest.java} | 5 +- .../vertx/java/test/junit/SimpleEchoTest.java | 21 +- .../test/junit/VerticleMethodRuleTest.java | 103 +++++++++ ...tionTest.java => VerticleRunWithTest.java} | 5 +- 19 files changed, 930 insertions(+), 296 deletions(-) create mode 100644 src/main/java/org/vertx/java/test/junit/DeploymentHandler.java create mode 100644 src/main/java/org/vertx/java/test/junit/OrderAnnotationComparator.java create mode 100644 src/main/java/org/vertx/java/test/junit/VertxBuilder.java delete mode 100644 src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java create mode 100644 src/main/java/org/vertx/java/test/junit/VertxConfigurationJUnit4Runner.java create mode 100644 src/main/java/org/vertx/java/test/junit/VertxExternalResource.java create mode 100644 src/main/java/org/vertx/java/test/junit/VertxTestRule.java create mode 100644 src/main/java/org/vertx/java/test/junit/VertxTestRunnerDelegate.java create mode 100644 src/main/java/org/vertx/java/test/junit/annotations/TestOrder.java rename src/main/java/org/vertx/java/test/junit/annotations/{VertxConfig.java => VertxConfiguration.java} (92%) create mode 100644 src/main/java/org/vertx/java/test/junit/support/DeploymentUtils.java create mode 100644 src/main/java/org/vertx/java/test/junit/support/VertxReflectionUtils.java create mode 100644 src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java rename src/test/java/org/vertx/java/test/junit/{ModuleAnnotationTest.java => ModuleRunWithTest.java} (94%) create mode 100644 src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java rename src/test/java/org/vertx/java/test/junit/{VerticleAnnotationTest.java => VerticleRunWithTest.java} (94%) diff --git a/src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java b/src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java index 5938568..9907759 100644 --- a/src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java +++ b/src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java @@ -26,9 +26,9 @@ */ public class CountDownLatchDoneHandler implements Handler { - public final CountDownLatch latch; + private final CountDownLatch latch; - CountDownLatchDoneHandler(final CountDownLatch latch) { + public CountDownLatchDoneHandler(final CountDownLatch latch) { this.latch = latch; } diff --git a/src/main/java/org/vertx/java/test/junit/Deployer.java b/src/main/java/org/vertx/java/test/junit/Deployer.java index 6cecf86..77097d7 100644 --- a/src/main/java/org/vertx/java/test/junit/Deployer.java +++ b/src/main/java/org/vertx/java/test/junit/Deployer.java @@ -16,14 +16,7 @@ package org.vertx.java.test.junit; import java.io.File; -import java.io.IOException; import java.net.URL; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -35,6 +28,7 @@ import org.vertx.java.test.junit.annotations.TestModules; import org.vertx.java.test.junit.annotations.TestVerticle; import org.vertx.java.test.junit.annotations.TestVerticles; +import org.vertx.java.test.junit.support.DeploymentUtils; /** @@ -73,9 +67,9 @@ private void deployVerticles(TestVerticles verticles) { final CountDownLatch latch = new CountDownLatch(verticles.value().length); for (TestVerticle v : verticles.value()) { - JsonObject config = getJsonConfig(v.jsonConfig()); + JsonObject config = DeploymentUtils.getJsonConfig(v.jsonConfig()); - URL[] urls = findVerticleURLs(v); + URL[] urls = DeploymentUtils.findVerticleURLs(v); manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, new CountDownLatchDoneHandler(latch)); deploymentCounter.incrementAndGet(); } @@ -89,8 +83,8 @@ private void deployVerticle(TestVerticle v) { } final CountDownLatch latch = new CountDownLatch(1); - JsonObject config = getJsonConfig(v.jsonConfig()); - URL[] urls = findVerticleURLs(v); + JsonObject config = DeploymentUtils.getJsonConfig(v.jsonConfig()); + URL[] urls = DeploymentUtils.findVerticleURLs(v); manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, new CountDownLatchDoneHandler(latch)); deploymentCounter.incrementAndGet(); @@ -106,7 +100,7 @@ private void deployModules(TestModules amodules) { final CountDownLatch latch = new CountDownLatch(amodules.value().length); for (TestModule m : amodules.value()) { - JsonObject config = getJsonConfig(m.jsonConfig()); + JsonObject config = DeploymentUtils.getJsonConfig(m.jsonConfig()); manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); deploymentCounter.incrementAndGet(); } @@ -121,94 +115,13 @@ private void deployModule(TestModule m) { final CountDownLatch latch = new CountDownLatch(1); - JsonObject config = getJsonConfig(m.jsonConfig()); + JsonObject config = DeploymentUtils.getJsonConfig(m.jsonConfig()); manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); deploymentCounter.incrementAndGet(); await(latch); } - private URL[] findVerticleURLs(TestVerticle v) { - Set urlSet = new HashSet(); - - if (v.urls().length > 0) { - for (String path : v.urls()) { - - try { - - URL url = new File(path).toURI().toURL(); - urlSet.add(url); - - } catch (Exception e) { - // TODO log something here - e.printStackTrace(); - } - } - } - - try { - String main = v.main(); - if (main.indexOf(':') > -1) { - main = main.substring(main.indexOf(':') + 1); - } - - // check for class, prep for locating root URL - int parts = 0; - if (!main.endsWith(".xml")) { - parts = main.split("\\.").length; - main = main.replaceAll("\\.", "/"); - main = main + ".class"; - } - - // contortions to get parent, may not be entirely accurate... - // URL url = getClass().getClassLoader().getResource(main); - URL url = Thread.currentThread().getContextClassLoader().getResource(main); - - if (url != null) { - Path path = Paths.get(url.toURI()); - - int i = parts; - while (i > 0) { - path = path.getParent(); - i--; - } - - url = path.toUri().toURL(); - urlSet.add(url); - } - - } catch (Exception e) { - // TODO log something here - e.printStackTrace(); - } - - URL[] urls = new URL[urlSet.size()]; - return urlSet.toArray(urls); - } - - private JsonObject getJsonConfig(String jsonConfig) { - JsonObject config; - - if (jsonConfig.startsWith("file:")) { - String filename = jsonConfig.replaceFirst("file:", ""); - Path json = new File(filename).toPath(); - - try { - Charset utf8 = Charset.forName("UTF-8"); - byte[] bytes = Files.readAllBytes(json); - config = new JsonObject(new String(bytes, utf8)); - - } catch (IOException e) { - throw new RuntimeException(e); - } - } - else { - config = new JsonObject(jsonConfig); - } - - return config; - } - private void await(final CountDownLatch latch) { try { latch.await(shutdownTimeout, TimeUnit.SECONDS); diff --git a/src/main/java/org/vertx/java/test/junit/DeploymentHandler.java b/src/main/java/org/vertx/java/test/junit/DeploymentHandler.java new file mode 100644 index 0000000..52b8f72 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/DeploymentHandler.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.java.test.junit; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.CountDownLatch; + +import org.vertx.java.core.Handler; + + +/** + * @author swilliams + * + */ +public class DeploymentHandler implements Handler { + + private final CountDownLatch latch; + + private final Set deploymentIDs = new HashSet<>(); + + public DeploymentHandler(final CountDownLatch latch) { + this.latch = latch; + } + + @Override + public void handle(String event) { + if (event != null) { + deploymentIDs.add(event); + } + latch.countDown(); + } + + public Set getDeploymentIDs() { + return deploymentIDs; + } + +} \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/OrderAnnotationComparator.java b/src/main/java/org/vertx/java/test/junit/OrderAnnotationComparator.java new file mode 100644 index 0000000..d16a8ad --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/OrderAnnotationComparator.java @@ -0,0 +1,34 @@ +package org.vertx.java.test.junit; + +import java.util.Comparator; + +import org.junit.runner.Description; +import org.vertx.java.test.junit.annotations.TestOrder; + +public class OrderAnnotationComparator implements Comparator { + + @Override + public int compare(Description one, Description two) { + + TestOrder order1 = one.getAnnotation(TestOrder.class); + TestOrder order2 = two.getAnnotation(TestOrder.class); + + int order = 0; + if (order1 != null && order2 != null) { + order = order1.value() - order2.value(); + } + else if (order1 != null && order2 == null) { + return order1.value(); + } + else if (order1 == null && order2 != null) { + return order2.value(); + } + + if (order == 0) { + order = one.getMethodName().compareTo(two.getMethodName()); + } + + return order; + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/VertxBuilder.java b/src/main/java/org/vertx/java/test/junit/VertxBuilder.java new file mode 100644 index 0000000..fc25177 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/VertxBuilder.java @@ -0,0 +1,41 @@ +package org.vertx.java.test.junit; + +import org.vertx.java.core.impl.DefaultVertx; + +public class VertxBuilder { + + private String address; + + private int port; + + public VertxBuilder setAddress(String address) { + this.address = address; + return this; + } + + public VertxBuilder setPort(int port) { + this.port = port; + return this; + } + + public DefaultVertx build() { + try { + DefaultVertx vertx; + if (port > -1 && address != null) { + vertx = new DefaultVertx(port, address); + } + else if (address != null) { + vertx = new DefaultVertx(address); + } + else { + vertx = new DefaultVertx(); + } + return vertx; + } + finally { + this.address = null; + this.port = -1; + } + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java b/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java deleted file mode 100644 index 399d0be..0000000 --- a/src/main/java/org/vertx/java/test/junit/VertxConfigurableJUnit4Runner.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.vertx.java.test.junit; - -import java.io.File; -import java.lang.reflect.Method; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CountDownLatch; - -import org.junit.rules.TestRule; -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.InitializationError; - -import org.vertx.java.core.Vertx; -import org.vertx.java.core.impl.DefaultVertx; -import org.vertx.java.core.impl.VertxInternal; -import org.vertx.java.deploy.Container; -import org.vertx.java.deploy.Verticle; -import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.junit.annotations.VertxConfig; -import org.vertx.java.test.junit.support.VerticleManagerSupport; -import org.vertx.java.test.junit.support.VertxSupport; - - -/** - * @author swilliams - * - */ -public class VertxConfigurableJUnit4Runner extends BlockJUnit4ClassRunner { - - private final Set classCache = new HashSet(); - - private VertxInternal vertx; - - private VerticleManager verticleManager; - - private Deployer deployer; - - private Verticle verticle; - - /** - * @param klass - * @throws InitializationError - */ - public VertxConfigurableJUnit4Runner(Class klass) throws InitializationError { - super(klass); - } - - /** - * {@inheritDoc} - */ - @Override - public void run(RunNotifier notifier) { - - long timeout; - VertxConfig vertxConfig = getDescription().getAnnotation(VertxConfig.class); - if (vertxConfig != null) { - timeout = vertxConfig.shutdownTimeoutSeconds(); - this.vertx = new DefaultVertx(vertxConfig.port(), vertxConfig.hostname()); - } - else { - timeout = 30L; - this.vertx = new DefaultVertx(); - } - - this.verticleManager = new VerticleManager(vertx); - - String vertxMods = System.getProperty("vertx.mods"); - File currentModDir = new File(vertxMods); - if (!currentModDir.exists()) { - currentModDir.mkdirs(); - } - - this.deployer = new Deployer(verticleManager, currentModDir, timeout); - deployer.deploy(getDescription()); - - super.run(notifier); - - undeployAll(); - } - - - /** - * {@inheritDoc} - */ - @Override - protected List getTestRules(Object target) { - - if (!classCache.contains(target.toString())) { - configureTargetTestClass(target); - classCache.add(target.toString()); - } - - List rules = super.getTestRules(target); - rules.add(new VertxRule(deployer)); - return rules; - } - - /** - * @param target - */ - private void configureTargetTestClass(Object target) { - - if (target instanceof Verticle) { - // TODO do something clever here... - System.out.printf("Test class is a Verticle: %s %n", target.getClass().getName()); - this.verticle = (Verticle) target; - verticle.setVertx(vertx); - verticle.setContainer(new Container(verticleManager)); - try { - verticle.start(); - } catch (Exception e) { - throw new UnexpectedTestRunnerException(e); - } - } - - // discover VertxSupport - if (target instanceof VertxSupport) { - VertxSupport support = (VertxSupport) target; - support.setVertx(vertx); - } - - // discover VerticleManager support - if (target instanceof VerticleManagerSupport) { - VerticleManagerSupport support = (VerticleManagerSupport) target; - support.setManager(verticleManager); - } - - // discover setVertx method - try { - Method setVertxMethod = target.getClass().getMethod("setVertx", Vertx.class); - setVertxMethod.invoke(target, vertx); - } catch (Exception e) { - // we can ignore this if the method isn't present - } - - // discover setVerticleManager method - try { - Method setVerticleManagerMethod = target.getClass().getMethod("setVerticleManager", VerticleManager.class); - setVerticleManagerMethod.invoke(target, verticleManager); - } catch (Exception e) { - // we can ignore this if the method isn't present - } - - } - - /** - * - */ - private void undeployAll() { - - CountDownLatch latch = new CountDownLatch(1); - verticleManager.undeployAll(new CountDownLatchDoneHandler(latch)); - - try { - latch.await(); - } catch (InterruptedException e) { - // - } - - if (verticle != null) { - try { - verticle.stop(); - } catch (Exception e) { - throw new UnexpectedTestRunnerException(e); - } - } - } - -} diff --git a/src/main/java/org/vertx/java/test/junit/VertxConfigurationJUnit4Runner.java b/src/main/java/org/vertx/java/test/junit/VertxConfigurationJUnit4Runner.java new file mode 100644 index 0000000..7fcdd34 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/VertxConfigurationJUnit4Runner.java @@ -0,0 +1,79 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.java.test.junit; + +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runner.manipulation.Sorter; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; + +/** + * @author swilliams + * + */ +public class VertxConfigurationJUnit4Runner extends BlockJUnit4ClassRunner { + + private final Set classCache = new HashSet(); + + private final VertxTestRunnerDelegate delegate; + + /** + * @param klass + * @throws InitializationError + */ + public VertxConfigurationJUnit4Runner(Class klass) throws InitializationError { + super(klass); + this.delegate = new VertxTestRunnerDelegate(); + } + + /** + * {@inheritDoc} + */ + @Override + public void run(RunNotifier notifier) { + + Comparator comparator = new OrderAnnotationComparator(); + super.sort(new Sorter(comparator)); + + delegate.runBeforeTest(getDescription()); + super.run(notifier); + delegate.runAfterTest(); + } + + @Override + protected List getTestRules(Object target) { + + List rules = super.getTestRules(target); + + if (!classCache.contains(target.toString())) { + delegate.runBeforeClass(target); + classCache.add(target.toString()); + } + else { + TestRule rule = delegate.runBeforeEachTest(target); + rules.add(rule); + } + + return rules; + } +} diff --git a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java new file mode 100644 index 0000000..7c80711 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java @@ -0,0 +1,27 @@ +package org.vertx.java.test.junit; + +import org.junit.rules.ExternalResource; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +public class VertxExternalResource extends ExternalResource { + + @Override + public Statement apply(Statement base, Description description) { + System.out.printf("VertxExternalResource.apply(%s,%s)%n", base, description); + return super.apply(base, description); + } + + @Override + protected void before() throws Throwable { + System.out.printf("VertxExternalResource.before()%n"); + super.before(); + } + + @Override + protected void after() { + System.out.printf("VertxExternalResource.after()%n"); + super.after(); + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/VertxTestRule.java b/src/main/java/org/vertx/java/test/junit/VertxTestRule.java new file mode 100644 index 0000000..42fc6ae --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/VertxTestRule.java @@ -0,0 +1,85 @@ +package org.vertx.java.test.junit; + +import java.io.File; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.rules.ExternalResource; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.junit.annotations.TestModule; +import org.vertx.java.test.junit.annotations.TestVerticle; +import org.vertx.java.test.junit.support.DeploymentUtils; + +public class VertxTestRule extends ExternalResource { + + private static final long TIMEOUT = 15L; + + private final Set testVerticles = new HashSet<>(); + + private final Set testModules = new HashSet<>(); + + private final VerticleManager manager; + + private File currentModDir; + + public VertxTestRule(VerticleManager manager) { + this.manager = manager; + + String vertxMods = System.getProperty("vertx.mods"); + this.currentModDir = new File(vertxMods); + if (!currentModDir.exists()) { + currentModDir.mkdirs(); + } + } + + public VertxTestRule(VerticleManager manager, File currentModDir) { + this.manager = manager; + this.currentModDir = currentModDir; + } + + @Override + public Statement apply(final Statement base, final Description description) { + findAnnotations(description); + return super.apply(base, description); + } + + private void findAnnotations(final Description description) { + testModules.addAll(DeploymentUtils.findTestModules(description)); + testVerticles.addAll(DeploymentUtils.findTestVerticles(description)); + } + + @Override + protected void before() throws Throwable { + + if (!currentModDir.exists()) { + currentModDir.mkdirs(); + } + + DeploymentUtils.deployVerticles(manager, testVerticles, currentModDir, TIMEOUT); + DeploymentUtils.deployModules(manager, testModules, currentModDir, TIMEOUT); + + super.before(); + } + + @Override + protected void after() { + + CountDownLatch latch = new CountDownLatch(1); + CountDownLatchDoneHandler handler = new CountDownLatchDoneHandler(latch); + + manager.undeployAll(handler); + + try { + latch.await(TIMEOUT, TimeUnit.SECONDS); + } catch (InterruptedException e) { + // + } + + super.after(); + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/VertxTestRunnerDelegate.java b/src/main/java/org/vertx/java/test/junit/VertxTestRunnerDelegate.java new file mode 100644 index 0000000..1e7b579 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/VertxTestRunnerDelegate.java @@ -0,0 +1,93 @@ +package org.vertx.java.test.junit; + +import java.io.File; +import java.util.Set; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.vertx.java.core.impl.DefaultVertx; +import org.vertx.java.deploy.Verticle; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.junit.annotations.TestModule; +import org.vertx.java.test.junit.annotations.TestVerticle; +import org.vertx.java.test.junit.annotations.VertxConfiguration; +import org.vertx.java.test.junit.support.DeploymentUtils; +import org.vertx.java.test.junit.support.VertxReflectionUtils; + +public class VertxTestRunnerDelegate { + + private long timeout = 15L; + + private File currentModDir; + + private DefaultVertx vertx; + + private VerticleManager manager; + + private Verticle verticle; + + private VertxTestRule testRule; + + public void runBeforeTest(Description description) { + + VertxConfiguration config = description.getAnnotation(VertxConfiguration.class); + VertxBuilder builder = new VertxBuilder(); + String vertxMods; + + if (config != null) { + this.timeout = config.shutdownTimeoutSeconds(); + if (config.port() > 0) { + builder.setPort(config.port()); + } + if (!"".equals(config.hostname())) { + builder.setAddress(config.hostname()); + } + vertxMods = System.getProperty("vertx.mods", config.modsDir()); + } + else { + this.timeout = 30L; + this.vertx = new DefaultVertx(); + vertxMods = System.getProperty("vertx.mods"); + } + + this.vertx = builder.build(); + + this.currentModDir = new File(vertxMods); + if (!currentModDir.exists()) { + currentModDir.mkdirs(); + } + + this.manager = new VerticleManager(vertx); + this.testRule = new VertxTestRule(manager, currentModDir); + + Set testModules = DeploymentUtils.findTestModules(description); + DeploymentUtils.deployModules(manager, testModules, currentModDir, timeout); + + Set testVerticles = DeploymentUtils.findTestVerticles(description); + DeploymentUtils.deployVerticles(manager, testVerticles, currentModDir, timeout); + } + + public void runBeforeClass(Object target) { + this.verticle = VertxReflectionUtils.configureTargetTestClass(vertx, manager, target); + } + + public TestRule runBeforeEachTest(Object target) { + return testRule; + } + + public void runAfterTest() { + System.out.println("Delegate.runAfterTest"); + + DeploymentUtils.undeployAll(manager, timeout); + + if (verticle != null) { + try { + verticle.stop(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/annotations/TestOrder.java b/src/main/java/org/vertx/java/test/junit/annotations/TestOrder.java new file mode 100644 index 0000000..1f34fb9 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/annotations/TestOrder.java @@ -0,0 +1,7 @@ +package org.vertx.java.test.junit.annotations; + +public @interface TestOrder { + + int value() default 0; + +} diff --git a/src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java b/src/main/java/org/vertx/java/test/junit/annotations/VertxConfiguration.java similarity index 92% rename from src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java rename to src/main/java/org/vertx/java/test/junit/annotations/VertxConfiguration.java index de9532c..e5458ac 100644 --- a/src/main/java/org/vertx/java/test/junit/annotations/VertxConfig.java +++ b/src/main/java/org/vertx/java/test/junit/annotations/VertxConfiguration.java @@ -31,7 +31,7 @@ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -public @interface VertxConfig { +public @interface VertxConfiguration { String hostname() default "localhost"; @@ -39,4 +39,6 @@ long shutdownTimeoutSeconds() default 30L; + String modsDir() default "build/tmp/test-mods"; + } diff --git a/src/main/java/org/vertx/java/test/junit/support/DeploymentUtils.java b/src/main/java/org/vertx/java/test/junit/support/DeploymentUtils.java new file mode 100644 index 0000000..8ae0b49 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/support/DeploymentUtils.java @@ -0,0 +1,210 @@ +package org.vertx.java.test.junit.support; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.runner.Description; +import org.vertx.java.core.json.JsonObject; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.junit.CountDownLatchDoneHandler; +import org.vertx.java.test.junit.DeploymentHandler; +import org.vertx.java.test.junit.annotations.TestModule; +import org.vertx.java.test.junit.annotations.TestModules; +import org.vertx.java.test.junit.annotations.TestVerticle; +import org.vertx.java.test.junit.annotations.TestVerticles; + +public class DeploymentUtils { + + public static Set findTestModules(Description description) { + Set testModules = new HashSet<>(); + + TestModules modules = description.getAnnotation(TestModules.class); + if (modules != null) { + for (TestModule m : modules.value()) { + testModules.add(m); + } + } + + TestModule m = description.getAnnotation(TestModule.class); + if (m != null) { + testModules.add(m); + } + + return testModules; + } + + public static Set findTestVerticles(Description description) { + Set testVerticles = new HashSet<>(); + + TestVerticles verticles = description.getAnnotation(TestVerticles.class); + if (verticles != null) { + for (TestVerticle v : verticles.value()) { + testVerticles.add(v); + } + } + + TestVerticle v = description.getAnnotation(TestVerticle.class); + if (v != null) { + testVerticles.add(v); + } + + return testVerticles; + } + + public static Set deployVerticles(VerticleManager manager, Set testVerticles, File currentModDir, long timeout) { + + Set verticleDeployments = new HashSet<>(); + + if (testVerticles.size() > 0) { + CountDownLatch latch = new CountDownLatch(testVerticles.size()); + + DeploymentHandler handler = new DeploymentHandler(latch); + for (TestVerticle v : testVerticles) { + JsonObject config = getJsonConfig(v.jsonConfig()); + URL[] urls = findVerticleURLs(v); + + System.out.printf("Deployment.deployVerticle(%s)%n", v); + manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), currentModDir, handler); + } + + try { + latch.await(timeout, TimeUnit.SECONDS); + } catch (InterruptedException e) { + + } + verticleDeployments.addAll(handler.getDeploymentIDs()); + } + + return verticleDeployments; + } + + public static Set deployModules(VerticleManager manager, Set testModules, File currentModDir, long timeout) { + Set moduleDeployments = new HashSet<>(); + + if (testModules.size() > 0) { + + CountDownLatch latch = new CountDownLatch(testModules.size()); + DeploymentHandler handler = new DeploymentHandler(latch); + for (TestModule m : testModules) { + + System.out.printf("Deployment.deployModule(%s)%n", m); + JsonObject config = getJsonConfig(m.jsonConfig()); + + manager.deployMod(m.name(), config, m.instances(), currentModDir, handler); + } + + try { + latch.await(timeout, TimeUnit.SECONDS); + } catch (InterruptedException e) { + + } + moduleDeployments.addAll(handler.getDeploymentIDs()); + } + return moduleDeployments; + } + + public static JsonObject getJsonConfig(String jsonConfig) { + JsonObject config; + + if (jsonConfig.startsWith("file:")) { + String filename = jsonConfig.replaceFirst("file:", ""); + Path json = new File(filename).toPath(); + + try { + Charset utf8 = Charset.forName("UTF-8"); + byte[] bytes = Files.readAllBytes(json); + config = new JsonObject(new String(bytes, utf8)); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + else { + config = new JsonObject(jsonConfig); + } + + return config; + } + + public static URL[] findVerticleURLs(TestVerticle v) { + Set urlSet = new HashSet(); + + if (v.urls().length > 0) { + for (String path : v.urls()) { + + try { + + URL url = new File(path).toURI().toURL(); + urlSet.add(url); + + } catch (Exception e) { + // TODO log something here + e.printStackTrace(); + } + } + } + + try { + String main = v.main(); + if (main.indexOf(':') > -1) { + main = main.substring(main.indexOf(':') + 1); + } + + // check for class, prep for locating root URL + int parts = 0; + if (!main.endsWith(".xml")) { + parts = main.split("\\.").length; + main = main.replaceAll("\\.", "/"); + main = main + ".class"; + } + + // contortions to get parent, may not be entirely accurate... + // URL url = getClass().getClassLoader().getResource(main); + URL url = Thread.currentThread().getContextClassLoader().getResource(main); + + if (url != null) { + Path path = Paths.get(url.toURI()); + + int i = parts; + while (i > 0) { + path = path.getParent(); + i--; + } + + url = path.toUri().toURL(); + urlSet.add(url); + } + + } catch (Exception e) { + // TODO log something here + e.printStackTrace(); + } + + URL[] urls = new URL[urlSet.size()]; + return urlSet.toArray(urls); + } + + public static void undeployAll(VerticleManager manager, long timeout) { + + CountDownLatch latch = new CountDownLatch(1); + CountDownLatchDoneHandler handler = new CountDownLatchDoneHandler(latch); + + manager.undeployAll(handler); + + try { + latch.await(timeout, TimeUnit.SECONDS); + } catch (InterruptedException e) { + // + } + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/support/VertxReflectionUtils.java b/src/main/java/org/vertx/java/test/junit/support/VertxReflectionUtils.java new file mode 100644 index 0000000..b80de68 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/support/VertxReflectionUtils.java @@ -0,0 +1,65 @@ +package org.vertx.java.test.junit.support; + +import org.vertx.java.core.Vertx; +import org.vertx.java.deploy.Container; +import org.vertx.java.deploy.Verticle; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.junit.UnexpectedTestRunnerException; + +public class VertxReflectionUtils { + + /** + * @param target + */ + public static Verticle configureTargetTestClass(Vertx vertx, VerticleManager verticleManager, Object target) { + + Verticle verticle = null; + if (target instanceof Verticle) { + // TODO do something clever here... + System.out.printf("Test class is a Verticle: %s %n", target.getClass().getName()); + verticle = (Verticle) target; + verticle.setVertx(vertx); + verticle.setContainer(new Container(verticleManager)); + try { + verticle.start(); + } catch (Exception e) { + throw new UnexpectedTestRunnerException(e); + } + } + + // discover VertxSupport + if (target instanceof VertxSupport) { + VertxSupport support = (VertxSupport) target; + support.setVertx(vertx); + } + + // discover VerticleManager support + if (target instanceof VerticleManagerSupport) { + VerticleManagerSupport support = (VerticleManagerSupport) target; + support.setManager(verticleManager); + } + +// // discover setVertx method +// try { +// Method setVertxMethod = target.getClass().getMethod("setVertx", Vertx.class); +// if (setVertxMethod.isAnnotationPresent(Resource.class)) { +// setVertxMethod.invoke(target, vertx); +// } +// } catch (Exception e) { +// // we can ignore this if the method isn't present +// } +// +// // discover setVerticleManager method +// try { +// Method setVerticleManagerMethod = target.getClass().getMethod("setVerticleManager", VerticleManager.class); +// if (setVerticleManagerMethod.isAnnotationPresent(Resource.class)) { +// setVerticleManagerMethod.invoke(target, verticleManager); +// } +// } catch (Exception e) { +// // we can ignore this if the method isn't present +// } + + return verticle; + } + +} diff --git a/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java b/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java new file mode 100644 index 0000000..b402990 --- /dev/null +++ b/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.java.test.junit; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import org.vertx.java.core.Vertx; +import org.vertx.java.core.impl.DefaultVertx; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.junit.annotations.TestModule; +import org.vertx.java.test.junit.annotations.TestModules; +import org.vertx.java.test.junit.support.QueueReplyHandler; + + +/** + * @author swilliams + * + */ +public class ModuleMethodRuleTest { + + private final DefaultVertx vertx = new DefaultVertx(); + + private final VerticleManager manager = new VerticleManager(vertx); + + @Rule + public VertxTestRule rule = new VertxTestRule(manager); + + private long timeout = 10L; + + public Vertx getVertx() { + return vertx; + } + + @Before + public void setup() { + this.timeout = Long.parseLong(System.getProperty("vertx.test.timeout", "15L")); + try { + Thread.sleep(2000L); + } catch (InterruptedException e) { + // + } + } + + @Test + @TestModule(name="test.echo1-v1.0") + public void testModuleEcho1() { + String QUESTION = "Is it beer oclock yet?"; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.mods.echo1", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + Assert.fail(e.getMessage()); + } + + } + + @Test + @TestModules({ + @TestModule(name="test.echo2-v1.0") + }) + public void testModulesEcho2() { + String QUESTION = "What ho!"; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.mods.echo2", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + Assert.fail(e.getMessage()); + } + + } + +} diff --git a/src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java b/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java similarity index 94% rename from src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java rename to src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java index e5297c3..92221dd 100644 --- a/src/test/java/org/vertx/java/test/junit/ModuleAnnotationTest.java +++ b/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; import org.vertx.java.test.junit.annotations.TestModule; import org.vertx.java.test.junit.annotations.TestModules; import org.vertx.java.test.junit.support.QueueReplyHandler; @@ -34,11 +33,11 @@ * @author swilliams * */ -@RunWith(VertxConfigurableJUnit4Runner.class) +@RunWith(VertxConfigurationJUnit4Runner.class) @TestModules({ @TestModule(name="test.echo0-v1.0") }) -public class ModuleAnnotationTest extends VertxTestBase { +public class ModuleRunWithTest extends VertxTestBase { private long timeout = 10L; diff --git a/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java index bac5743..82dbd8a 100644 --- a/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java +++ b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java @@ -23,28 +23,35 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.vertx.java.core.Handler; +import org.vertx.java.core.Vertx; import org.vertx.java.core.eventbus.Message; -import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; import org.vertx.java.test.junit.support.QueueReplyHandler; -import org.vertx.java.test.junit.support.VertxTestBase; +import org.vertx.java.test.junit.support.VertxSupport; /** * @author swilliams * */ -@RunWith(VertxConfigurableJUnit4Runner.class) -public class SimpleEchoTest extends VertxTestBase { +@RunWith(VertxConfigurationJUnit4Runner.class) +public class SimpleEchoTest implements VertxSupport { private static final String QUESTION = "Hello World"; private static final String TEST_ADDRESS = "vertx.test.echo"; + private Vertx vertx; + + @Override + public void setVertx(Vertx vertx) { + this.vertx = vertx; + } + @Before public void setup() { - Assert.assertNotNull(super.getVertx()); + Assert.assertNotNull(vertx); - getVertx().eventBus().registerHandler(TEST_ADDRESS, new Handler>() { + vertx.eventBus().registerHandler(TEST_ADDRESS, new Handler>() { @Override public void handle(Message event) { if (QUESTION.equals(event.body)) { @@ -68,7 +75,7 @@ public void test() { final long timeout = 10L; final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); - getVertx().eventBus().send(TEST_ADDRESS, QUESTION, new QueueReplyHandler(queue, timeout)); + vertx.eventBus().send(TEST_ADDRESS, QUESTION, new QueueReplyHandler(queue, timeout)); try { String answer = queue.poll(timeout, TimeUnit.SECONDS); diff --git a/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java b/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java new file mode 100644 index 0000000..4d6bd14 --- /dev/null +++ b/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java @@ -0,0 +1,103 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.java.test.junit; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import org.vertx.java.core.Vertx; +import org.vertx.java.core.impl.DefaultVertx; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.junit.annotations.TestVerticle; +import org.vertx.java.test.junit.annotations.TestVerticles; +import org.vertx.java.test.junit.support.QueueReplyHandler; + + +/** + * @author swilliams + * + */ +public class VerticleMethodRuleTest { + + private final DefaultVertx vertx = new DefaultVertx(); + + private final VerticleManager manager = new VerticleManager(vertx); + + @Rule + public VertxTestRule rule = new VertxTestRule(manager); + + private long timeout = 10L; + + public Vertx getVertx() { + return vertx; + } + + @Before + public void setup() { + this.timeout = Long.parseLong(System.getProperty("vertx.test.timeout", "15L")); + try { + Thread.sleep(2000L); + } catch (InterruptedException e) { + // + } + } + + @Test + @TestVerticle(main="test_verticle1.js") + public void testVerticle1() { + String QUESTION = "Oh no. Not penalties again..."; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.echo1", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + // + } + } + + @Test + @TestVerticles({ + @TestVerticle(main="test_verticle2.js") + }) + public void testVerticles2() { + String QUESTION = "Smashing fun, what!"; + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send("vertx.test.echo2", QUESTION, new QueueReplyHandler(queue, timeout)); + + try { + String answer = queue.poll(timeout, TimeUnit.SECONDS); + System.out.println("answer: " + answer); + Assert.assertTrue(QUESTION.equals(answer)); + + } catch (InterruptedException e) { + // + } + } + +} diff --git a/src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java b/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java similarity index 94% rename from src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java rename to src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java index 0d3f65a..7dd4208 100644 --- a/src/test/java/org/vertx/java/test/junit/VerticleAnnotationTest.java +++ b/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.vertx.java.test.junit.VertxConfigurableJUnit4Runner; import org.vertx.java.test.junit.annotations.TestVerticle; import org.vertx.java.test.junit.annotations.TestVerticles; import org.vertx.java.test.junit.support.QueueReplyHandler; @@ -34,9 +33,9 @@ * @author swilliams * */ -@RunWith(VertxConfigurableJUnit4Runner.class) +@RunWith(VertxConfigurationJUnit4Runner.class) @TestVerticle(main="test_verticle0.js") -public class VerticleAnnotationTest extends VertxTestBase { +public class VerticleRunWithTest extends VertxTestBase { private long timeout = 10L; From af08461b75f5f634eb1f0a593633d54de5f83ad8 Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Mon, 3 Sep 2012 13:26:46 +0100 Subject: [PATCH 07/18] major refactor, simplify --- .../{junit/annotations => }/TestModule.java | 2 +- .../{junit/annotations => }/TestModules.java | 2 +- .../{junit/annotations => }/TestOrder.java | 2 +- .../{junit/annotations => }/TestVerticle.java | 2 +- .../annotations => }/TestVerticles.java | 2 +- .../vertx/java/test/VerticleManagerAware.java | 9 + .../java/test/VerticleManagerResource.java | 16 ++ .../java/org/vertx/java/test/VertxAware.java | 9 + .../annotations => }/VertxConfiguration.java | 6 +- .../org/vertx/java/test/VertxResource.java | 16 ++ .../org/vertx/java/test/VertxTestBase.java | 143 +++++++++++++ .../org/vertx/java/test/junit/Deployer.java | 139 ------------ .../test/junit/JUnit4ClassRunnerAdapter.java | 97 +++++++++ .../java/test/junit/JUnitDeploymentUtils.java | 70 ++++++ .../test/junit/OrderAnnotationComparator.java | 2 +- .../junit/UnexpectedTestRunnerException.java | 11 - .../junit/VertxConfigurationJUnit4Runner.java | 79 ------- .../test/junit/VertxJUnit4ClassRunner.java | 107 ++++++++++ .../vertx/java/test/junit/VertxTestRule.java | 85 -------- .../test/junit/VertxTestRunnerDelegate.java | 93 -------- .../{VertxRule.java => package-info.java} | 29 +-- .../CountDownLatchDoneHandler.java | 2 +- .../{junit => utils}/DeploymentHandler.java | 9 +- .../java/test/utils/DeploymentUtils.java | 200 ++++++++++++++++++ .../vertx/java/test/utils/InjectionUtils.java | 24 +++ .../java/test/utils/QueueReplyHandler.java | 64 ++++++ .../utils/SimpleLatchAsyncResultHandler.java | 28 +++ .../vertx/java/test/utils/package-info.java | 20 ++ .../java/test/junit/ModuleMethodRuleTest.java | 7 +- .../java/test/junit/ModuleRunWithTest.java | 9 +- .../vertx/java/test/junit/SimpleEchoTest.java | 5 +- .../java/test/junit/SimpleModuleTest.java | 73 +++++++ .../java/test/junit/SimpleVerticleTest.java | 52 +++++ .../test/junit/VerticleMethodRuleTest.java | 7 +- .../java/test/junit/VerticleRunWithTest.java | 9 +- src/test/resources/test_verticle3.js | 25 +++ src/test/resources/test_verticle4.js | 25 +++ src/test/resources/test_verticle5.js | 25 +++ src/test/resources/test_verticle6.js | 25 +++ 39 files changed, 1067 insertions(+), 463 deletions(-) rename src/main/java/org/vertx/java/test/{junit/annotations => }/TestModule.java (95%) rename src/main/java/org/vertx/java/test/{junit/annotations => }/TestModules.java (95%) rename src/main/java/org/vertx/java/test/{junit/annotations => }/TestOrder.java (56%) rename src/main/java/org/vertx/java/test/{junit/annotations => }/TestVerticle.java (96%) rename src/main/java/org/vertx/java/test/{junit/annotations => }/TestVerticles.java (95%) create mode 100644 src/main/java/org/vertx/java/test/VerticleManagerAware.java create mode 100644 src/main/java/org/vertx/java/test/VerticleManagerResource.java create mode 100644 src/main/java/org/vertx/java/test/VertxAware.java rename src/main/java/org/vertx/java/test/{junit/annotations => }/VertxConfiguration.java (91%) create mode 100644 src/main/java/org/vertx/java/test/VertxResource.java create mode 100644 src/main/java/org/vertx/java/test/VertxTestBase.java delete mode 100644 src/main/java/org/vertx/java/test/junit/Deployer.java create mode 100644 src/main/java/org/vertx/java/test/junit/JUnit4ClassRunnerAdapter.java create mode 100644 src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java delete mode 100644 src/main/java/org/vertx/java/test/junit/UnexpectedTestRunnerException.java delete mode 100644 src/main/java/org/vertx/java/test/junit/VertxConfigurationJUnit4Runner.java create mode 100644 src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java delete mode 100644 src/main/java/org/vertx/java/test/junit/VertxTestRule.java delete mode 100644 src/main/java/org/vertx/java/test/junit/VertxTestRunnerDelegate.java rename src/main/java/org/vertx/java/test/junit/{VertxRule.java => package-info.java} (52%) rename src/main/java/org/vertx/java/test/{junit => utils}/CountDownLatchDoneHandler.java (96%) rename src/main/java/org/vertx/java/test/{junit => utils}/DeploymentHandler.java (86%) create mode 100644 src/main/java/org/vertx/java/test/utils/DeploymentUtils.java create mode 100644 src/main/java/org/vertx/java/test/utils/InjectionUtils.java create mode 100644 src/main/java/org/vertx/java/test/utils/QueueReplyHandler.java create mode 100644 src/main/java/org/vertx/java/test/utils/SimpleLatchAsyncResultHandler.java create mode 100644 src/main/java/org/vertx/java/test/utils/package-info.java create mode 100644 src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java create mode 100644 src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java create mode 100644 src/test/resources/test_verticle3.js create mode 100644 src/test/resources/test_verticle4.js create mode 100644 src/test/resources/test_verticle5.js create mode 100644 src/test/resources/test_verticle6.js diff --git a/src/main/java/org/vertx/java/test/junit/annotations/TestModule.java b/src/main/java/org/vertx/java/test/TestModule.java similarity index 95% rename from src/main/java/org/vertx/java/test/junit/annotations/TestModule.java rename to src/main/java/org/vertx/java/test/TestModule.java index 74b5b2b..9635378 100644 --- a/src/main/java/org/vertx/java/test/junit/annotations/TestModule.java +++ b/src/main/java/org/vertx/java/test/TestModule.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test.junit.annotations; +package org.vertx.java.test; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/src/main/java/org/vertx/java/test/junit/annotations/TestModules.java b/src/main/java/org/vertx/java/test/TestModules.java similarity index 95% rename from src/main/java/org/vertx/java/test/junit/annotations/TestModules.java rename to src/main/java/org/vertx/java/test/TestModules.java index ac9974d..5598578 100644 --- a/src/main/java/org/vertx/java/test/junit/annotations/TestModules.java +++ b/src/main/java/org/vertx/java/test/TestModules.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test.junit.annotations; +package org.vertx.java.test; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/src/main/java/org/vertx/java/test/junit/annotations/TestOrder.java b/src/main/java/org/vertx/java/test/TestOrder.java similarity index 56% rename from src/main/java/org/vertx/java/test/junit/annotations/TestOrder.java rename to src/main/java/org/vertx/java/test/TestOrder.java index 1f34fb9..1f71038 100644 --- a/src/main/java/org/vertx/java/test/junit/annotations/TestOrder.java +++ b/src/main/java/org/vertx/java/test/TestOrder.java @@ -1,4 +1,4 @@ -package org.vertx.java.test.junit.annotations; +package org.vertx.java.test; public @interface TestOrder { diff --git a/src/main/java/org/vertx/java/test/junit/annotations/TestVerticle.java b/src/main/java/org/vertx/java/test/TestVerticle.java similarity index 96% rename from src/main/java/org/vertx/java/test/junit/annotations/TestVerticle.java rename to src/main/java/org/vertx/java/test/TestVerticle.java index 3f97079..242f222 100644 --- a/src/main/java/org/vertx/java/test/junit/annotations/TestVerticle.java +++ b/src/main/java/org/vertx/java/test/TestVerticle.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test.junit.annotations; +package org.vertx.java.test; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/src/main/java/org/vertx/java/test/junit/annotations/TestVerticles.java b/src/main/java/org/vertx/java/test/TestVerticles.java similarity index 95% rename from src/main/java/org/vertx/java/test/junit/annotations/TestVerticles.java rename to src/main/java/org/vertx/java/test/TestVerticles.java index 3da8441..402afd6 100644 --- a/src/main/java/org/vertx/java/test/junit/annotations/TestVerticles.java +++ b/src/main/java/org/vertx/java/test/TestVerticles.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test.junit.annotations; +package org.vertx.java.test; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/src/main/java/org/vertx/java/test/VerticleManagerAware.java b/src/main/java/org/vertx/java/test/VerticleManagerAware.java new file mode 100644 index 0000000..af324bb --- /dev/null +++ b/src/main/java/org/vertx/java/test/VerticleManagerAware.java @@ -0,0 +1,9 @@ +package org.vertx.java.test; + +import org.vertx.java.deploy.impl.VerticleManager; + +public interface VerticleManagerAware { + + void setVerticleManager(VerticleManager verticleManager); + +} diff --git a/src/main/java/org/vertx/java/test/VerticleManagerResource.java b/src/main/java/org/vertx/java/test/VerticleManagerResource.java new file mode 100644 index 0000000..ba02801 --- /dev/null +++ b/src/main/java/org/vertx/java/test/VerticleManagerResource.java @@ -0,0 +1,16 @@ +package org.vertx.java.test; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.METHOD}) +public @interface VerticleManagerResource { + +} diff --git a/src/main/java/org/vertx/java/test/VertxAware.java b/src/main/java/org/vertx/java/test/VertxAware.java new file mode 100644 index 0000000..a1cf82c --- /dev/null +++ b/src/main/java/org/vertx/java/test/VertxAware.java @@ -0,0 +1,9 @@ +package org.vertx.java.test; + +import org.vertx.java.core.Vertx; + +public interface VertxAware { + + void setVertx(Vertx vertx); + +} diff --git a/src/main/java/org/vertx/java/test/junit/annotations/VertxConfiguration.java b/src/main/java/org/vertx/java/test/VertxConfiguration.java similarity index 91% rename from src/main/java/org/vertx/java/test/junit/annotations/VertxConfiguration.java rename to src/main/java/org/vertx/java/test/VertxConfiguration.java index e5458ac..c5239cf 100644 --- a/src/main/java/org/vertx/java/test/junit/annotations/VertxConfiguration.java +++ b/src/main/java/org/vertx/java/test/VertxConfiguration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test.junit.annotations; +package org.vertx.java.test; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -33,7 +33,7 @@ @Target(ElementType.TYPE) public @interface VertxConfiguration { - String hostname() default "localhost"; + String hostname() default ""; int port() default -1; @@ -41,4 +41,6 @@ String modsDir() default "build/tmp/test-mods"; + boolean injectResources() default true; + } diff --git a/src/main/java/org/vertx/java/test/VertxResource.java b/src/main/java/org/vertx/java/test/VertxResource.java new file mode 100644 index 0000000..166425f --- /dev/null +++ b/src/main/java/org/vertx/java/test/VertxResource.java @@ -0,0 +1,16 @@ +package org.vertx.java.test; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.METHOD}) +public @interface VertxResource { + +} diff --git a/src/main/java/org/vertx/java/test/VertxTestBase.java b/src/main/java/org/vertx/java/test/VertxTestBase.java new file mode 100644 index 0000000..b043735 --- /dev/null +++ b/src/main/java/org/vertx/java/test/VertxTestBase.java @@ -0,0 +1,143 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.java.test; + +import java.util.Arrays; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.vertx.java.core.Handler; +import org.vertx.java.core.Vertx; +import org.vertx.java.core.eventbus.EventBus; +import org.vertx.java.core.eventbus.Message; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.utils.QueueReplyHandler; +import org.vertx.java.test.utils.SimpleLatchAsyncResultHandler; + + +/** + * @author swilliams + * + */ +public abstract class VertxTestBase implements VertxAware, VerticleManagerAware { + + private Vertx vertx; + + private VerticleManager manager; + + private static long AWAIT_TIMEOUT = 5000L; + + protected VertxTestBase() { + super(); + } + + @Override + public void setVertx(Vertx vertx) { + this.vertx = vertx; + } + + @Override + public void setVerticleManager(VerticleManager manager) { + this.manager = manager; + } + + protected Vertx getVertx() { + return vertx; + } + + protected EventBus getEventBus() { + return vertx.eventBus(); + } + + protected VerticleManager getManager() { + return manager; + } + + protected static final void setAwaitTimeout(long awaitTimeout) { + AWAIT_TIMEOUT = awaitTimeout; + } + + protected static final void lightSleep(long timeout) { + try { + Thread.sleep(timeout); + } catch (InterruptedException e) { + // + } + } + + protected final void testMessageEcho(String address, String message) throws Exception { + + final long timeout = 2000L; + final TimeUnit timeUnit = TimeUnit.MILLISECONDS; + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + getVertx().eventBus().send(address, message, new QueueReplyHandler(queue, timeout, timeUnit)); + + try { + String answer = queue.poll(timeout, timeUnit); + System.out.printf("For %s Q:%s A:%s %n", address, message, message.equals(answer)); + Assert.assertTrue(message.equals(answer)); + + } catch (InterruptedException e) { + // + } + } + + protected final > String registerHandler(String address, Handler handler) { + final CountDownLatch latch = new CountDownLatch(1); + String handlerId = vertx.eventBus().registerHandler(address, handler, new SimpleLatchAsyncResultHandler(latch)); + await(latch); + return handlerId; + } + + protected final > String registerLocalHandler(String address, Handler handler) { + final CountDownLatch latch = new CountDownLatch(1); + String handlerId = vertx.eventBus().registerLocalHandler(address, handler); + await(latch); + return handlerId; + } + + protected final void unregisterHandlers(String... handlers) { + unregisterHandlers(Arrays.asList(handlers)); + } + + protected final void unregisterHandlers(Iterable iterable) { + for (String handler : iterable) { + System.out.printf("unregisterHandler: %s %n", handler); + vertx.eventBus().unregisterHandler(handler); + } + } + + protected static final void await(CountDownLatch latch) { + await(latch, AWAIT_TIMEOUT); + } + + protected static final void await(CountDownLatch latch, long timeout) { + await(latch, timeout, TimeUnit.MILLISECONDS); + } + + protected static final void await(CountDownLatch latch, long timeout, TimeUnit timeUnit) { + try { + latch.await(timeout, timeUnit); + } + catch (InterruptedException e) { + // + } + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/Deployer.java b/src/main/java/org/vertx/java/test/junit/Deployer.java deleted file mode 100644 index 77097d7..0000000 --- a/src/main/java/org/vertx/java/test/junit/Deployer.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.vertx.java.test.junit; - -import java.io.File; -import java.net.URL; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import org.junit.runner.Description; -import org.vertx.java.core.json.JsonObject; -import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.junit.annotations.TestModule; -import org.vertx.java.test.junit.annotations.TestModules; -import org.vertx.java.test.junit.annotations.TestVerticle; -import org.vertx.java.test.junit.annotations.TestVerticles; -import org.vertx.java.test.junit.support.DeploymentUtils; - - -/** - * @author swilliams - * - */ -public class Deployer { - - private final AtomicInteger deploymentCounter = new AtomicInteger(0); - - private final File modDir; - - private final VerticleManager manager; - - private long shutdownTimeout; - - Deployer(VerticleManager manager, File modDir, long shutdownTimeout) { - this.manager = manager; - this.modDir = modDir; - this.shutdownTimeout = shutdownTimeout; - } - - public void deploy(Description description) { - deployModules(description.getAnnotation(TestModules.class)); - deployModule(description.getAnnotation(TestModule.class)); - deployVerticles(description.getAnnotation(TestVerticles.class)); - deployVerticle(description.getAnnotation(TestVerticle.class)); - } - - - private void deployVerticles(TestVerticles verticles) { - - if (verticles == null) { - return; - } - - final CountDownLatch latch = new CountDownLatch(verticles.value().length); - for (TestVerticle v : verticles.value()) { - JsonObject config = DeploymentUtils.getJsonConfig(v.jsonConfig()); - - URL[] urls = DeploymentUtils.findVerticleURLs(v); - manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, new CountDownLatchDoneHandler(latch)); - deploymentCounter.incrementAndGet(); - } - - await(latch); - } - - private void deployVerticle(TestVerticle v) { - if (v == null) { - return; - } - - final CountDownLatch latch = new CountDownLatch(1); - JsonObject config = DeploymentUtils.getJsonConfig(v.jsonConfig()); - URL[] urls = DeploymentUtils.findVerticleURLs(v); - - manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, new CountDownLatchDoneHandler(latch)); - deploymentCounter.incrementAndGet(); - - await(latch); - } - - private void deployModules(TestModules amodules) { - if (amodules == null) { - return; - } - - final CountDownLatch latch = new CountDownLatch(amodules.value().length); - - for (TestModule m : amodules.value()) { - JsonObject config = DeploymentUtils.getJsonConfig(m.jsonConfig()); - manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); - deploymentCounter.incrementAndGet(); - } - - await(latch); - } - - private void deployModule(TestModule m) { - if (m == null) { - return; - } - - final CountDownLatch latch = new CountDownLatch(1); - - JsonObject config = DeploymentUtils.getJsonConfig(m.jsonConfig()); - manager.deployMod(m.name(), config, m.instances(), modDir, new CountDownLatchDoneHandler(latch)); - deploymentCounter.incrementAndGet(); - - await(latch); - } - - private void await(final CountDownLatch latch) { - try { - latch.await(shutdownTimeout, TimeUnit.SECONDS); - - } catch (InterruptedException e) { - // TODO log something here - e.printStackTrace(); - } - } - - public int getDeploymentCount() { - return deploymentCounter.get(); - } - -} diff --git a/src/main/java/org/vertx/java/test/junit/JUnit4ClassRunnerAdapter.java b/src/main/java/org/vertx/java/test/junit/JUnit4ClassRunnerAdapter.java new file mode 100644 index 0000000..8867a27 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/JUnit4ClassRunnerAdapter.java @@ -0,0 +1,97 @@ +package org.vertx.java.test.junit; + +import java.util.List; + +import org.junit.rules.ExternalResource; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; + +abstract class JUnit4ClassRunnerAdapter extends BlockJUnit4ClassRunner { + + protected JUnit4ClassRunnerAdapter(Class klass) throws InitializationError { + super(klass); + } + + @Override + protected Statement methodInvoker(FrameworkMethod method, Object target) { + injectResources(method, target); + return super.methodInvoker(method, target); + } + + @Override + protected List classRules() { + List rules = super.classRules(); + rules.add(new ExternalResource() { + @Override + protected void before() throws Throwable { + beforeClass(); + super.before(); + } + + @Override + protected void after() { + afterClass(); + super.after(); + } + }); + return rules; + } + + @Override + protected List getTestRules(final Object target) { + + injectResources(target); + + List rules = super.getTestRules(target); + rules.add(new ExternalResource() { + + private Description description; + + @Override + public Statement apply(Statement base, Description description) { + this.description = description; + return super.apply(base, description); + } + + @Override + protected void before() throws Throwable { + beforeTest(description, target); + } + + @Override + protected void after() { + afterTest(description, target); + } + }); + return rules; + } + + @Override + public void run(RunNotifier notifier) { + beforeAll(); + super.run(notifier); + afterAll(); + } + + protected abstract void beforeAll(); + + protected abstract void injectResources(Object target); + + protected abstract void injectResources(FrameworkMethod method, Object target); + + protected abstract void beforeClass(); + + protected abstract void beforeTest(Description description, Object target); + + protected abstract void afterTest(Description description, Object target); + + protected abstract void afterClass(); + + protected abstract void afterAll(); + +} diff --git a/src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java b/src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java new file mode 100644 index 0000000..6a34d89 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java @@ -0,0 +1,70 @@ +package org.vertx.java.test.junit; + +import java.io.File; +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.junit.runner.Description; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.TestModule; +import org.vertx.java.test.TestModules; +import org.vertx.java.test.TestVerticle; +import org.vertx.java.test.TestVerticles; +import org.vertx.java.test.utils.DeploymentUtils; + +public class JUnitDeploymentUtils { + + /** + * @param manager + * @param description + * @return map + */ + public static Map deploy(VerticleManager manager, File modDir, Description description) { + + Map deployments = new HashMap<>(); + + // ------------------------------------------------------------------------------ + // Discover and deploy verticles + Set verticles = new HashSet<>(); + TestVerticle testVerticle = description.getAnnotation(TestVerticle.class); + if (testVerticle != null) { + verticles.add(testVerticle); + } + + TestVerticles testVerticles = description.getAnnotation(TestVerticles.class); + if (testVerticles != null) { + for (TestVerticle v : testVerticles.value()) { + verticles.add(v); + } + } + + Map verticleDeployments = DeploymentUtils.deployVerticles(manager, modDir, verticles); + deployments.putAll(verticleDeployments); + + // ------------------------------------------------------------------------------ + // Discover and deploy modules + Set modules = new HashSet<>(); + TestModule testModule = description.getAnnotation(TestModule.class); + if (testModule != null) { + modules.add(testModule); + } + + TestModules testModules = description.getAnnotation(TestModules.class); + if (testModules != null) { + for (TestModule v : testModules.value()) { + modules.add(v); + } + } + + Map modulesDeployments = DeploymentUtils.deployModules(manager, modDir, modules); + deployments.putAll(modulesDeployments); + + // ------------------------------------------------------------------------------ + // return result + return deployments; + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/OrderAnnotationComparator.java b/src/main/java/org/vertx/java/test/junit/OrderAnnotationComparator.java index d16a8ad..ce651f7 100644 --- a/src/main/java/org/vertx/java/test/junit/OrderAnnotationComparator.java +++ b/src/main/java/org/vertx/java/test/junit/OrderAnnotationComparator.java @@ -3,7 +3,7 @@ import java.util.Comparator; import org.junit.runner.Description; -import org.vertx.java.test.junit.annotations.TestOrder; +import org.vertx.java.test.TestOrder; public class OrderAnnotationComparator implements Comparator { diff --git a/src/main/java/org/vertx/java/test/junit/UnexpectedTestRunnerException.java b/src/main/java/org/vertx/java/test/junit/UnexpectedTestRunnerException.java deleted file mode 100644 index 042b1a0..0000000 --- a/src/main/java/org/vertx/java/test/junit/UnexpectedTestRunnerException.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.vertx.java.test.junit; - -public class UnexpectedTestRunnerException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public UnexpectedTestRunnerException(Exception e) { - super(e); - } - -} diff --git a/src/main/java/org/vertx/java/test/junit/VertxConfigurationJUnit4Runner.java b/src/main/java/org/vertx/java/test/junit/VertxConfigurationJUnit4Runner.java deleted file mode 100644 index 7fcdd34..0000000 --- a/src/main/java/org/vertx/java/test/junit/VertxConfigurationJUnit4Runner.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.vertx.java.test.junit; - -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runner.manipulation.Sorter; -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.InitializationError; - -/** - * @author swilliams - * - */ -public class VertxConfigurationJUnit4Runner extends BlockJUnit4ClassRunner { - - private final Set classCache = new HashSet(); - - private final VertxTestRunnerDelegate delegate; - - /** - * @param klass - * @throws InitializationError - */ - public VertxConfigurationJUnit4Runner(Class klass) throws InitializationError { - super(klass); - this.delegate = new VertxTestRunnerDelegate(); - } - - /** - * {@inheritDoc} - */ - @Override - public void run(RunNotifier notifier) { - - Comparator comparator = new OrderAnnotationComparator(); - super.sort(new Sorter(comparator)); - - delegate.runBeforeTest(getDescription()); - super.run(notifier); - delegate.runAfterTest(); - } - - @Override - protected List getTestRules(Object target) { - - List rules = super.getTestRules(target); - - if (!classCache.contains(target.toString())) { - delegate.runBeforeClass(target); - classCache.add(target.toString()); - } - else { - TestRule rule = delegate.runBeforeEachTest(target); - rules.add(rule); - } - - return rules; - } -} diff --git a/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java b/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java new file mode 100644 index 0000000..1ae46e0 --- /dev/null +++ b/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java @@ -0,0 +1,107 @@ +package org.vertx.java.test.junit; + +import java.io.File; +import java.lang.annotation.Annotation; +import java.util.Map; + +import org.junit.runner.Description; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.vertx.java.core.Handler; +import org.vertx.java.core.impl.VertxInternal; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.VertxConfiguration; +import org.vertx.java.test.utils.DeploymentUtils; +import org.vertx.java.test.utils.InjectionUtils; + +public class VertxJUnit4ClassRunner extends JUnit4ClassRunnerAdapter { + + private VertxInternal vertx; + + private VerticleManager manager; + + private VertxConfiguration configuration; + + private File modDir; + + private Map classDeployments; + + private Map methodDeployments; + + public VertxJUnit4ClassRunner(Class klass) throws InitializationError { + super(klass); + } + + @Override + protected void beforeAll() { + + VertxBuilder builder = new VertxBuilder(); + + String vertxMods = System.getProperty("vertx.mods"); + this.configuration = getDescription().getAnnotation(VertxConfiguration.class); + if (configuration != null) { + if (!"".equalsIgnoreCase(configuration.hostname())) { + builder.setAddress(configuration.hostname()); + } + if (configuration.port() > 0) { + builder.setPort(configuration.port()); + } + vertxMods = System.getProperty("vertx.mods", configuration.modsDir()); + } + + this.modDir = new File(vertxMods); + if (!modDir.exists()) { + modDir.mkdirs(); + } + + this.vertx = builder.build(); + this.manager = new VerticleManager(vertx); + } + + @Override + protected void injectResources(Object target) { + if ((configuration != null && configuration.injectResources()) || configuration == null) { + InjectionUtils.inject(vertx, target); + InjectionUtils.inject(manager, target); + } + } + + @Override + protected void injectResources(FrameworkMethod method, Object target) { + injectResources(target); // TODO probable double setting... test & remove + } + + @Override + protected void beforeClass() { + this.classDeployments = JUnitDeploymentUtils.deploy(manager, modDir, getDescription()); + } + + @Override + protected void beforeTest(Description description, Object target) { + this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description); + } + + @Override + protected void afterTest(Description description, Object target) { + if (methodDeployments.size() > 0) { + DeploymentUtils.undeploy(manager, methodDeployments); + } + } + + @Override + protected void afterClass() { + if (classDeployments.size() > 0) { + DeploymentUtils.undeploy(manager, classDeployments); + } + } + + @Override + protected void afterAll() { + manager.undeployAll(new Handler() { + @Override + public void handle(Void event) { + // + }}); + } + +} diff --git a/src/main/java/org/vertx/java/test/junit/VertxTestRule.java b/src/main/java/org/vertx/java/test/junit/VertxTestRule.java deleted file mode 100644 index 42fc6ae..0000000 --- a/src/main/java/org/vertx/java/test/junit/VertxTestRule.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.vertx.java.test.junit; - -import java.io.File; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.junit.rules.ExternalResource; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; -import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.junit.annotations.TestModule; -import org.vertx.java.test.junit.annotations.TestVerticle; -import org.vertx.java.test.junit.support.DeploymentUtils; - -public class VertxTestRule extends ExternalResource { - - private static final long TIMEOUT = 15L; - - private final Set testVerticles = new HashSet<>(); - - private final Set testModules = new HashSet<>(); - - private final VerticleManager manager; - - private File currentModDir; - - public VertxTestRule(VerticleManager manager) { - this.manager = manager; - - String vertxMods = System.getProperty("vertx.mods"); - this.currentModDir = new File(vertxMods); - if (!currentModDir.exists()) { - currentModDir.mkdirs(); - } - } - - public VertxTestRule(VerticleManager manager, File currentModDir) { - this.manager = manager; - this.currentModDir = currentModDir; - } - - @Override - public Statement apply(final Statement base, final Description description) { - findAnnotations(description); - return super.apply(base, description); - } - - private void findAnnotations(final Description description) { - testModules.addAll(DeploymentUtils.findTestModules(description)); - testVerticles.addAll(DeploymentUtils.findTestVerticles(description)); - } - - @Override - protected void before() throws Throwable { - - if (!currentModDir.exists()) { - currentModDir.mkdirs(); - } - - DeploymentUtils.deployVerticles(manager, testVerticles, currentModDir, TIMEOUT); - DeploymentUtils.deployModules(manager, testModules, currentModDir, TIMEOUT); - - super.before(); - } - - @Override - protected void after() { - - CountDownLatch latch = new CountDownLatch(1); - CountDownLatchDoneHandler handler = new CountDownLatchDoneHandler(latch); - - manager.undeployAll(handler); - - try { - latch.await(TIMEOUT, TimeUnit.SECONDS); - } catch (InterruptedException e) { - // - } - - super.after(); - } - -} diff --git a/src/main/java/org/vertx/java/test/junit/VertxTestRunnerDelegate.java b/src/main/java/org/vertx/java/test/junit/VertxTestRunnerDelegate.java deleted file mode 100644 index 1e7b579..0000000 --- a/src/main/java/org/vertx/java/test/junit/VertxTestRunnerDelegate.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.vertx.java.test.junit; - -import java.io.File; -import java.util.Set; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.vertx.java.core.impl.DefaultVertx; -import org.vertx.java.deploy.Verticle; -import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.junit.annotations.TestModule; -import org.vertx.java.test.junit.annotations.TestVerticle; -import org.vertx.java.test.junit.annotations.VertxConfiguration; -import org.vertx.java.test.junit.support.DeploymentUtils; -import org.vertx.java.test.junit.support.VertxReflectionUtils; - -public class VertxTestRunnerDelegate { - - private long timeout = 15L; - - private File currentModDir; - - private DefaultVertx vertx; - - private VerticleManager manager; - - private Verticle verticle; - - private VertxTestRule testRule; - - public void runBeforeTest(Description description) { - - VertxConfiguration config = description.getAnnotation(VertxConfiguration.class); - VertxBuilder builder = new VertxBuilder(); - String vertxMods; - - if (config != null) { - this.timeout = config.shutdownTimeoutSeconds(); - if (config.port() > 0) { - builder.setPort(config.port()); - } - if (!"".equals(config.hostname())) { - builder.setAddress(config.hostname()); - } - vertxMods = System.getProperty("vertx.mods", config.modsDir()); - } - else { - this.timeout = 30L; - this.vertx = new DefaultVertx(); - vertxMods = System.getProperty("vertx.mods"); - } - - this.vertx = builder.build(); - - this.currentModDir = new File(vertxMods); - if (!currentModDir.exists()) { - currentModDir.mkdirs(); - } - - this.manager = new VerticleManager(vertx); - this.testRule = new VertxTestRule(manager, currentModDir); - - Set testModules = DeploymentUtils.findTestModules(description); - DeploymentUtils.deployModules(manager, testModules, currentModDir, timeout); - - Set testVerticles = DeploymentUtils.findTestVerticles(description); - DeploymentUtils.deployVerticles(manager, testVerticles, currentModDir, timeout); - } - - public void runBeforeClass(Object target) { - this.verticle = VertxReflectionUtils.configureTargetTestClass(vertx, manager, target); - } - - public TestRule runBeforeEachTest(Object target) { - return testRule; - } - - public void runAfterTest() { - System.out.println("Delegate.runAfterTest"); - - DeploymentUtils.undeployAll(manager, timeout); - - if (verticle != null) { - try { - verticle.stop(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - -} diff --git a/src/main/java/org/vertx/java/test/junit/VertxRule.java b/src/main/java/org/vertx/java/test/junit/package-info.java similarity index 52% rename from src/main/java/org/vertx/java/test/junit/VertxRule.java rename to src/main/java/org/vertx/java/test/junit/package-info.java index f6df304..c2ef99b 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxRule.java +++ b/src/main/java/org/vertx/java/test/junit/package-info.java @@ -13,35 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test.junit; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - - /** * @author swilliams * */ -public class VertxRule implements TestRule { - - private final Deployer deployer; - - public VertxRule(Deployer deployer) { - this.deployer = deployer; - } - - @Override - public Statement apply(final Statement base, final Description description) { - - return new Statement() { - - @Override - public void evaluate() throws Throwable { - deployer.deploy(description); - base.evaluate(); - }}; - } - -} +package org.vertx.java.test.junit; \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java b/src/main/java/org/vertx/java/test/utils/CountDownLatchDoneHandler.java similarity index 96% rename from src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java rename to src/main/java/org/vertx/java/test/utils/CountDownLatchDoneHandler.java index 9907759..0616123 100644 --- a/src/main/java/org/vertx/java/test/junit/CountDownLatchDoneHandler.java +++ b/src/main/java/org/vertx/java/test/utils/CountDownLatchDoneHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test.junit; +package org.vertx.java.test.utils; import java.util.concurrent.CountDownLatch; diff --git a/src/main/java/org/vertx/java/test/junit/DeploymentHandler.java b/src/main/java/org/vertx/java/test/utils/DeploymentHandler.java similarity index 86% rename from src/main/java/org/vertx/java/test/junit/DeploymentHandler.java rename to src/main/java/org/vertx/java/test/utils/DeploymentHandler.java index 52b8f72..0bbd7d2 100644 --- a/src/main/java/org/vertx/java/test/junit/DeploymentHandler.java +++ b/src/main/java/org/vertx/java/test/utils/DeploymentHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.vertx.java.test.junit; +package org.vertx.java.test.utils; import java.util.HashSet; import java.util.Set; @@ -44,8 +44,11 @@ public void handle(String event) { latch.countDown(); } - public Set getDeploymentIDs() { - return deploymentIDs; + public String getDeploymentID() { + if (deploymentIDs.size() == 0) { + return null; + } + return deploymentIDs.iterator().next(); } } \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java new file mode 100644 index 0000000..eba6cff --- /dev/null +++ b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java @@ -0,0 +1,200 @@ +package org.vertx.java.test.utils; + +import java.io.File; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.vertx.java.core.Handler; +import org.vertx.java.core.json.JsonObject; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.TestModule; +import org.vertx.java.test.TestVerticle; + +public class DeploymentUtils { + + public static Map deployVerticles(VerticleManager manager, File modDir, Set verticles) { + Map deployments = new HashMap<>(); + + if (verticles.size() > 0) { + CountDownLatch latch = new CountDownLatch(verticles.size()); + Map handlers = new HashMap<>(); + + for (TestVerticle v : verticles) { + DeploymentHandler handler = new DeploymentHandler(latch); + handlers.put(v, handler); + + JsonObject config = getJsonConfig(v.jsonConfig()); + URL[] urls = findVerticleURLs(v); + + System.out.printf("DeploymentUtils.deployVerticle(%s)%n", v); + manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, handler); + } + + await(latch); + + Set> entrySet = handlers.entrySet(); + for (Entry e : entrySet) { + deployments.put(e.getKey(), e.getValue().getDeploymentID()); + } + } + + return deployments; + } + + public static Map deployModules(VerticleManager manager, File modDir, Set modules) { + Map deployments = new HashMap<>(); + + if (modules.size() > 0) { + CountDownLatch latch = new CountDownLatch(modules.size()); + Map handlers = new HashMap<>(); + + for (TestModule m : modules) { + DeploymentHandler handler = new DeploymentHandler(latch); + handlers.put(m, handler); + + JsonObject config = getJsonConfig(m.jsonConfig()); + + System.out.printf("DeploymentUtils.deployModule(%s)%n", m); + manager.deployMod(m.name(), config, m.instances(), modDir, handler); + } + + await(latch); + + Set> entrySet = handlers.entrySet(); + for (Entry e : entrySet) { + deployments.put(e.getKey(), e.getValue().getDeploymentID()); + } + } + + return deployments; + } + + public static void undeploy(VerticleManager manager, Map deployments) { + + final CountDownLatch latch = new CountDownLatch(deployments.size()); + + for (final String id : deployments.values()) { + manager.undeploy(id, new Handler() { + @Override + public void handle(Void event) { + System.out.printf("DeploymentUtils.undeployed(%s)%n", id); + latch.countDown(); + } + }); + + await(latch, 2000L); // FIXME this appears to hang + } + } + + + public static JsonObject getJsonConfig(String jsonConfig) { + JsonObject config; + + if (jsonConfig.startsWith("file:")) { + String filename = jsonConfig.replaceFirst("file:", ""); + Path json = new File(filename).toPath(); + + try { + Charset utf8 = Charset.forName("UTF-8"); + byte[] bytes = Files.readAllBytes(json); + config = new JsonObject(new String(bytes, utf8)); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + else { + config = new JsonObject(jsonConfig); + } + + return config; + } + + public static URL[] findVerticleURLs(TestVerticle v) { + Set urlSet = new HashSet(); + + if (v.urls().length > 0) { + for (String path : v.urls()) { + + try { + + URL url = new File(path).toURI().toURL(); + urlSet.add(url); + + } catch (Exception e) { + // TODO log something here + e.printStackTrace(); + } + } + } + + try { + String main = v.main(); + if (main.indexOf(':') > -1) { + main = main.substring(main.indexOf(':') + 1); + } + + // check for class, prep for locating root URL + int parts = 0; + if (!main.endsWith(".xml")) { + parts = main.split("\\.").length; + main = main.replaceAll("\\.", "/"); + main = main + ".class"; + } + + // contortions to get parent, may not be entirely accurate... + // URL url = getClass().getClassLoader().getResource(main); + URL url = Thread.currentThread().getContextClassLoader().getResource(main); + + if (url != null) { + Path path = Paths.get(url.toURI()); + + int i = parts; + while (i > 0) { + path = path.getParent(); + i--; + } + + url = path.toUri().toURL(); + urlSet.add(url); + } + + } catch (Exception e) { + // TODO log something here + e.printStackTrace(); + } + + URL[] urls = new URL[urlSet.size()]; + return urlSet.toArray(urls); + } + + public static void await(final CountDownLatch latch) { + try { + latch.await(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void await(final CountDownLatch latch, final long timeout) { + try { + latch.await(timeout, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/src/main/java/org/vertx/java/test/utils/InjectionUtils.java b/src/main/java/org/vertx/java/test/utils/InjectionUtils.java new file mode 100644 index 0000000..01c1e08 --- /dev/null +++ b/src/main/java/org/vertx/java/test/utils/InjectionUtils.java @@ -0,0 +1,24 @@ +package org.vertx.java.test.utils; + +import org.vertx.java.core.impl.VertxInternal; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.VerticleManagerAware; +import org.vertx.java.test.VertxAware; + +public class InjectionUtils { + + public static void inject(VertxInternal vertx, Object target) { + if (target instanceof VertxAware) { + VertxAware aware = (VertxAware) target; + aware.setVertx(vertx); + } + } + + public static void inject(VerticleManager verticleManager, Object target) { + if (target instanceof VerticleManagerAware) { + VerticleManagerAware aware = (VerticleManagerAware) target; + aware.setVerticleManager(verticleManager); + } + } + +} diff --git a/src/main/java/org/vertx/java/test/utils/QueueReplyHandler.java b/src/main/java/org/vertx/java/test/utils/QueueReplyHandler.java new file mode 100644 index 0000000..8a5c664 --- /dev/null +++ b/src/main/java/org/vertx/java/test/utils/QueueReplyHandler.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vertx.java.test.utils; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.vertx.java.core.Handler; +import org.vertx.java.core.eventbus.Message; + +/** + * @author swilliams + * + * @param + */ +public class QueueReplyHandler implements Handler> { + + private final LinkedBlockingQueue queue; + + private final long timeout; + + private final TimeUnit timeUnit; + + public QueueReplyHandler(LinkedBlockingQueue queue) { + this(queue, 5000L); + } + + public QueueReplyHandler(LinkedBlockingQueue queue, long timeout) { + this(queue, timeout, TimeUnit.MILLISECONDS); + } + + public QueueReplyHandler(LinkedBlockingQueue queue, long timeout, TimeUnit timeUnit) { + this.queue = queue; + this.timeout = timeout; + this.timeUnit = timeUnit; + } + + @Override + public void handle(Message event) { + + try { + if (event != null && event.body != null) { + queue.offer(event.body, timeout, timeUnit); + } + + } catch (InterruptedException e) { + Assert.fail(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/utils/SimpleLatchAsyncResultHandler.java b/src/main/java/org/vertx/java/test/utils/SimpleLatchAsyncResultHandler.java new file mode 100644 index 0000000..a466ebe --- /dev/null +++ b/src/main/java/org/vertx/java/test/utils/SimpleLatchAsyncResultHandler.java @@ -0,0 +1,28 @@ +package org.vertx.java.test.utils; + +import java.util.concurrent.CountDownLatch; + +import org.vertx.java.core.AsyncResult; +import org.vertx.java.core.AsyncResultHandler; + +public class SimpleLatchAsyncResultHandler implements AsyncResultHandler { + + private final CountDownLatch latch; + + private volatile boolean succeeded; + + public SimpleLatchAsyncResultHandler(CountDownLatch latch) { + this.latch = latch; + } + + @Override + public void handle(AsyncResult event) { + this.succeeded = event.succeeded(); + latch.countDown(); + } + + public boolean isSucceeded() { + return succeeded; + } + +} \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/utils/package-info.java b/src/main/java/org/vertx/java/test/utils/package-info.java new file mode 100644 index 0000000..87a1004 --- /dev/null +++ b/src/main/java/org/vertx/java/test/utils/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author swilliams + * + */ +package org.vertx.java.test.utils; \ No newline at end of file diff --git a/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java b/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java index b402990..44bf4b7 100644 --- a/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java +++ b/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java @@ -26,9 +26,10 @@ import org.vertx.java.core.Vertx; import org.vertx.java.core.impl.DefaultVertx; import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.junit.annotations.TestModule; -import org.vertx.java.test.junit.annotations.TestModules; -import org.vertx.java.test.junit.support.QueueReplyHandler; +import org.vertx.java.test.TestModule; +import org.vertx.java.test.TestModules; +import org.vertx.java.test.junit.old.VertxTestRule; +import org.vertx.java.test.utils.QueueReplyHandler; /** diff --git a/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java b/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java index 92221dd..77dfc0f 100644 --- a/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java +++ b/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java @@ -23,10 +23,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.vertx.java.test.junit.annotations.TestModule; -import org.vertx.java.test.junit.annotations.TestModules; -import org.vertx.java.test.junit.support.QueueReplyHandler; -import org.vertx.java.test.junit.support.VertxTestBase; +import org.vertx.java.test.TestModule; +import org.vertx.java.test.TestModules; +import org.vertx.java.test.VertxTestBase; +import org.vertx.java.test.junit.old.VertxConfigurationJUnit4Runner; +import org.vertx.java.test.utils.QueueReplyHandler; /** diff --git a/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java index 82dbd8a..b642c9c 100644 --- a/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java +++ b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java @@ -25,8 +25,9 @@ import org.vertx.java.core.Handler; import org.vertx.java.core.Vertx; import org.vertx.java.core.eventbus.Message; -import org.vertx.java.test.junit.support.QueueReplyHandler; -import org.vertx.java.test.junit.support.VertxSupport; +import org.vertx.java.test.junit.old.VertxConfigurationJUnit4Runner; +import org.vertx.java.test.junit.old.VertxSupport; +import org.vertx.java.test.utils.QueueReplyHandler; /** diff --git a/src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java b/src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java new file mode 100644 index 0000000..318984b --- /dev/null +++ b/src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java @@ -0,0 +1,73 @@ +package org.vertx.java.test.junit; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.TestVerticle; +import org.vertx.java.test.VerticleManagerAware; +import org.vertx.java.test.VertxConfiguration; + +@RunWith(VertxJUnit4ClassRunner.class) +@VertxConfiguration +@TestVerticle(main="test_verticle0.js") +public class SimpleModuleTest implements VerticleManagerAware { + + private volatile VerticleManager verticleManager; + + @Override + public void setVerticleManager(VerticleManager verticleManager) { + this.verticleManager = verticleManager; + } + + + @BeforeClass + @TestVerticle(main="test_verticle1.js") + public static void beforeClass() { + System.out.println("test.beforeClass"); + } + + @Before + @TestVerticle(main="test_verticle2.js") + public void before() { + System.out.println("test.before"); + } + + @Test + @TestVerticle(main="test_verticle3.js") + public void test1() { + System.out.println("test.test1"); + } + + @Test + @TestVerticle(main="test_verticle4.js") + public void test2() { + System.out.println("test.test2"); + } + + @Test + @TestVerticle(main="test_verticle5.js") + public void test3() { + System.out.println("test.test3"); + } + + @Test + @TestVerticle(main="test_verticle6.js") + public void test4() { + System.out.println("test.test4"); + } + + @After + public void after() { + System.out.println("test.after"); + } + + @AfterClass + public static void afterClass() { + System.out.println("test.afterClass"); + } + +} diff --git a/src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java b/src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java new file mode 100644 index 0000000..ba42b64 --- /dev/null +++ b/src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java @@ -0,0 +1,52 @@ +package org.vertx.java.test.junit; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.TestVerticle; +import org.vertx.java.test.TestVerticles; +import org.vertx.java.test.VerticleManagerAware; +import org.vertx.java.test.VertxConfiguration; + +@RunWith(VertxJUnit4ClassRunner.class) +@VertxConfiguration +@TestVerticle(main="test_verticle0.js") +public class SimpleVerticleTest implements VerticleManagerAware { + + private volatile VerticleManager verticleManager; + + @Override + public void setVerticleManager(VerticleManager verticleManager) { + this.verticleManager = verticleManager; + } + + @Test + public void test0() { + int instances = verticleManager.listInstances().size(); + System.out.println("test.test0 " + instances); + Assert.assertEquals(instances, 1); + } + + @Test + @TestVerticles({ + @TestVerticle(main="test_verticle1.js"), + @TestVerticle(main="test_verticle2.js"), + @TestVerticle(main="test_verticle3.js") + }) + public void test1() { + int instances = verticleManager.listInstances().size(); + System.out.println("test.test1 " + instances); + Assert.assertEquals(instances, 4); + } + + @Test + @TestVerticle(main="test_verticle4.js") + public void test2() { + int instances = verticleManager.listInstances().size(); + System.out.println("test.test2 " + instances); + Assert.assertEquals(instances, 2); + } + +} diff --git a/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java b/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java index 4d6bd14..5c9438c 100644 --- a/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java +++ b/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java @@ -26,9 +26,10 @@ import org.vertx.java.core.Vertx; import org.vertx.java.core.impl.DefaultVertx; import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.junit.annotations.TestVerticle; -import org.vertx.java.test.junit.annotations.TestVerticles; -import org.vertx.java.test.junit.support.QueueReplyHandler; +import org.vertx.java.test.TestVerticle; +import org.vertx.java.test.TestVerticles; +import org.vertx.java.test.junit.old.VertxTestRule; +import org.vertx.java.test.utils.QueueReplyHandler; /** diff --git a/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java b/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java index 7dd4208..d75444d 100644 --- a/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java +++ b/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java @@ -23,10 +23,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.vertx.java.test.junit.annotations.TestVerticle; -import org.vertx.java.test.junit.annotations.TestVerticles; -import org.vertx.java.test.junit.support.QueueReplyHandler; -import org.vertx.java.test.junit.support.VertxTestBase; +import org.vertx.java.test.TestVerticle; +import org.vertx.java.test.TestVerticles; +import org.vertx.java.test.VertxTestBase; +import org.vertx.java.test.junit.old.VertxConfigurationJUnit4Runner; +import org.vertx.java.test.utils.QueueReplyHandler; /** diff --git a/src/test/resources/test_verticle3.js b/src/test/resources/test_verticle3.js new file mode 100644 index 0000000..6d7b1b5 --- /dev/null +++ b/src/test/resources/test_verticle3.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; + +var address = 'vertx.test.echo3'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); diff --git a/src/test/resources/test_verticle4.js b/src/test/resources/test_verticle4.js new file mode 100644 index 0000000..927f0db --- /dev/null +++ b/src/test/resources/test_verticle4.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; + +var address = 'vertx.test.echo4'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); diff --git a/src/test/resources/test_verticle5.js b/src/test/resources/test_verticle5.js new file mode 100644 index 0000000..f939e04 --- /dev/null +++ b/src/test/resources/test_verticle5.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; + +var address = 'vertx.test.echo5'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); diff --git a/src/test/resources/test_verticle6.js b/src/test/resources/test_verticle6.js new file mode 100644 index 0000000..a49ac92 --- /dev/null +++ b/src/test/resources/test_verticle6.js @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +load('vertx.js') + +var eb = vertx.eventBus; + +var address = 'vertx.test.echo6'; + +eb.registerHandler(address, function(msg, reply) { + reply(msg); +}); From f53b84ac4cd987dbf87e1f1c1cd16bf0047f7a61 Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Mon, 3 Sep 2012 13:27:30 +0100 Subject: [PATCH 08/18] removed classes --- .../test/junit/support/DeploymentUtils.java | 210 ------------------ .../test/junit/support/QueueReplyHandler.java | 64 ------ .../SimpleLatchAsyncResultHandler.java | 28 --- .../junit/support/VerticleManagerSupport.java | 29 --- .../junit/support/VertxReflectionUtils.java | 65 ------ .../java/test/junit/support/VertxSupport.java | 29 --- .../test/junit/support/VertxTestBase.java | 141 ------------ .../java/test/junit/support/package-info.java | 20 -- 8 files changed, 586 deletions(-) delete mode 100644 src/main/java/org/vertx/java/test/junit/support/DeploymentUtils.java delete mode 100644 src/main/java/org/vertx/java/test/junit/support/QueueReplyHandler.java delete mode 100644 src/main/java/org/vertx/java/test/junit/support/SimpleLatchAsyncResultHandler.java delete mode 100644 src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java delete mode 100644 src/main/java/org/vertx/java/test/junit/support/VertxReflectionUtils.java delete mode 100644 src/main/java/org/vertx/java/test/junit/support/VertxSupport.java delete mode 100644 src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java delete mode 100644 src/main/java/org/vertx/java/test/junit/support/package-info.java diff --git a/src/main/java/org/vertx/java/test/junit/support/DeploymentUtils.java b/src/main/java/org/vertx/java/test/junit/support/DeploymentUtils.java deleted file mode 100644 index 8ae0b49..0000000 --- a/src/main/java/org/vertx/java/test/junit/support/DeploymentUtils.java +++ /dev/null @@ -1,210 +0,0 @@ -package org.vertx.java.test.junit.support; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.junit.runner.Description; -import org.vertx.java.core.json.JsonObject; -import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.junit.CountDownLatchDoneHandler; -import org.vertx.java.test.junit.DeploymentHandler; -import org.vertx.java.test.junit.annotations.TestModule; -import org.vertx.java.test.junit.annotations.TestModules; -import org.vertx.java.test.junit.annotations.TestVerticle; -import org.vertx.java.test.junit.annotations.TestVerticles; - -public class DeploymentUtils { - - public static Set findTestModules(Description description) { - Set testModules = new HashSet<>(); - - TestModules modules = description.getAnnotation(TestModules.class); - if (modules != null) { - for (TestModule m : modules.value()) { - testModules.add(m); - } - } - - TestModule m = description.getAnnotation(TestModule.class); - if (m != null) { - testModules.add(m); - } - - return testModules; - } - - public static Set findTestVerticles(Description description) { - Set testVerticles = new HashSet<>(); - - TestVerticles verticles = description.getAnnotation(TestVerticles.class); - if (verticles != null) { - for (TestVerticle v : verticles.value()) { - testVerticles.add(v); - } - } - - TestVerticle v = description.getAnnotation(TestVerticle.class); - if (v != null) { - testVerticles.add(v); - } - - return testVerticles; - } - - public static Set deployVerticles(VerticleManager manager, Set testVerticles, File currentModDir, long timeout) { - - Set verticleDeployments = new HashSet<>(); - - if (testVerticles.size() > 0) { - CountDownLatch latch = new CountDownLatch(testVerticles.size()); - - DeploymentHandler handler = new DeploymentHandler(latch); - for (TestVerticle v : testVerticles) { - JsonObject config = getJsonConfig(v.jsonConfig()); - URL[] urls = findVerticleURLs(v); - - System.out.printf("Deployment.deployVerticle(%s)%n", v); - manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), currentModDir, handler); - } - - try { - latch.await(timeout, TimeUnit.SECONDS); - } catch (InterruptedException e) { - - } - verticleDeployments.addAll(handler.getDeploymentIDs()); - } - - return verticleDeployments; - } - - public static Set deployModules(VerticleManager manager, Set testModules, File currentModDir, long timeout) { - Set moduleDeployments = new HashSet<>(); - - if (testModules.size() > 0) { - - CountDownLatch latch = new CountDownLatch(testModules.size()); - DeploymentHandler handler = new DeploymentHandler(latch); - for (TestModule m : testModules) { - - System.out.printf("Deployment.deployModule(%s)%n", m); - JsonObject config = getJsonConfig(m.jsonConfig()); - - manager.deployMod(m.name(), config, m.instances(), currentModDir, handler); - } - - try { - latch.await(timeout, TimeUnit.SECONDS); - } catch (InterruptedException e) { - - } - moduleDeployments.addAll(handler.getDeploymentIDs()); - } - return moduleDeployments; - } - - public static JsonObject getJsonConfig(String jsonConfig) { - JsonObject config; - - if (jsonConfig.startsWith("file:")) { - String filename = jsonConfig.replaceFirst("file:", ""); - Path json = new File(filename).toPath(); - - try { - Charset utf8 = Charset.forName("UTF-8"); - byte[] bytes = Files.readAllBytes(json); - config = new JsonObject(new String(bytes, utf8)); - - } catch (IOException e) { - throw new RuntimeException(e); - } - } - else { - config = new JsonObject(jsonConfig); - } - - return config; - } - - public static URL[] findVerticleURLs(TestVerticle v) { - Set urlSet = new HashSet(); - - if (v.urls().length > 0) { - for (String path : v.urls()) { - - try { - - URL url = new File(path).toURI().toURL(); - urlSet.add(url); - - } catch (Exception e) { - // TODO log something here - e.printStackTrace(); - } - } - } - - try { - String main = v.main(); - if (main.indexOf(':') > -1) { - main = main.substring(main.indexOf(':') + 1); - } - - // check for class, prep for locating root URL - int parts = 0; - if (!main.endsWith(".xml")) { - parts = main.split("\\.").length; - main = main.replaceAll("\\.", "/"); - main = main + ".class"; - } - - // contortions to get parent, may not be entirely accurate... - // URL url = getClass().getClassLoader().getResource(main); - URL url = Thread.currentThread().getContextClassLoader().getResource(main); - - if (url != null) { - Path path = Paths.get(url.toURI()); - - int i = parts; - while (i > 0) { - path = path.getParent(); - i--; - } - - url = path.toUri().toURL(); - urlSet.add(url); - } - - } catch (Exception e) { - // TODO log something here - e.printStackTrace(); - } - - URL[] urls = new URL[urlSet.size()]; - return urlSet.toArray(urls); - } - - public static void undeployAll(VerticleManager manager, long timeout) { - - CountDownLatch latch = new CountDownLatch(1); - CountDownLatchDoneHandler handler = new CountDownLatchDoneHandler(latch); - - manager.undeployAll(handler); - - try { - latch.await(timeout, TimeUnit.SECONDS); - } catch (InterruptedException e) { - // - } - } - -} diff --git a/src/main/java/org/vertx/java/test/junit/support/QueueReplyHandler.java b/src/main/java/org/vertx/java/test/junit/support/QueueReplyHandler.java deleted file mode 100644 index c8a21aa..0000000 --- a/src/main/java/org/vertx/java/test/junit/support/QueueReplyHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.vertx.java.test.junit.support; - -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -import org.junit.Assert; -import org.vertx.java.core.Handler; -import org.vertx.java.core.eventbus.Message; - -/** - * @author swilliams - * - * @param - */ -public class QueueReplyHandler implements Handler> { - - private final LinkedBlockingQueue queue; - - private final long timeout; - - private final TimeUnit timeUnit; - - public QueueReplyHandler(LinkedBlockingQueue queue) { - this(queue, 5000L); - } - - public QueueReplyHandler(LinkedBlockingQueue queue, long timeout) { - this(queue, timeout, TimeUnit.MILLISECONDS); - } - - public QueueReplyHandler(LinkedBlockingQueue queue, long timeout, TimeUnit timeUnit) { - this.queue = queue; - this.timeout = timeout; - this.timeUnit = timeUnit; - } - - @Override - public void handle(Message event) { - - try { - if (event != null && event.body != null) { - queue.offer(event.body, timeout, timeUnit); - } - - } catch (InterruptedException e) { - Assert.fail(e.getMessage()); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/support/SimpleLatchAsyncResultHandler.java b/src/main/java/org/vertx/java/test/junit/support/SimpleLatchAsyncResultHandler.java deleted file mode 100644 index 12e8d20..0000000 --- a/src/main/java/org/vertx/java/test/junit/support/SimpleLatchAsyncResultHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.vertx.java.test.junit.support; - -import java.util.concurrent.CountDownLatch; - -import org.vertx.java.core.AsyncResult; -import org.vertx.java.core.AsyncResultHandler; - -public class SimpleLatchAsyncResultHandler implements AsyncResultHandler { - - private final CountDownLatch latch; - - private volatile boolean succeeded; - - public SimpleLatchAsyncResultHandler(CountDownLatch latch) { - this.latch = latch; - } - - @Override - public void handle(AsyncResult event) { - this.succeeded = event.succeeded(); - latch.countDown(); - } - - public boolean isSucceeded() { - return succeeded; - } - -} \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java b/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java deleted file mode 100644 index 042c2ba..0000000 --- a/src/main/java/org/vertx/java/test/junit/support/VerticleManagerSupport.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.vertx.java.test.junit.support; - -import org.vertx.java.deploy.impl.VerticleManager; - - -/** - * @author swilliams - * - */ -public interface VerticleManagerSupport { - - void setManager(VerticleManager manager); - -} \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/support/VertxReflectionUtils.java b/src/main/java/org/vertx/java/test/junit/support/VertxReflectionUtils.java deleted file mode 100644 index b80de68..0000000 --- a/src/main/java/org/vertx/java/test/junit/support/VertxReflectionUtils.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.vertx.java.test.junit.support; - -import org.vertx.java.core.Vertx; -import org.vertx.java.deploy.Container; -import org.vertx.java.deploy.Verticle; -import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.junit.UnexpectedTestRunnerException; - -public class VertxReflectionUtils { - - /** - * @param target - */ - public static Verticle configureTargetTestClass(Vertx vertx, VerticleManager verticleManager, Object target) { - - Verticle verticle = null; - if (target instanceof Verticle) { - // TODO do something clever here... - System.out.printf("Test class is a Verticle: %s %n", target.getClass().getName()); - verticle = (Verticle) target; - verticle.setVertx(vertx); - verticle.setContainer(new Container(verticleManager)); - try { - verticle.start(); - } catch (Exception e) { - throw new UnexpectedTestRunnerException(e); - } - } - - // discover VertxSupport - if (target instanceof VertxSupport) { - VertxSupport support = (VertxSupport) target; - support.setVertx(vertx); - } - - // discover VerticleManager support - if (target instanceof VerticleManagerSupport) { - VerticleManagerSupport support = (VerticleManagerSupport) target; - support.setManager(verticleManager); - } - -// // discover setVertx method -// try { -// Method setVertxMethod = target.getClass().getMethod("setVertx", Vertx.class); -// if (setVertxMethod.isAnnotationPresent(Resource.class)) { -// setVertxMethod.invoke(target, vertx); -// } -// } catch (Exception e) { -// // we can ignore this if the method isn't present -// } -// -// // discover setVerticleManager method -// try { -// Method setVerticleManagerMethod = target.getClass().getMethod("setVerticleManager", VerticleManager.class); -// if (setVerticleManagerMethod.isAnnotationPresent(Resource.class)) { -// setVerticleManagerMethod.invoke(target, verticleManager); -// } -// } catch (Exception e) { -// // we can ignore this if the method isn't present -// } - - return verticle; - } - -} diff --git a/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java b/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java deleted file mode 100644 index 24355ed..0000000 --- a/src/main/java/org/vertx/java/test/junit/support/VertxSupport.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.vertx.java.test.junit.support; - -import org.vertx.java.core.Vertx; - - -/** - * @author swilliams - * - */ -public interface VertxSupport { - - void setVertx(Vertx vertx); - -} \ No newline at end of file diff --git a/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java b/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java deleted file mode 100644 index 5f6fcf1..0000000 --- a/src/main/java/org/vertx/java/test/junit/support/VertxTestBase.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.vertx.java.test.junit.support; - -import java.util.Arrays; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -import org.junit.Assert; -import org.vertx.java.core.Handler; -import org.vertx.java.core.Vertx; -import org.vertx.java.core.eventbus.EventBus; -import org.vertx.java.core.eventbus.Message; -import org.vertx.java.deploy.impl.VerticleManager; - - -/** - * @author swilliams - * - */ -public abstract class VertxTestBase implements VertxSupport, VerticleManagerSupport { - - private Vertx vertx; - - private VerticleManager manager; - - private long awaitTimeout = 5000L; - - protected VertxTestBase() { - super(); - } - - @Override - public void setVertx(Vertx vertx) { - this.vertx = vertx; - } - - @Override - public void setManager(VerticleManager manager) { - this.manager = manager; - } - - protected Vertx getVertx() { - return vertx; - } - - protected EventBus getEventBus() { - return vertx.eventBus(); - } - - protected VerticleManager getManager() { - return manager; - } - - protected final void setAwaitTimeout(long awaitTimeout) { - this.awaitTimeout = awaitTimeout; - } - - protected final void lightSleep(long timeout) { - try { - Thread.sleep(timeout); - } catch (InterruptedException e) { - // - } - } - - protected final void testMessageEcho(String address, String message) throws Exception { - - final long timeout = 2000L; - final TimeUnit timeUnit = TimeUnit.MILLISECONDS; - final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); - - getVertx().eventBus().send(address, message, new QueueReplyHandler(queue, timeout, timeUnit)); - - try { - String answer = queue.poll(timeout, timeUnit); - System.out.printf("For %s Q:%s A:%s %n", address, message, message.equals(answer)); - Assert.assertTrue(message.equals(answer)); - - } catch (InterruptedException e) { - // - } - } - - protected final > String registerHandler(String address, Handler handler) { - final CountDownLatch latch = new CountDownLatch(1); - String handlerId = vertx.eventBus().registerHandler(address, handler, new SimpleLatchAsyncResultHandler(latch)); - await(latch); - return handlerId; - } - - protected final > String registerLocalHandler(String address, Handler handler) { - final CountDownLatch latch = new CountDownLatch(1); - String handlerId = vertx.eventBus().registerLocalHandler(address, handler); - await(latch); - return handlerId; - } - - protected final void unregisterHandlers(String... handlers) { - unregisterHandlers(Arrays.asList(handlers)); - } - - protected final void unregisterHandlers(Iterable iterable) { - for (String handler : iterable) { - System.out.printf("unregisterHandler: %s %n", handler); - getVertx().eventBus().unregisterHandler(handler); - } - } - - protected final void await(CountDownLatch latch) { - await(latch, this.awaitTimeout); - } - - protected final void await(CountDownLatch latch, long timeout) { - await(latch, timeout, TimeUnit.MILLISECONDS); - } - - protected final void await(CountDownLatch latch, long timeout, TimeUnit timeUnit) { - try { - latch.await(timeout, timeUnit); - } - catch (InterruptedException e) { - // - } - } - -} diff --git a/src/main/java/org/vertx/java/test/junit/support/package-info.java b/src/main/java/org/vertx/java/test/junit/support/package-info.java deleted file mode 100644 index aa82c25..0000000 --- a/src/main/java/org/vertx/java/test/junit/support/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author swilliams - * - */ -package org.vertx.java.test.junit.support; \ No newline at end of file From ce5d89bb5316ea95bd774e9300b98796eab59a7e Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Mon, 3 Sep 2012 15:00:20 +0100 Subject: [PATCH 09/18] finish removing old code --- .../test/junit/VertxExternalResource.java | 32 ++++++++++++++++++- .../java/test/junit/ModuleMethodRuleTest.java | 3 +- .../java/test/junit/ModuleRunWithTest.java | 3 +- .../vertx/java/test/junit/SimpleEchoTest.java | 7 ++-- .../test/junit/VerticleMethodRuleTest.java | 4 +-- .../java/test/junit/VerticleRunWithTest.java | 3 +- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java index 7c80711..55fe926 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java +++ b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java @@ -1,26 +1,56 @@ package org.vertx.java.test.junit; +import java.io.File; +import java.lang.annotation.Annotation; +import java.util.Map; + import org.junit.rules.ExternalResource; import org.junit.runner.Description; import org.junit.runners.model.Statement; +import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.utils.DeploymentUtils; public class VertxExternalResource extends ExternalResource { + private File modDir; + + private VerticleManager manager; + + private Description description; + + private Map methodDeployments; + + public VertxExternalResource(VerticleManager manager) { + this.manager = manager; + } + @Override public Statement apply(Statement base, Description description) { + + this.description = description; + + String vertxMods = System.getProperty("vertx.mods"); + this.modDir = new File(vertxMods); + if (!modDir.exists()) { + modDir.mkdirs(); + } + System.out.printf("VertxExternalResource.apply(%s,%s)%n", base, description); return super.apply(base, description); } @Override protected void before() throws Throwable { - System.out.printf("VertxExternalResource.before()%n"); + this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description); super.before(); } @Override protected void after() { System.out.printf("VertxExternalResource.after()%n"); + if (methodDeployments.size() > 0) { + DeploymentUtils.undeploy(manager, methodDeployments); + } super.after(); } diff --git a/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java b/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java index 44bf4b7..7298fd2 100644 --- a/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java +++ b/src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java @@ -28,7 +28,6 @@ import org.vertx.java.deploy.impl.VerticleManager; import org.vertx.java.test.TestModule; import org.vertx.java.test.TestModules; -import org.vertx.java.test.junit.old.VertxTestRule; import org.vertx.java.test.utils.QueueReplyHandler; @@ -43,7 +42,7 @@ public class ModuleMethodRuleTest { private final VerticleManager manager = new VerticleManager(vertx); @Rule - public VertxTestRule rule = new VertxTestRule(manager); + public VertxExternalResource rule = new VertxExternalResource(manager); private long timeout = 10L; diff --git a/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java b/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java index 77dfc0f..d774d18 100644 --- a/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java +++ b/src/test/java/org/vertx/java/test/junit/ModuleRunWithTest.java @@ -26,7 +26,6 @@ import org.vertx.java.test.TestModule; import org.vertx.java.test.TestModules; import org.vertx.java.test.VertxTestBase; -import org.vertx.java.test.junit.old.VertxConfigurationJUnit4Runner; import org.vertx.java.test.utils.QueueReplyHandler; @@ -34,7 +33,7 @@ * @author swilliams * */ -@RunWith(VertxConfigurationJUnit4Runner.class) +@RunWith(VertxJUnit4ClassRunner.class) @TestModules({ @TestModule(name="test.echo0-v1.0") }) diff --git a/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java index b642c9c..aaf10a8 100644 --- a/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java +++ b/src/test/java/org/vertx/java/test/junit/SimpleEchoTest.java @@ -25,8 +25,7 @@ import org.vertx.java.core.Handler; import org.vertx.java.core.Vertx; import org.vertx.java.core.eventbus.Message; -import org.vertx.java.test.junit.old.VertxConfigurationJUnit4Runner; -import org.vertx.java.test.junit.old.VertxSupport; +import org.vertx.java.test.VertxAware; import org.vertx.java.test.utils.QueueReplyHandler; @@ -34,8 +33,8 @@ * @author swilliams * */ -@RunWith(VertxConfigurationJUnit4Runner.class) -public class SimpleEchoTest implements VertxSupport { +@RunWith(VertxJUnit4ClassRunner.class) +public class SimpleEchoTest implements VertxAware { private static final String QUESTION = "Hello World"; diff --git a/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java b/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java index 5c9438c..d3a5afd 100644 --- a/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java +++ b/src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java @@ -28,10 +28,8 @@ import org.vertx.java.deploy.impl.VerticleManager; import org.vertx.java.test.TestVerticle; import org.vertx.java.test.TestVerticles; -import org.vertx.java.test.junit.old.VertxTestRule; import org.vertx.java.test.utils.QueueReplyHandler; - /** * @author swilliams * @@ -43,7 +41,7 @@ public class VerticleMethodRuleTest { private final VerticleManager manager = new VerticleManager(vertx); @Rule - public VertxTestRule rule = new VertxTestRule(manager); + public VertxExternalResource rule = new VertxExternalResource(manager); private long timeout = 10L; diff --git a/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java b/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java index d75444d..bb77374 100644 --- a/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java +++ b/src/test/java/org/vertx/java/test/junit/VerticleRunWithTest.java @@ -26,7 +26,6 @@ import org.vertx.java.test.TestVerticle; import org.vertx.java.test.TestVerticles; import org.vertx.java.test.VertxTestBase; -import org.vertx.java.test.junit.old.VertxConfigurationJUnit4Runner; import org.vertx.java.test.utils.QueueReplyHandler; @@ -34,7 +33,7 @@ * @author swilliams * */ -@RunWith(VertxConfigurationJUnit4Runner.class) +@RunWith(VertxJUnit4ClassRunner.class) @TestVerticle(main="test_verticle0.js") public class VerticleRunWithTest extends VertxTestBase { From f9aa038cbc10d7d2ba322867d592eba6bf6a796f Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Mon, 3 Sep 2012 15:05:19 +0100 Subject: [PATCH 10/18] fix timeout --- src/main/java/org/vertx/java/test/VertxTestBase.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/vertx/java/test/VertxTestBase.java b/src/main/java/org/vertx/java/test/VertxTestBase.java index b043735..90c75db 100644 --- a/src/main/java/org/vertx/java/test/VertxTestBase.java +++ b/src/main/java/org/vertx/java/test/VertxTestBase.java @@ -82,14 +82,13 @@ protected static final void lightSleep(long timeout) { protected final void testMessageEcho(String address, String message) throws Exception { - final long timeout = 2000L; final TimeUnit timeUnit = TimeUnit.MILLISECONDS; final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); - getVertx().eventBus().send(address, message, new QueueReplyHandler(queue, timeout, timeUnit)); + getVertx().eventBus().send(address, message, new QueueReplyHandler(queue, AWAIT_TIMEOUT, timeUnit)); try { - String answer = queue.poll(timeout, timeUnit); + String answer = queue.poll(AWAIT_TIMEOUT, timeUnit); System.out.printf("For %s Q:%s A:%s %n", address, message, message.equals(answer)); Assert.assertTrue(message.equals(answer)); From b5717399818467e53ee42a79c55aed8e9626a9bb Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Mon, 3 Sep 2012 22:18:27 +0100 Subject: [PATCH 11/18] Add more interception points and refine the detection of verticles. --- .../test/junit/JUnit4ClassRunnerAdapter.java | 29 +++++++--- .../test/junit/VertxExternalResource.java | 6 +- .../test/junit/VertxJUnit4ClassRunner.java | 45 +++++++++++++- .../java/test/junit/SimpleModuleTest.java | 58 +++++++++---------- .../java/test/junit/SimpleTestBusModTest.java | 46 +++++++++++++++ .../test/junit/SimpleTestVerticleTest.java | 46 +++++++++++++++ .../java/test/junit/SimpleVerticleTest.java | 8 +++ 7 files changed, 195 insertions(+), 43 deletions(-) create mode 100644 src/test/java/org/vertx/java/test/junit/SimpleTestBusModTest.java create mode 100644 src/test/java/org/vertx/java/test/junit/SimpleTestVerticleTest.java diff --git a/src/main/java/org/vertx/java/test/junit/JUnit4ClassRunnerAdapter.java b/src/main/java/org/vertx/java/test/junit/JUnit4ClassRunnerAdapter.java index 8867a27..9c34964 100644 --- a/src/main/java/org/vertx/java/test/junit/JUnit4ClassRunnerAdapter.java +++ b/src/main/java/org/vertx/java/test/junit/JUnit4ClassRunnerAdapter.java @@ -18,9 +18,11 @@ protected JUnit4ClassRunnerAdapter(Class klass) throws InitializationError { } @Override - protected Statement methodInvoker(FrameworkMethod method, Object target) { - injectResources(method, target); - return super.methodInvoker(method, target); + protected Object createTest() throws Exception { + beforeCreateTest(); + Object test = super.createTest(); + afterCreateTest(test); + return test; } @Override @@ -35,13 +37,20 @@ protected void before() throws Throwable { @Override protected void after() { - afterClass(); + beforeAfterClass(); super.after(); + afterClass(); } }); return rules; } + @Override + protected Statement methodInvoker(FrameworkMethod method, Object target) { + injectMethodResources(method, target); + return super.methodInvoker(method, target); + } + @Override protected List getTestRules(final Object target) { @@ -80,16 +89,22 @@ public void run(RunNotifier notifier) { protected abstract void beforeAll(); - protected abstract void injectResources(Object target); + protected abstract void beforeClass(); - protected abstract void injectResources(FrameworkMethod method, Object target); + protected abstract void beforeCreateTest(); - protected abstract void beforeClass(); + protected abstract void afterCreateTest(Object target); + + protected abstract void injectResources(Object target); + + protected abstract void injectMethodResources(FrameworkMethod method, Object target); protected abstract void beforeTest(Description description, Object target); protected abstract void afterTest(Description description, Object target); + protected abstract void beforeAfterClass(); + protected abstract void afterClass(); protected abstract void afterAll(); diff --git a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java index 55fe926..6b67b02 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java +++ b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java @@ -26,16 +26,13 @@ public VertxExternalResource(VerticleManager manager) { @Override public Statement apply(Statement base, Description description) { - - this.description = description; + this.description = description; // TODO check this is entirely safe String vertxMods = System.getProperty("vertx.mods"); this.modDir = new File(vertxMods); if (!modDir.exists()) { modDir.mkdirs(); } - - System.out.printf("VertxExternalResource.apply(%s,%s)%n", base, description); return super.apply(base, description); } @@ -47,7 +44,6 @@ protected void before() throws Throwable { @Override protected void after() { - System.out.printf("VertxExternalResource.after()%n"); if (methodDeployments.size() > 0) { DeploymentUtils.undeploy(manager, methodDeployments); } diff --git a/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java b/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java index 1ae46e0..47e4c20 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java +++ b/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java @@ -9,6 +9,8 @@ import org.junit.runners.model.InitializationError; import org.vertx.java.core.Handler; import org.vertx.java.core.impl.VertxInternal; +import org.vertx.java.deploy.Container; +import org.vertx.java.deploy.Verticle; import org.vertx.java.deploy.impl.VerticleManager; import org.vertx.java.test.VertxConfiguration; import org.vertx.java.test.utils.DeploymentUtils; @@ -28,6 +30,8 @@ public class VertxJUnit4ClassRunner extends JUnit4ClassRunnerAdapter { private Map methodDeployments; + private Verticle verticle; + public VertxJUnit4ClassRunner(Class klass) throws InitializationError { super(klass); } @@ -58,6 +62,28 @@ protected void beforeAll() { this.manager = new VerticleManager(vertx); } + @Override + protected void beforeCreateTest() { + // + } + + @Override + protected void afterCreateTest(Object target) { + + if (target instanceof Verticle) { + this.verticle = (Verticle) target; + verticle.setVertx(vertx); + verticle.setContainer(new Container(manager)); + try { + System.out.println("Starting test verticle!"); + verticle.start(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + @Override protected void injectResources(Object target) { if ((configuration != null && configuration.injectResources()) || configuration == null) { @@ -67,8 +93,8 @@ protected void injectResources(Object target) { } @Override - protected void injectResources(FrameworkMethod method, Object target) { - injectResources(target); // TODO probable double setting... test & remove + protected void injectMethodResources(FrameworkMethod method, Object target) { +// injectResources(target); // TODO probable double setting... test & remove } @Override @@ -88,6 +114,20 @@ protected void afterTest(Description description, Object target) { } } + @Override + protected void beforeAfterClass() { + System.out.println("beforeAfterClass"); + if (this.verticle != null) { + try { + System.out.println("Stopping test verticle!"); + verticle.stop(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + @Override protected void afterClass() { if (classDeployments.size() > 0) { @@ -97,6 +137,7 @@ protected void afterClass() { @Override protected void afterAll() { + manager.undeployAll(new Handler() { @Override public void handle(Void event) { diff --git a/src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java b/src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java index 318984b..13087e3 100644 --- a/src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java +++ b/src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java @@ -1,19 +1,20 @@ package org.vertx.java.test.junit; +import junit.framework.Assert; + import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.vertx.java.deploy.impl.VerticleManager; -import org.vertx.java.test.TestVerticle; +import org.vertx.java.test.TestModule; +import org.vertx.java.test.TestModules; import org.vertx.java.test.VerticleManagerAware; import org.vertx.java.test.VertxConfiguration; @RunWith(VertxJUnit4ClassRunner.class) -@VertxConfiguration -@TestVerticle(main="test_verticle0.js") +@VertxConfiguration(modsDir="src/test/mods") +@TestModule(name="test.echo0-v1.0") public class SimpleModuleTest implements VerticleManagerAware { private volatile VerticleManager verticleManager; @@ -23,51 +24,50 @@ public void setVerticleManager(VerticleManager verticleManager) { this.verticleManager = verticleManager; } - - @BeforeClass - @TestVerticle(main="test_verticle1.js") - public static void beforeClass() { - System.out.println("test.beforeClass"); - } - @Before - @TestVerticle(main="test_verticle2.js") + @TestModule(name="test.echo0-v1.0") public void before() { - System.out.println("test.before"); + System.out.printf("test.before %s %n", verticleManager.listInstances()); } @Test - @TestVerticle(main="test_verticle3.js") + @TestModules({ + @TestModule(name="test.echo0-v1.0"), + @TestModule(name="test.echo1-v1.0"), + @TestModule(name="test.echo2-v1.0") + }) public void test1() { - System.out.println("test.test1"); + int instances = verticleManager.listInstances().size(); + System.out.printf("test.test1 %s %n", verticleManager.listInstances()); + Assert.assertEquals(instances, 4); } @Test - @TestVerticle(main="test_verticle4.js") + @TestModule(name="test.echo1-v1.0", instances=3) public void test2() { - System.out.println("test.test2"); + int instances = verticleManager.listInstances().size(); + System.out.printf("test.test2 %s %n", verticleManager.listInstances()); + Assert.assertEquals(instances, 2); } @Test - @TestVerticle(main="test_verticle5.js") + @TestModule(name="test.echo2-v1.0", jsonConfig="{\"port\":8091}") public void test3() { - System.out.println("test.test3"); + int instances = verticleManager.listInstances().size(); + System.out.printf("test.test3 %s %n", verticleManager.listInstances()); + Assert.assertEquals(instances, 2); } @Test - @TestVerticle(main="test_verticle6.js") + @TestModule(name="test.echo0-v1.0") public void test4() { - System.out.println("test.test4"); + int instances = verticleManager.listInstances().size(); + System.out.printf("test.test4 %s %n", verticleManager.listInstances()); + Assert.assertEquals(instances, 2); } @After public void after() { - System.out.println("test.after"); + System.out.printf("test.after %s %n", verticleManager.listInstances()); } - - @AfterClass - public static void afterClass() { - System.out.println("test.afterClass"); - } - } diff --git a/src/test/java/org/vertx/java/test/junit/SimpleTestBusModTest.java b/src/test/java/org/vertx/java/test/junit/SimpleTestBusModTest.java new file mode 100644 index 0000000..888abb0 --- /dev/null +++ b/src/test/java/org/vertx/java/test/junit/SimpleTestBusModTest.java @@ -0,0 +1,46 @@ +package org.vertx.java.test.junit; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.vertx.java.deploy.Verticle; +import org.vertx.java.test.VertxConfiguration; + +@RunWith(VertxJUnit4ClassRunner.class) +@VertxConfiguration +public class SimpleTestBusModTest extends Verticle { + + private boolean started; + + @Override + public void start() throws Exception { + System.out.println("verticle.start"); + this.started = true; + } + + @Before + public void before() throws Exception { + System.out.println("verticle.before"); + Assert.assertTrue(started); + } + + @Test + public void test() throws Exception { + System.out.println("verticle.test"); + } + + @After + public void after() throws Exception { + System.out.println("verticle.after"); + } + + @Override + public void stop() throws Exception { + System.out.println("verticle.stop"); + this.started = false; + super.stop(); + } + +} diff --git a/src/test/java/org/vertx/java/test/junit/SimpleTestVerticleTest.java b/src/test/java/org/vertx/java/test/junit/SimpleTestVerticleTest.java new file mode 100644 index 0000000..51456d0 --- /dev/null +++ b/src/test/java/org/vertx/java/test/junit/SimpleTestVerticleTest.java @@ -0,0 +1,46 @@ +package org.vertx.java.test.junit; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.vertx.java.busmods.BusModBase; +import org.vertx.java.test.VertxConfiguration; + +@RunWith(VertxJUnit4ClassRunner.class) +@VertxConfiguration +public class SimpleTestVerticleTest extends BusModBase { + + private boolean started; + + @Override + public void start() { + System.out.println("busmod.start"); + this.started = true; + } + + @Before + public void before() throws Exception { + System.out.println("busmod.before"); + Assert.assertTrue(started); + } + + @Test + public void test() throws Exception { + System.out.println("busmod.test"); + } + + @After + public void after() throws Exception { + System.out.println("busmod.after"); + } + + @Override + public void stop() throws Exception { + System.out.println("busmod.stop"); + started = false; + super.stop(); + } + +} diff --git a/src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java b/src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java index ba42b64..d2ec845 100644 --- a/src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java +++ b/src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java @@ -49,4 +49,12 @@ public void test2() { Assert.assertEquals(instances, 2); } + @Test + @TestVerticle(main="test_verticle5.js", instances=3) + public void test3() { + int instances = verticleManager.listInstances().size(); + System.out.println("test.test3 " + instances); + Assert.assertEquals(instances, 2); + } + } From 2d33f955cda74369579f8dc62de73a0c138ce14f Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Tue, 4 Sep 2012 10:12:00 +0100 Subject: [PATCH 12/18] Add some logging, remove some sysout, add static registry helper. --- .../org/vertx/java/test/VertxTestBase.java | 1 - .../test/junit/VertxExternalResource.java | 3 + .../test/junit/VertxJUnit4ClassRunner.java | 10 +++- .../java/test/utils/DeploymentRegistry.java | 59 +++++++++++++++++++ .../java/test/utils/DeploymentUtils.java | 30 ++++++---- 5 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/vertx/java/test/utils/DeploymentRegistry.java diff --git a/src/main/java/org/vertx/java/test/VertxTestBase.java b/src/main/java/org/vertx/java/test/VertxTestBase.java index 90c75db..e65bade 100644 --- a/src/main/java/org/vertx/java/test/VertxTestBase.java +++ b/src/main/java/org/vertx/java/test/VertxTestBase.java @@ -117,7 +117,6 @@ protected final void unregisterHandlers(String... handlers) { protected final void unregisterHandlers(Iterable iterable) { for (String handler : iterable) { - System.out.printf("unregisterHandler: %s %n", handler); vertx.eventBus().unregisterHandler(handler); } } diff --git a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java index 6b67b02..899b914 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java +++ b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java @@ -8,6 +8,7 @@ import org.junit.runner.Description; import org.junit.runners.model.Statement; import org.vertx.java.deploy.impl.VerticleManager; +import org.vertx.java.test.utils.DeploymentRegistry; import org.vertx.java.test.utils.DeploymentUtils; public class VertxExternalResource extends ExternalResource { @@ -39,6 +40,7 @@ public Statement apply(Statement base, Description description) { @Override protected void before() throws Throwable { this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description); + DeploymentRegistry.register(methodDeployments); super.before(); } @@ -48,6 +50,7 @@ protected void after() { DeploymentUtils.undeploy(manager, methodDeployments); } super.after(); + DeploymentRegistry.clear(); } } diff --git a/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java b/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java index 47e4c20..2839b11 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java +++ b/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java @@ -13,6 +13,7 @@ import org.vertx.java.deploy.Verticle; import org.vertx.java.deploy.impl.VerticleManager; import org.vertx.java.test.VertxConfiguration; +import org.vertx.java.test.utils.DeploymentRegistry; import org.vertx.java.test.utils.DeploymentUtils; import org.vertx.java.test.utils.InjectionUtils; @@ -105,6 +106,7 @@ protected void beforeClass() { @Override protected void beforeTest(Description description, Object target) { this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description); + DeploymentRegistry.register(methodDeployments); } @Override @@ -112,14 +114,16 @@ protected void afterTest(Description description, Object target) { if (methodDeployments.size() > 0) { DeploymentUtils.undeploy(manager, methodDeployments); } + + // avoid leaks + DeploymentRegistry.clear(); } @Override protected void beforeAfterClass() { - System.out.println("beforeAfterClass"); + if (this.verticle != null) { try { - System.out.println("Stopping test verticle!"); verticle.stop(); } catch (Exception e) { // TODO Auto-generated catch block @@ -141,7 +145,7 @@ protected void afterAll() { manager.undeployAll(new Handler() { @Override public void handle(Void event) { - // + // TODO log this }}); } diff --git a/src/main/java/org/vertx/java/test/utils/DeploymentRegistry.java b/src/main/java/org/vertx/java/test/utils/DeploymentRegistry.java new file mode 100644 index 0000000..349e7c1 --- /dev/null +++ b/src/main/java/org/vertx/java/test/utils/DeploymentRegistry.java @@ -0,0 +1,59 @@ +package org.vertx.java.test.utils; + +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import org.vertx.java.test.TestModule; +import org.vertx.java.test.TestVerticle; + +public class DeploymentRegistry { + + private final static ThreadLocal> deployments = new ThreadLocal>() { + @Override + protected Map initialValue() { + return new HashMap(); + } + }; + + public static final void register(Map deployments) { + Set> entrySet = deployments.entrySet(); + for (Entry e : entrySet) { + String deploymentId = e.getValue(); + Annotation key = e.getKey(); + if (key instanceof TestModule) { + DeploymentRegistry.register((TestModule) key, deploymentId); + } + if (key instanceof TestVerticle) { + DeploymentRegistry.register((TestVerticle) key, deploymentId); + } + } + } + + public static final void register(TestModule module, String deploymentId) { + deployments.get().put(module.name(), deploymentId); + } + + public static final String find(TestModule module) { + return deployments.get().get(module.name()); + } + + public static final void register(TestVerticle verticle, String deploymentId) { + deployments.get().put(verticle.main(), deploymentId); + } + + public static final String find(TestVerticle module) { + return deployments.get().get(module.main()); + } + + public static final String find(String name) { + return deployments.get().get(name); + } + + public static void clear() { + deployments.remove(); + } + +} diff --git a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java index eba6cff..3ed14e9 100644 --- a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java +++ b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java @@ -15,6 +15,8 @@ import java.util.Map.Entry; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; import org.vertx.java.core.Handler; import org.vertx.java.core.json.JsonObject; @@ -24,6 +26,8 @@ public class DeploymentUtils { + private static final Logger LOG = Logger.getLogger(DeploymentUtils.class.getName()); + public static Map deployVerticles(VerticleManager manager, File modDir, Set verticles) { Map deployments = new HashMap<>(); @@ -38,7 +42,7 @@ public static Map deployVerticles(VerticleManager manager, F JsonObject config = getJsonConfig(v.jsonConfig()); URL[] urls = findVerticleURLs(v); - System.out.printf("DeploymentUtils.deployVerticle(%s)%n", v); + LOG.log(Level.FINE, "DeploymentUtils.deployVerticle(%s)%n", v); manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, handler); } @@ -66,7 +70,7 @@ public static Map deployModules(VerticleManager manager, Fil JsonObject config = getJsonConfig(m.jsonConfig()); - System.out.printf("DeploymentUtils.deployModule(%s)%n", m); + LOG.log(Level.FINE, "DeploymentUtils.deployModule(%s)%n", m); manager.deployMod(m.name(), config, m.instances(), modDir, handler); } @@ -86,15 +90,21 @@ public static void undeploy(VerticleManager manager, Map dep final CountDownLatch latch = new CountDownLatch(deployments.size()); for (final String id : deployments.values()) { - manager.undeploy(id, new Handler() { - @Override - public void handle(Void event) { - System.out.printf("DeploymentUtils.undeployed(%s)%n", id); - latch.countDown(); - } - }); + try { + manager.undeploy(id, new Handler() { + @Override + public void handle(Void event) { + System.out.printf("DeploymentUtils.undeployed(%s)%n", id); + latch.countDown(); + } + }); + + await(latch, 2000L); // FIXME this appears to hang + } + catch (IllegalArgumentException e) { + LOG.log(Level.WARNING, String.format("DeploymentUtils.undeployed(%s)%n", id), e); + } - await(latch, 2000L); // FIXME this appears to hang } } From 80528f419062bb146fb5c03476509f42d6e14010 Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Tue, 4 Sep 2012 10:12:41 +0100 Subject: [PATCH 13/18] remove whitespace --- src/main/java/org/vertx/java/test/utils/DeploymentUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java index 3ed14e9..08bb331 100644 --- a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java +++ b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java @@ -104,7 +104,6 @@ public void handle(Void event) { catch (IllegalArgumentException e) { LOG.log(Level.WARNING, String.format("DeploymentUtils.undeployed(%s)%n", id), e); } - } } From 08f118569ef3c5ed996bf45367970d5f1665d4ef Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Fri, 7 Sep 2012 13:40:55 +0100 Subject: [PATCH 14/18] Update build properties --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index a975967..f827d9c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,10 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -version=1.0 +version=1.0-SNAPSHOT group=org.vert-x modulename=vertx-junit-annotations -gradleVersion=1.0 +gradleVersion=1.1 vertxVersion=1.2.3.final rhinoVersion=1.7R4 From e13896c40a5038ee582fd25499bbc83cfaa56174 Mon Sep 17 00:00:00 2001 From: Stuart Williams Date: Thu, 13 Sep 2012 21:02:28 +0100 Subject: [PATCH 15/18] Add license file --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. From 8d80664ff683a6bb99b3038d573bf818715a6f02 Mon Sep 17 00:00:00 2001 From: Stuart Date: Fri, 23 Nov 2012 23:47:35 +0000 Subject: [PATCH 16/18] Update to vertx 1.3 API --- gradle.properties | 7 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- .../org/vertx/java/test/TestVerticle.java | 2 ++ .../vertx/java/test/VertxHandlerMapping.java | 25 +++++++++++++++++++ .../org/vertx/java/test/VertxTestBase.java | 24 +++++++++++++----- .../java/test/utils/DeploymentUtils.java | 5 +++- src/test/resources/langs.properties | 13 ++++++++++ 7 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/vertx/java/test/VertxHandlerMapping.java create mode 100644 src/test/resources/langs.properties diff --git a/gradle.properties b/gradle.properties index f827d9c..c35595f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,13 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # -version=1.0-SNAPSHOT +version=1.3-SNAPSHOT group=org.vert-x modulename=vertx-junit-annotations -gradleVersion=1.1 +gradleVersion=1.3 -vertxVersion=1.2.3.final +vertxVersion=1.3.0.final rhinoVersion=1.7R4 -springVersion=3.1.2.RELEASE junitVersion=4.10 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2589d57..dc03500 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.1-bin.zip +distributionUrl=http\://services.gradle.org/distributions/gradle-1.3-bin.zip diff --git a/src/main/java/org/vertx/java/test/TestVerticle.java b/src/main/java/org/vertx/java/test/TestVerticle.java index 242f222..06d4ddb 100644 --- a/src/main/java/org/vertx/java/test/TestVerticle.java +++ b/src/main/java/org/vertx/java/test/TestVerticle.java @@ -41,6 +41,8 @@ String jsonConfig() default "{}"; + String includes() default ""; + String[] urls() default {}; } diff --git a/src/main/java/org/vertx/java/test/VertxHandlerMapping.java b/src/main/java/org/vertx/java/test/VertxHandlerMapping.java new file mode 100644 index 0000000..85ed757 --- /dev/null +++ b/src/main/java/org/vertx/java/test/VertxHandlerMapping.java @@ -0,0 +1,25 @@ +package org.vertx.java.test; + +import org.vertx.java.core.Handler; +import org.vertx.java.core.eventbus.Message; + +public class VertxHandlerMapping> { + + private final String address; + + private final Handler handler; + + public VertxHandlerMapping(String address, Handler handler) { + this.address = address; + this.handler = handler; + } + + public String getAddress() { + return address; + } + + public Handler getHandler() { + return handler; + } + +} diff --git a/src/main/java/org/vertx/java/test/VertxTestBase.java b/src/main/java/org/vertx/java/test/VertxTestBase.java index e65bade..e90a6f4 100644 --- a/src/main/java/org/vertx/java/test/VertxTestBase.java +++ b/src/main/java/org/vertx/java/test/VertxTestBase.java @@ -16,6 +16,9 @@ package org.vertx.java.test; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -40,6 +43,9 @@ public abstract class VertxTestBase implements VertxAware, VerticleManagerAware private VerticleManager manager; + @SuppressWarnings("rawtypes") + private Map mappings = new HashMap<>(); + private static long AWAIT_TIMEOUT = 5000L; protected VertxTestBase() { @@ -99,25 +105,31 @@ protected final void testMessageEcho(String address, String message) throws Exce protected final > String registerHandler(String address, Handler handler) { final CountDownLatch latch = new CountDownLatch(1); - String handlerId = vertx.eventBus().registerHandler(address, handler, new SimpleLatchAsyncResultHandler(latch)); + vertx.eventBus().registerHandler(address, handler, new SimpleLatchAsyncResultHandler(latch)); await(latch); - return handlerId; + String id = UUID.randomUUID().toString(); + mappings.put(id, new VertxHandlerMapping(address, handler)); + return id; } protected final > String registerLocalHandler(String address, Handler handler) { final CountDownLatch latch = new CountDownLatch(1); - String handlerId = vertx.eventBus().registerLocalHandler(address, handler); + vertx.eventBus().registerLocalHandler(address, handler); await(latch); - return handlerId; + String id = UUID.randomUUID().toString(); + mappings.put(id, new VertxHandlerMapping(address, handler)); + return id; } protected final void unregisterHandlers(String... handlers) { unregisterHandlers(Arrays.asList(handlers)); } + @SuppressWarnings({ "rawtypes", "unchecked" }) protected final void unregisterHandlers(Iterable iterable) { - for (String handler : iterable) { - vertx.eventBus().unregisterHandler(handler); + for (String id : iterable) { + VertxHandlerMapping mapping = mappings.get(id); + vertx.eventBus().unregisterHandler(mapping.getAddress(), mapping.getHandler()); } } diff --git a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java index 08bb331..81429b6 100644 --- a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java +++ b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java @@ -43,7 +43,10 @@ public static Map deployVerticles(VerticleManager manager, F URL[] urls = findVerticleURLs(v); LOG.log(Level.FINE, "DeploymentUtils.deployVerticle(%s)%n", v); - manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, handler); + + // we are having to set null here which is not that clever + String includes = ("".equals(v.includes())) ? null : v.includes(); + manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, includes, handler); } await(latch); diff --git a/src/test/resources/langs.properties b/src/test/resources/langs.properties new file mode 100644 index 0000000..1cce19c --- /dev/null +++ b/src/test/resources/langs.properties @@ -0,0 +1,13 @@ +# Mapping between main file extensions and the verticle factory for the class + +java=org.vertx.java.deploy.impl.java.JavaVerticleFactory +class=org.vertx.java.deploy.impl.java.JavaVerticleFactory +js=org.vertx.java.deploy.impl.rhino.RhinoVerticleFactory +coffee=org.vertx.java.deploy.impl.rhino.RhinoVerticleFactory +rb=org.vertx.java.deploy.impl.jruby.JRubyVerticleFactory +groovy=org.vertx.groovy.deploy.impl.groovy.GroovyVerticleFactory +py=org.vertx.java.deploy.impl.jython.JythonVerticleFactory + +# Default - if none match this will be assumed + +default=org.vertx.java.deploy.impl.java.JavaVerticleFactory From ae2683b687a36a4894f46e25e1340786cfdf90d0 Mon Sep 17 00:00:00 2001 From: Stuart Date: Sat, 24 Nov 2012 00:13:00 +0000 Subject: [PATCH 17/18] add sensible timeout --- .../vertx/java/test/junit/JUnitDeploymentUtils.java | 6 +++--- .../vertx/java/test/junit/VertxExternalResource.java | 3 ++- .../vertx/java/test/junit/VertxJUnit4ClassRunner.java | 6 ++++-- .../org/vertx/java/test/utils/DeploymentUtils.java | 10 +++++----- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java b/src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java index 6a34d89..5de925f 100644 --- a/src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java +++ b/src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java @@ -22,7 +22,7 @@ public class JUnitDeploymentUtils { * @param description * @return map */ - public static Map deploy(VerticleManager manager, File modDir, Description description) { + public static Map deploy(VerticleManager manager, File modDir, Description description, long timeout) { Map deployments = new HashMap<>(); @@ -41,7 +41,7 @@ public static Map deploy(VerticleManager manager, File modDi } } - Map verticleDeployments = DeploymentUtils.deployVerticles(manager, modDir, verticles); + Map verticleDeployments = DeploymentUtils.deployVerticles(manager, modDir, verticles, timeout); deployments.putAll(verticleDeployments); // ------------------------------------------------------------------------------ @@ -59,7 +59,7 @@ public static Map deploy(VerticleManager manager, File modDi } } - Map modulesDeployments = DeploymentUtils.deployModules(manager, modDir, modules); + Map modulesDeployments = DeploymentUtils.deployModules(manager, modDir, modules, timeout); deployments.putAll(modulesDeployments); // ------------------------------------------------------------------------------ diff --git a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java index 899b914..19ace9a 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java +++ b/src/main/java/org/vertx/java/test/junit/VertxExternalResource.java @@ -39,7 +39,8 @@ public Statement apply(Statement base, Description description) { @Override protected void before() throws Throwable { - this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description); + long timeout = Long.getLong("vertx.test.timeout", 15000L); + this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description, timeout); DeploymentRegistry.register(methodDeployments); super.before(); } diff --git a/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java b/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java index 2839b11..fa45d38 100644 --- a/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java +++ b/src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java @@ -100,12 +100,14 @@ protected void injectMethodResources(FrameworkMethod method, Object target) { @Override protected void beforeClass() { - this.classDeployments = JUnitDeploymentUtils.deploy(manager, modDir, getDescription()); + long timeout = Long.getLong("vertx.test.timeout", 15000L); + this.classDeployments = JUnitDeploymentUtils.deploy(manager, modDir, getDescription(), timeout); } @Override protected void beforeTest(Description description, Object target) { - this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description); + long timeout = Long.getLong("vertx.test.timeout", 15000L); + this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description, timeout); DeploymentRegistry.register(methodDeployments); } diff --git a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java index 81429b6..b996d87 100644 --- a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java +++ b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java @@ -28,7 +28,7 @@ public class DeploymentUtils { private static final Logger LOG = Logger.getLogger(DeploymentUtils.class.getName()); - public static Map deployVerticles(VerticleManager manager, File modDir, Set verticles) { + public static Map deployVerticles(VerticleManager manager, File modDir, Set verticles, long timeout) { Map deployments = new HashMap<>(); if (verticles.size() > 0) { @@ -49,7 +49,7 @@ public static Map deployVerticles(VerticleManager manager, F manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, includes, handler); } - await(latch); + await(latch, timeout); Set> entrySet = handlers.entrySet(); for (Entry e : entrySet) { @@ -60,7 +60,7 @@ public static Map deployVerticles(VerticleManager manager, F return deployments; } - public static Map deployModules(VerticleManager manager, File modDir, Set modules) { + public static Map deployModules(VerticleManager manager, File modDir, Set modules, long timeout) { Map deployments = new HashMap<>(); if (modules.size() > 0) { @@ -77,7 +77,7 @@ public static Map deployModules(VerticleManager manager, Fil manager.deployMod(m.name(), config, m.instances(), modDir, handler); } - await(latch); + await(latch, timeout); Set> entrySet = handlers.entrySet(); for (Entry e : entrySet) { @@ -192,7 +192,7 @@ public static URL[] findVerticleURLs(TestVerticle v) { return urlSet.toArray(urls); } - public static void await(final CountDownLatch latch) { + public static void await2(final CountDownLatch latch) { try { latch.await(); } catch (InterruptedException e) { From b7515617ca5f3f1b0bf492528aa31da1155cecfe Mon Sep 17 00:00:00 2001 From: Stuart Date: Sat, 24 Nov 2012 00:23:37 +0000 Subject: [PATCH 18/18] fix timeout bug --- .../java/test/utils/DeploymentUtils.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java index b996d87..50b792c 100644 --- a/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java +++ b/src/main/java/org/vertx/java/test/utils/DeploymentUtils.java @@ -46,10 +46,16 @@ public static Map deployVerticles(VerticleManager manager, F // we are having to set null here which is not that clever String includes = ("".equals(v.includes())) ? null : v.includes(); - manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, includes, handler); + try { + manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, includes, handler); + } catch (Exception e) { + e.printStackTrace(); + latch.countDown(); + } } - await(latch, timeout); + await(latch); + // await(latch, timeout); // Eh? Set> entrySet = handlers.entrySet(); for (Entry e : entrySet) { @@ -74,10 +80,16 @@ public static Map deployModules(VerticleManager manager, Fil JsonObject config = getJsonConfig(m.jsonConfig()); LOG.log(Level.FINE, "DeploymentUtils.deployModule(%s)%n", m); - manager.deployMod(m.name(), config, m.instances(), modDir, handler); + try { + manager.deployMod(m.name(), config, m.instances(), modDir, handler); + } catch (Exception e) { + e.printStackTrace(); + latch.countDown(); + } } - await(latch, timeout); + await(latch); + // await(latch, timeout); // Eh? Set> entrySet = handlers.entrySet(); for (Entry e : entrySet) { @@ -192,7 +204,7 @@ public static URL[] findVerticleURLs(TestVerticle v) { return urlSet.toArray(urls); } - public static void await2(final CountDownLatch latch) { + public static void await(final CountDownLatch latch) { try { latch.await(); } catch (InterruptedException e) {