diff --git a/build.gradle b/build.gradle index 53ebb57..36ffe5f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,155 +1,99 @@ -import org.vertx.java.platform.PlatformLocator -import org.vertx.java.core.Handler +apply from: "gradle/setup.gradle" +apply from: "gradle/vertx.gradle" /* - * Copyright 2013 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. - */ +Usage: -apply from: "gradle/maven.gradle" +./gradlew task_name -apply plugin: 'java' -apply plugin: 'groovy' -apply plugin: 'idea' -apply plugin: 'eclipse' +(or gradlew.bat task_name if you have the misfortune to have to use Windows) -group = groupname -archivesBaseName = artifact +If no task name is specified then the default task 'assemble' is run -defaultTasks = ['assemble'] +Task names are: -sourceCompatibility = '1.7' -targetCompatibility = '1.7' +idea - generate a skeleton IntelliJ IDEA project -// We don't produce a jar -jar.enabled = false -assert configurations.archives.artifacts.removeAll { it.file == jar.archivePath } +eclipse - generate a skeleton Eclipse IDE project -configurations { - provided - testCompile.extendsFrom provided -} +assemble - builds the outputs, by default this is the module zip file. It can also include a jar file if produceJar + in gradle.properties is set to true. Outputs are created in build/libs. + if pullInDeps in gradle.properties is set to 'true' then the modules dependencies will be + automatically pulled into a nested mods directory inside the module during the build -repositories { - mavenLocal() - maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } - mavenCentral() -} +copyMod - builds and copies the module to the local 'mods' directory so you can execute vertx runmod (etc) + directly from the command line -dependencies { - provided "io.vertx:vertx-core:$vertxVersion" - provided "io.vertx:vertx-platform:$vertxVersion" - compile "c3p0:c3p0:$c3p0Version" - compile "commons-dbutils:commons-dbutils:$dbutilsVersion" - testCompile "org.hsqldb:hsqldb:$hsqldbVersion" - testCompile "junit:junit:$junitVersion" - testCompile( "io.vertx:testtools:$toolsVersion" ) { - transitive = false - } -} - -// This sets up the classpath for -buildscript { +modZip - creates the module zip into build/libs - repositories { - mavenLocal() - maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } - mavenCentral() - } +clean - cleans everything up - dependencies { - classpath "io.vertx:vertx-core:$vertxVersion" - classpath "io.vertx:vertx-platform:$vertxVersion" - } -} +test - runs the tests. An nice html test report is created in build/reports/tests (index.html) -sourceSets { - main { - compileClasspath = compileClasspath + configurations.provided - } -} +runMod - runs the module. This is similar to executing vertx runmod from the command line except that it does + not use the version of Vert.x installed and on the PATH to run it. Instead it uses the version of Vert.x + that the module was compiled and tested against. -task copyMod( type:Copy, dependsOn: 'classes', description: 'Assemble the module into the local mods directory' ) { - into "mods/maven:$groupname:$artifact:$version" - from compileJava - from 'src/main/resources' - into( 'lib' ) { - from configurations.compile - } -} +pullInDeps - pulls in all dependencies of the module into a nested module directory -task modZip( type: Zip, dependsOn: 'pullInDeps', description: 'Package the module .zip file') { - group = 'vert.x' - description = "Assembles a vert.x module" - destinationDir = project.file('build/libs') - archiveName = "${artifact}-${version}" + ".zip" - from copyMod -} +uploadArchives - upload the module zip file (and jar if one has been created) to Nexus. You will need to + configure sonatypeUsername and sonatypePassword in ~/.gradle/gradle.properties. -artifacts { - archives modZip -} +install - install any jars produced to the local Maven repository (.m2) -task cleanModsDir(type: Delete) { - delete 'mods' -} + */ -clean { - dependsOn cleanModsDir +dependencies { + compile "c3p0:c3p0:$c3p0Version" + compile "commons-dbutils:commons-dbutils:$dbutilsVersion" + testCompile "org.hsqldb:hsqldb:$hsqldbVersion" + testCompile "junit:junit:$junitVersion" + testCompile( "io.vertx:testtools:$toolsVersion" ) { + transitive = false + } } test { - dependsOn copyMod - // Remove any classpath entries for the module classes and resources- these must be picked up using the module classloader from - // inside the module, not from the system classpath - classpath -= sourceSets.main.output - classpath -= configurations.compile + /* Configure which tests are included + include 'org/foo/**' + exclude 'org/boo/**' + */ -// classpath.each { -// File file -> -// println file.absolutePath -// } - - // Make sure tests are always run! - outputs.upToDateWhen { false } - - systemProperty 'vertx.test.timeout', 15 - systemProperty 'vertx.version', "$project.version" - systemProperty 'vertx.modulename', "maven:$groupname:$artifact:$version" +} - // Show output - testLogging.showStandardStreams = true +/* +If you're uploading stuff to Maven, Gradle needs to generate a POM. +Please edit the details below. + */ +def configurePom(def pom) { + pom.project { + description 'MongoDB Persistor Module for Vert.x' + inceptionYear '2012' + packaging 'zip' + url 'https://github.com/vert-x/mod-mongo-persistor' + + developers { + developer { + id 'purplefox' + name 'Tim Fox' + // email 'developer email' + } + } - testLogging { exceptionFormat "full" } -} + scm { + url 'https://github.com/vert-x/mod-mongo-persistor' + } -task runMod(dependsOn: copyMod, description: 'Run the module using all the build dependencies (not using installed vertx') << { - def pm = PlatformLocator.factory.createPlatformManager() - pm.deployModule("maven:$groupname:$artifact:$version", null, 1, new Handler() { - public void handle(String deploymentID) { - System.out.println("CTRL-C to stop server") + licenses { + license { + name 'The Apache Software License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution 'repo' + } } - }); - Thread.sleep(Long.MAX_VALUE); -} -task pullInDeps(dependsOn: copyMod, description: 'Pull in all the module dependencies for the module into the nested mods directory') << { - if (pullInDeps == 'true') { - def pm = PlatformLocator.factory.createPlatformManager() - def modName = "maven:$groupname:$artifact:$version" - System.out.println("Pulling in dependencies for module " + modName + " Please wait") - pm.pullInDependencies(modName) - System.out.println("Dependencies pulled into mods directory of module") + properties { + setProperty('project.build.sourceEncoding', 'UTF8') + } } } diff --git a/gradle.properties b/gradle.properties index b5c47a2..9e04f7f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,11 @@ -groupname=com.bloidonia -artifact=mod-jdbc-persistor -version=2.0.0-SNAPSHOT - # Set to true if you want module dependencies to be pulled in and nested inside the module itself pullInDeps=false -gradleVersion=1.4 +# Set to true if you want the build to output a jar as well as a module zip file +produceJar=false + +gradleVersion=1.5 vertxVersion=2.0.0-SNAPSHOT toolsVersion=1.0.0-SNAPSHOT junitVersion=4.10 -c3p0Version=0.9.1.2 -dbutilsVersion=1.5 -hsqldbVersion=2.2.9 diff --git a/gradle/maven.gradle b/gradle/maven.gradle index 42bf893..0ddab88 100644 --- a/gradle/maven.gradle +++ b/gradle/maven.gradle @@ -40,7 +40,7 @@ uploadArchives { repositories { mavenDeployer { - setUniqueVersion(false) + // setUniqueVersion(false) configuration = configurations.archives @@ -64,36 +64,4 @@ uploadArchives { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // configuration methods -def configurePom(def pom) { - pom.project { - description 'Vert.x module that provides JavaScript support using Rhino' - inceptionYear '2013' - packaging 'jar' - url 'http://vertx.io' - - developers { - developer { - id 'purplefox' - name 'Tim Fox' - // email 'tim@tfox.org' - } - } - - scm { - url 'https://github.com/vert-x/mod-lang-rhino' - } - - 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') - } - } -} diff --git a/gradle/vertx.gradle b/gradle/vertx.gradle new file mode 100644 index 0000000..6e483a9 --- /dev/null +++ b/gradle/vertx.gradle @@ -0,0 +1,169 @@ +import org.vertx.java.core.Handler +import org.vertx.java.platform.PlatformLocator +import org.vertx.java.platform.impl.ModuleClassLoader + +/* + * 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: 'java' +apply plugin: 'groovy' +apply plugin: 'idea' +apply plugin: 'eclipse' + +// We load some extra properties from vertx.properties +loadProperties("vertx.properties") + +// We have to explicitly load props from the user home dir - on CI we set +// GRADLE_USER_HOME to a different dir to avoid problems with concurrent builds corrupting +// a shared Maven local and using Gradle wrapper concurrently +loadProperties("${System.getProperty('user.home')}/.gradle/gradle.properties") + +apply from: "gradle/maven.gradle" + +version = project.ext.version +group = modowner +archivesBaseName = modname + +defaultTasks = ['assemble'] + +sourceCompatibility = '1.7' +targetCompatibility = '1.7' + +project.ext.moduleName = "$modowner~$modname~$version" + +if (produceJar == 'false') { + jar.enabled = false + assert configurations.archives.artifacts.removeAll { it.file == jar.archivePath } +} + +configurations { + provided + testCompile.extendsFrom provided +} + +repositories { + if (System.getenv("JENKINS_HOME") == null) { + // We don't want to use mavenLocal when running on CI - mavenLocal is only useful in Gradle for + // publishing artifacts locally for development purposes - maven local is also not threadsafe when there + // are concurrent builds + mavenLocal() + } + maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } + mavenCentral() +} + +dependencies { + provided "io.vertx:vertx-core:$vertxVersion" + provided "io.vertx:vertx-platform:$vertxVersion" + testCompile "junit:junit:$junitVersion" + testCompile "io.vertx:testtools:$toolsVersion" +} + +// This sets up the classpath for the script itself +buildscript { + + repositories { + mavenLocal() + maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } + mavenCentral() + } + + dependencies { + classpath "io.vertx:vertx-core:$vertxVersion" + classpath "io.vertx:vertx-platform:$vertxVersion" + } +} + +sourceSets { + main { + compileClasspath = compileClasspath + configurations.provided + } +} + +task copyMod( type:Copy, dependsOn: 'classes', description: 'Assemble the module into the local mods directory' ) { + into "mods/$moduleName" + from compileJava + from 'src/main/resources' + into( 'lib' ) { + from configurations.compile + } +} + +task modZip( type: Zip, dependsOn: 'pullInDeps', description: 'Package the module .zip file') { + group = 'vert.x' + description = "Assembles a vert.x module" + destinationDir = project.file('build/libs') + archiveName = "${modname}-${version}" + ".zip" + from copyMod +} + +artifacts { + archives modZip +} + +task cleanModsDir(type: Delete) { + delete 'mods' +} + +clean { + dependsOn cleanModsDir +} + +test { + dependsOn copyMod + + // Make sure tests are always run! + outputs.upToDateWhen { false } + + classpath -= sourceSets.main.output + classpath -= configurations.compile + + // Show output + testLogging.showStandardStreams = true + + testLogging { exceptionFormat "full" } +} + +task runMod(dependsOn: copyMod, description: 'Run the module using all the build dependencies (not using installed vertx') << { + ModuleClassLoader.reverseLoadOrder = false + def pm = PlatformLocator.factory.createPlatformManager() + pm.deployModule(moduleName, null, 1, new Handler() { + public void handle(String deploymentID) { + System.out.println("CTRL-C to stop server") + } + }); + Thread.sleep(Long.MAX_VALUE); +} + +task pullInDeps(dependsOn: copyMod, description: 'Pull in all the module dependencies for the module into the nested mods directory') << { + if (pullInDeps == 'true') { + def pm = PlatformLocator.factory.createPlatformManager() + System.out.println("Pulling in dependencies for module " + moduleName + " Please wait") + pm.pullInDependencies(moduleName) + System.out.println("Dependencies pulled into mods directory of module") + } +} + +def loadProperties(String sourceFileName) { + def config = new Properties() + def propFile = new File(sourceFileName) + if (propFile.canRead()) { + config.load(new FileInputStream(propFile)) + for (Map.Entry property in config) { + project.ext[property.key] = property.value; + } + } +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 43dc243..66af270 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jan 28 08:12:12 GMT 2013 +#Fri Apr 05 12:52:46 BST 2013 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.4-bin.zip +distributionUrl=http\://services.gradle.org/distributions/gradle-1.5-bin.zip diff --git a/gradlew b/gradlew index 15680c7..91a7e26 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ############################################################################## ## @@ -61,9 +61,9 @@ while [ -h "$PRG" ] ; do fi done SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" +cd "`dirname \"$PRG\"`/" >&- APP_HOME="`pwd -P`" -cd "$SAVED" +cd "$SAVED" >&- CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -101,7 +101,7 @@ if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; 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" + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi @@ -161,4 +161,4 @@ function splitJvmOpts() { 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 --daemon "$@" +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat index 284db44..aec9973 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -69,7 +69,7 @@ set CMD_LINE_ARGS=%$ :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper.jar +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% diff --git a/src/main/java/com/bloidonia/vertx/mods/JdbcBusMod.java b/src/main/java/com/bloidonia/vertx/mods/JdbcBusMod.java index dbdd81a..74640a3 100644 --- a/src/main/java/com/bloidonia/vertx/mods/JdbcBusMod.java +++ b/src/main/java/com/bloidonia/vertx/mods/JdbcBusMod.java @@ -29,7 +29,7 @@ public void start() { address = getOptionalStringConfig( "address", "com.bloidonia.jdbcpersistor" ) ; maxpool = getOptionalIntConfig( "maxpool", 20 ) ; - container.deployModule( "vertx.work-queue-v1.2", config, 1, new Handler() { + container.deployModule( "io.vertx~mod-work-queue~2.0.0-SNAPSHOT", config, 1, new Handler() { public void handle( String response ) { container.deployWorkerVerticle( JdbcProcessor.class.getName(), config, maxpool, false, new Handler() { public void handle( String response ) { diff --git a/src/main/resources/mod.json b/src/main/resources/mod.json index 216d69c..63c2421 100644 --- a/src/main/resources/mod.json +++ b/src/main/resources/mod.json @@ -1,4 +1,4 @@ { "main": "com.bloidonia.vertx.mods.JdbcBusMod", - "deploys":"vertx.work-queue-v1.2" + "worker": true } \ No newline at end of file diff --git a/src/test/java/com/bloidonia/vertx/mods/integration/javascript/JavaScriptIntegrationTests.java b/src/test/java/com/bloidonia/vertx/mods/integration/javascript/JavaScriptIntegrationTests.java index 12fbb4c..c7c4862 100644 --- a/src/test/java/com/bloidonia/vertx/mods/integration/javascript/JavaScriptIntegrationTests.java +++ b/src/test/java/com/bloidonia/vertx/mods/integration/javascript/JavaScriptIntegrationTests.java @@ -25,6 +25,17 @@ @TestVerticleInfo(filenameFilter=".+\\.js", funcRegex="function[\\s]+(test[^\\s(]+)") @RunWith(ScriptClassRunner.class) public class JavaScriptIntegrationTests { + + public static int sleep( int seconds, int id ) { + try { + Thread.sleep( seconds * 1000 ) ; + return id ; + } + catch( Exception e ) { + return -id ; + } + } + @Test public void __vertxDummy() { } diff --git a/src/test/resources/integration_tests/javascript/test_client.js b/src/test/resources/integration_tests/javascript/test_client.js index 90c1e6c..e7b48e1 100644 --- a/src/test/resources/integration_tests/javascript/test_client.js +++ b/src/test/resources/integration_tests/javascript/test_client.js @@ -19,11 +19,28 @@ load("vertx_tests.js"); var eb = vertx.eventBus; +var script = this ; +var persistorConfig = { address: 'test.persistor', url: 'jdbc:hsqldb:mem:' + vertx.generateUUID() + '?shutdown=true' } +java.lang.System.out.println( persistorConfig.url ) ; +var readyAddress = persistorConfig.address + '.ready' + +var readyHandler = function( msg ) { + if( msg.status === 'ok' ) { + initTests( script ) ; + eb.unregisterHandler( readyAddress, readyHandler ) ; + } +} ; + +// This will get called by the jdbc-persistor when it has installed the work-queue +eb.registerHandler( readyAddress, readyHandler ) ; + +vertx.deployModule(java.lang.System.getProperty( 'vertx.modulename' ), persistorConfig, 1, function() {} ) ; + function test_InvalidAction() { eb.send( 'test.persistor', { action: 'blahblahblah' }, function( reply ) { - vassert.azzert( reply.status === 'error' ) ; + vassert.assertEquals( reply.status, 'error' ) ; vassert.testComplete() ; } ) } @@ -50,21 +67,21 @@ function testConcurrency() { action: 'execute', stmt: "CREATE FUNCTION sleep(seconds INTEGER, num INTEGER) RETURNS INTEGER " + "LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME " + - "'CLASSPATH:com.bloidonia.vertx.mods.tests.JavaScriptPersistorTest.sleep'" + "'CLASSPATH:com.bloidonia.vertx.mods.integration.javascript.JavaScriptIntegrationTests.sleep'" }, function( reply ) { - vassert.azzert( reply.status === 'ok', reply.message ) ; + vassert.assertEquals( reply.status, 'ok' ) ; var start = new Date() ; for( var i = 0 ; i < todo ; i++ ) { eb.send( 'test.persistor', { action: 'select', stmt: 'CALL sleep( 1, ' + ( i + 1 ) + ' )' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; + vassert.assertEquals( reply.status, 'ok' ) ; done++ ; java.lang.System.out.println( "Done " + done + " (task " + reply.result[0][ '@p0' ] + " returned ok)" ) ; if( done == todo ) { var diff = new Date().getTime() - start.getTime() ; - vassert.azzert( diff < 5000, 'Expected time delay to be less than 5s, but it was ' + ( diff / 1000 ) + 's' ) ; + vassert.assertTrue( diff < 5000 ) ; vassert.testComplete() ; } } ) ; @@ -78,8 +95,8 @@ function testSimpleSelect() { action: 'select', stmt: 'SELECT * FROM INFORMATION_SCHEMA.SYSTEM_USERS' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result != undefined ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertNotSame( reply.result, undefined ) ; vassert.testComplete() ; } ) } @@ -95,8 +112,8 @@ function testBatchedSimpleSelector() { if( reply.status === 'more-exist' ) { replier( {}, createReplyHandler() ) ; } else { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( received === num, 'Expected ' + num + 'records in total. Got ' + received + ' insead' ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( received, num, 0 ) ; vassert.testComplete() ; } } @@ -113,9 +130,9 @@ function testBatchedSimpleSelector() { stmt: 'INSERT INTO test ( name, age ) VALUES ( ?, ? )', values: values }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.updated === num, 'updated should equal ' + num + ', actually was ' + reply.updated ) ; - vassert.azzert( reply.result.length === num, 'should get back ' + num + ', primary keys' ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.updated, num, 0 ) ; + vassert.assertEquals( reply.result.length, num, 0 ) ; eb.send('test.persistor', { action: 'select', stmt: 'SELECT * FROM test ORDER BY age ASC', @@ -132,29 +149,29 @@ function testCreateAndInsert() { stmt: 'INSERT INTO test( name, age ) VALUES ( ?, ? )', values: [ [ 'tim', 65 ], [ 'dave', 29 ], [ 'mike', 42 ] ] }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result != undefined ) ; - vassert.azzert( reply.result.length == 3 ) ; - vassert.azzert( reply.result[ 0 ].ID == 1 ) ; - vassert.azzert( reply.result[ 1 ].ID == 2 ) ; - vassert.azzert( reply.result[ 2 ].ID == 3 ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertNotSame( reply.result, undefined ) ; + vassert.assertEquals( reply.result.length, 3, 0 ) ; + vassert.assertEquals( reply.result[ 0 ].ID, 1, 0 ) ; + vassert.assertEquals( reply.result[ 1 ].ID, 2, 0 ) ; + vassert.assertEquals( reply.result[ 2 ].ID, 3, 0 ) ; eb.send( 'test.persistor', { action: 'select', stmt: 'SELECT * FROM test ORDER BY age ASC' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result.length == 3 ) ; - vassert.azzert( reply.result[ 0 ].ID === 2 ) ; - vassert.azzert( reply.result[ 0 ].NAME === 'dave' ) ; - vassert.azzert( reply.result[ 0 ].AGE === 29 ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result.length, 3, 0 ) ; + vassert.assertEquals( reply.result[ 0 ].ID, 2, 0 ) ; + vassert.assertEquals( reply.result[ 0 ].NAME, 'dave' ) ; + vassert.assertEquals( reply.result[ 0 ].AGE, 29, 0 ) ; - vassert.azzert( reply.result[ 1 ].ID === 3 ) ; - vassert.azzert( reply.result[ 1 ].NAME === 'mike' ) ; - vassert.azzert( reply.result[ 1 ].AGE === 42 ) ; + vassert.assertEquals( reply.result[ 1 ].ID, 3, 0 ) ; + vassert.assertEquals( reply.result[ 1 ].NAME, 'mike' ) ; + vassert.assertEquals( reply.result[ 1 ].AGE, 42, 0 ) ; - vassert.azzert( reply.result[ 2 ].ID === 1 ) ; - vassert.azzert( reply.result[ 2 ].NAME === 'tim' ) ; - vassert.azzert( reply.result[ 2 ].AGE === 65 ) ; + vassert.assertEquals( reply.result[ 2 ].ID, 1, 0 ) ; + vassert.assertEquals( reply.result[ 2 ].NAME, 'tim' ) ; + vassert.assertEquals( reply.result[ 2 ].AGE, 65, 0 ) ; vassert.testComplete() ; } ) ; @@ -168,29 +185,30 @@ function testCreateAndInsertViaStmt() { action: 'insert', stmt: "INSERT INTO test( name, age ) VALUES ( 'tim', 65 ), ( 'dave', 29 ), ( 'mike', 42 )", }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result != undefined ) ; - vassert.azzert( reply.result.length == 3 ) ; - vassert.azzert( reply.result[ 0 ].ID != null ) ; - vassert.azzert( reply.result[ 1 ].ID != null ) ; - vassert.azzert( reply.result[ 2 ].ID != null ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertNotSame( reply.result, undefined ) ; + vassert.assertEquals( reply.result.length, 3, 0 ) ; + vassert.assertEquals( reply.result[ 0 ].ID, 1, 0 ) ; + vassert.assertEquals( reply.result[ 1 ].ID, 2, 0 ) ; + vassert.assertEquals( reply.result[ 2 ].ID, 3, 0 ) ; eb.send( 'test.persistor', { action: 'select', stmt: 'SELECT * FROM test ORDER BY age ASC' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result.length == 3, 'Expected 3 results. Got ' + reply.result.length ) ; - vassert.azzert( reply.result[ 0 ].ID != null ) ; - vassert.azzert( reply.result[ 0 ].NAME === 'dave' ) ; - vassert.azzert( reply.result[ 0 ].AGE === 29 ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result.length, 3, 0 ) ; - vassert.azzert( reply.result[ 1 ].ID != null ) ; - vassert.azzert( reply.result[ 1 ].NAME === 'mike' ) ; - vassert.azzert( reply.result[ 1 ].AGE === 42 ) ; + vassert.assertEquals( reply.result[ 0 ].ID, 2, 0 ) ; + vassert.assertEquals( reply.result[ 0 ].NAME, 'dave' ) ; + vassert.assertEquals( reply.result[ 0 ].AGE, 29, 0 ) ; - vassert.azzert( reply.result[ 2 ].ID != null ) ; - vassert.azzert( reply.result[ 2 ].NAME === 'tim' ) ; - vassert.azzert( reply.result[ 2 ].AGE === 65 ) ; + vassert.assertEquals( reply.result[ 1 ].ID, 3, 0 ) ; + vassert.assertEquals( reply.result[ 1 ].NAME, 'mike' ) ; + vassert.assertEquals( reply.result[ 1 ].AGE, 42, 0 ) ; + + vassert.assertEquals( reply.result[ 2 ].ID, 1, 0 ) ; + vassert.assertEquals( reply.result[ 2 ].NAME, 'tim' ) ; + vassert.assertEquals( reply.result[ 2 ].AGE, 65, 0 ) ; vassert.testComplete() ; } ) ; @@ -210,15 +228,15 @@ function testHammerInsert() { stmt: "INSERT INTO test( age ) VALUES ( ? )", values: valueList }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result != undefined ) ; - vassert.azzert( reply.result.length == hammerSize ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertNotSame( reply.result, undefined ) ; + vassert.assertEquals( reply.result.length, hammerSize, 0 ) ; eb.send( 'test.persistor', { action: 'select', stmt: 'SELECT COUNT( * ) AS CNT FROM test' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result[ 0 ].CNT === hammerSize ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result[ 0 ].CNT, hammerSize, 0 ) ; vassert.testComplete() ; } ) ; } ) ; @@ -240,17 +258,17 @@ function testHammerParallel() { stmt: "INSERT INTO test( age ) VALUES ( ? )", values: valueList }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result != undefined ) ; - vassert.azzert( reply.result.length == hammerSize ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertNotSame( reply.result, undefined ) ; + vassert.assertEquals( reply.result.length, hammerSize, 0 ) ; received++ ; if( received === loops ) { eb.send( 'test.persistor', { action: 'select', stmt: 'SELECT COUNT( * ) AS CNT FROM test' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result[ 0 ].CNT === hammerSize * loops, 'Expected ' + hammerSize * loops + '. Got ' + reply.result[ 0 ].CNT ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result[ 0 ].CNT, hammerSize * loops, 0 ) ; vassert.testComplete() ; } ) ; } @@ -264,25 +282,25 @@ function testRollback() { eb.send( 'test.persistor', { action: 'transaction' }, function( reply, replier ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result == undefined ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result, undefined ) ; replier( { action: 'insert', stmt: 'INSERT INTO test( name, age ) VALUES ( ?, ? )', values: [ [ 'tim', 65 ], [ 'dave', 29 ], [ 'mike', 42 ] ] }, function( reply, replier ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result.length == 3 ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result.length, 3, 0 ) ; replier( { action:'rollback' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; + vassert.assertEquals( reply.status, 'ok' ) ; eb.send( 'test.persistor', { action: 'select', stmt: 'SELECT * FROM test ORDER BY age ASC' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result.length == 0 ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result.length, 0, 0 ) ; vassert.testComplete() ; } ) ; } ) ; @@ -296,28 +314,28 @@ function testCommit() { eb.send( 'test.persistor', { action: 'transaction' }, function( reply, replier ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result == undefined ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result, undefined ) ; replier( { action: 'insert', stmt: 'INSERT INTO test( name, age ) VALUES ( ?, ? )', values: [ [ 'tim', 65 ], [ 'dave', 29 ], [ 'mike', 42 ] ] }, function( reply, replier ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result.length == 3 ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result.length, 3, 0 ) ; replier( { action:'commit' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; + vassert.assertEquals( reply.status, 'ok' ) ; eb.send( 'test.persistor', { action: 'select', stmt: 'SELECT * FROM test ORDER BY age ASC' }, function( reply ) { - vassert.azzert( reply.status === 'ok' ) ; - vassert.azzert( reply.result.length == 3 ) ; - vassert.azzert( reply.result[ 0 ].NAME == 'dave', 'Expected Dave first' ) ; - vassert.azzert( reply.result[ 1 ].NAME == 'mike', 'Mike should be second' ) ; - vassert.azzert( reply.result[ 2 ].NAME == 'tim', 'And Tim last' ) ; + vassert.assertEquals( reply.status, 'ok' ) ; + vassert.assertEquals( reply.result.length, 3, 0 ) ; + vassert.assertEquals( reply.result[ 0 ].NAME, 'dave' ) ; + vassert.assertEquals( reply.result[ 1 ].NAME, 'mike' ) ; + vassert.assertEquals( reply.result[ 2 ].NAME, 'tim' ) ; vassert.testComplete() ; } ) ; } ) ; @@ -325,27 +343,3 @@ function testCommit() { } ) ; } ) ; } - -initTests( this ) ; - -var persistorConfig = { address: 'test.persistor', url: 'jdbc:hsqldb:mem:' + vertx.generateUUID() + '?shutdown=true' } - -java.lang.System.out.println( persistorConfig.url ) ; - -var readyAddress = persistorConfig.address + '.ready' - -var readyHandler = function( msg ) { - if( msg.status === 'ok' ) { - vassert.appReady(); - eb.unregisterHandler( readyAddress, readyHandler ) ; - } -} ; - -java.lang.System.out.println( ) ; - -// This will get called by the jdbc-persistor when it has installed the work-queue -eb.registerHandler( readyAddress, readyHandler ) ; -vertx.deployModule(java.lang.System.getProperty( 'vertx.modulename' ), persistorConfig, 1, function() {} ) ; -function vertxStop() { - vassert.appStopped(); -} \ No newline at end of file diff --git a/vertx.properties b/vertx.properties new file mode 100644 index 0000000..a251ebf --- /dev/null +++ b/vertx.properties @@ -0,0 +1,15 @@ +# Your domain name +modowner=com.bloidonia + +# Your module name +modname=mod-jdbc-persistor + +# Your module version +version=2.0.0-SNAPSHOT + +# The test timeout +testtimeout=300 + +c3p0Version=0.9.1.2 +dbutilsVersion=1.5 +hsqldbVersion=2.2.9