diff --git a/build.gradle b/build.gradle index c506520..5195ba6 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,8 @@ dependencies { testCompile( "io.vertx:testtools:$toolsVersion" ) { transitive = false } + provided "org.codehaus.groovy:groovy-all:$groovyVersion" + testCompile "io.vertx:mod-rxjava:$rxVersion" } test { @@ -68,6 +70,7 @@ Please edit the details below. */ def configurePom( def pom ) { pom.project { + name 'mod-jdbc-persistor' description 'JDBC Persistor Module for Vert.x' inceptionYear '2012' packaging 'zip' diff --git a/gradle.properties b/gradle.properties index 2b93f06..1694b22 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ modowner=com.bloidonia modname=mod-jdbc-persistor # Your module version -version=2.0.0-beta2 +version=2.0.0-beta5 # The test timeout in seconds testtimeout=300 @@ -26,7 +26,7 @@ groovyVersion=2.1.3 gradleVersion=1.6 # The version of Vert.x -vertxVersion=2.0.0-beta2 +vertxVersion=2.0.0-beta5 # The version of Vert.x test tools toolsVersion=2.0.0-beta1 @@ -34,7 +34,10 @@ toolsVersion=2.0.0-beta1 # The version of JUnit junitVersion=4.10 -c3p0Version=0.9.5-pre2 +c3p0Version=0.9.5-pre3 dbutilsVersion=1.5 hsqldbVersion=2.2.9 metricsVersion=3.0.0-BETA1 + +rxVersion=1.0.0-beta1-SNAPSHOT +groovyVersion=2.1.4 \ No newline at end of file diff --git a/src/main/resources/mod.json b/src/main/resources/mod.json index d1d66b3..c53de15 100644 --- a/src/main/resources/mod.json +++ b/src/main/resources/mod.json @@ -1,5 +1,11 @@ { "main": "com.bloidonia.vertx.mods.JdbcProcessor", "multi-threaded": true, - "worker": true + "worker": true, + + "description":"JDBC persistor module for Vert.x", + "licenses": ["The Apache Software License Version 2.0"], + "author": "Tim Yates", + "keywords": ["jdbc", "database", "databases", "persistence", "json", "sql"], + "homepage": "https://github.com/timyates/mod-jdbc-persistor" } \ No newline at end of file diff --git a/src/test/java/com/bloidonia/vertx/mods/integration/JavaBasedRxTest.java b/src/test/java/com/bloidonia/vertx/mods/integration/JavaBasedRxTest.java new file mode 100644 index 0000000..6ee23a8 --- /dev/null +++ b/src/test/java/com/bloidonia/vertx/mods/integration/JavaBasedRxTest.java @@ -0,0 +1,162 @@ +package com.bloidonia.vertx.mods.integration ; + +import io.vertx.rxcore.java.eventbus.RxEventBus ; +import io.vertx.rxcore.java.eventbus.RxMessage ; + +import java.util.ArrayList ; + +import org.junit.Test ; + +import org.vertx.java.core.AsyncResult ; +import org.vertx.java.core.AsyncResultHandler ; +import org.vertx.java.core.json.JsonObject ; +import org.vertx.java.core.json.JsonArray ; +import org.vertx.testtools.TestVerticle ; + +import rx.Observable ; +import rx.util.functions.Action1 ; +import rx.util.functions.Func1 ; + +import static org.vertx.testtools.VertxAssert.* ; + +public class JavaBasedRxTest extends TestVerticle { + + private RxEventBus rxEventBus ; + + private JsonObject createMsg, insertMsg, selectMsg, dropMsg ; + + private void appReady() { + super.start() ; + } + + public void start() { + rxEventBus = new RxEventBus( vertx.eventBus() ) ; + JsonObject config = new JsonObject() {{ + putString( "address", "test.persistor" ) ; + putString( "url", "jdbc:hsqldb:mem:testdb?shutdown=true" ) ; + }} ; + + container.deployModule(System.getProperty("vertx.modulename"), config, 1, new AsyncResultHandler() { + @Override + public void handle(AsyncResult event1) { + createMsg = new JsonObject() {{ + putString( "action", "execute" ) ; + putString( "stmt", "CREATE TABLE IF NOT EXISTS test ( id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) NOT NULL, name VARCHAR(80), age INTEGER, CONSTRAINT testid PRIMARY KEY ( id ) )" ) ; + }} ; + insertMsg = new JsonObject() {{ + putString( "action", "insert" ) ; + putString( "stmt", "INSERT INTO test ( name, age ) VALUES ( ?, ? )" ) ; + putArray( "values", new JsonArray( new ArrayList() {{ + add( new ArrayList() {{ add( "tim" ) ; add( 65 ) ; }} ) ; + add( new ArrayList() {{ add( "dave" ) ; add( 29 ) ; }} ) ; + add( new ArrayList() {{ add( "mike" ) ; add( 42 ) ; }} ) ; + }} ) ) ; + }} ; + selectMsg = new JsonObject() {{ + putString( "action", "select" ) ; + putString( "stmt", "SELECT * FROM test ORDER BY age ASC" ) ; + }} ; + dropMsg = new JsonObject() {{ + putString( "action", "execute" ) ; + putString( "stmt", "DROP TABLE test" ) ; + }} ; + appReady() ; + } + } ) ; + } + + @Test + public void testCreateInsertSelectAndDropMapMany() { + rxEventBus.send( "test.persistor", createMsg ) + .mapMany( new Func1, Observable>>() { + @Override + public Observable> call(RxMessage message) { + assertEquals( message.body().getString( "status" ), "ok" ) ; + return rxEventBus.send( "test.persistor", insertMsg ) ; + } + } ) + .mapMany( new Func1, Observable>>() { + @Override + public Observable> call(RxMessage message) { + assertEquals( message.body().getString( "status" ), "ok" ) ; + JsonArray result = message.body().getArray( "result" ) ; + assertEquals( ((JsonObject)result.get( 0 )).getNumber( "ID" ), 1 ) ; + assertEquals( ((JsonObject)result.get( 1 )).getNumber( "ID" ), 2 ) ; + assertEquals( ((JsonObject)result.get( 2 )).getNumber( "ID" ), 3 ) ; + return rxEventBus.send( "test.persistor", selectMsg ) ; + } + } ) + .mapMany( new Func1, Observable>>() { + @Override + public Observable> call(RxMessage message) { + assertEquals( message.body().getString( "status" ), "ok" ) ; + JsonArray result = message.body().getArray( "result" ) ; + assertEquals( ((JsonObject)result.get( 0 )).getNumber( "AGE" ), 29 ) ; + assertEquals( ((JsonObject)result.get( 1 )).getNumber( "AGE" ), 42 ) ; + assertEquals( ((JsonObject)result.get( 2 )).getNumber( "AGE" ), 65 ) ; + return rxEventBus.send( "test.persistor", dropMsg ) ; + } + } ) + .subscribe( new Action1>() { + @Override + public void call( RxMessage message ) { + assertEquals( message.body().getString( "status" ), "ok" ) ; + testComplete() ; + } + } ) ; + } + + @Test + public void testCreateInsertSelectAndDrop() { + // Last subscription in the chain; drop the table + final Action1> dropSubscription = new Action1>() { + @Override + public void call( RxMessage message ) { + assertEquals( message.body().getString( "status" ), "ok" ) ; + testComplete() ; + } + } ; + + // Thirdly we select the data from the table + final Action1> selectSubscription = new Action1>() { + @Override + public void call( RxMessage message ) { + JsonArray result = message.body().getArray( "result" ) ; + assertEquals( ((JsonObject)result.get( 0 )).getNumber( "AGE" ), 29 ) ; + assertEquals( ((JsonObject)result.get( 1 )).getNumber( "AGE" ), 42 ) ; + assertEquals( ((JsonObject)result.get( 2 )).getNumber( "AGE" ), 65 ) ; + rxEventBus.send( "test.persistor", dropMsg ).subscribe( dropSubscription ) ; + } + } ; + + // Secondly we insert some data + final Action1> insertSubscription = new Action1>() { + @Override + public void call( RxMessage message ) { + JsonArray result = message.body().getArray( "result" ) ; + assertEquals( ((JsonObject)result.get( 0 )).getNumber( "ID" ), 1 ) ; + assertEquals( ((JsonObject)result.get( 1 )).getNumber( "ID" ), 2 ) ; + assertEquals( ((JsonObject)result.get( 2 )).getNumber( "ID" ), 3 ) ; + rxEventBus.send( "test.persistor", selectMsg ).subscribe( selectSubscription ) ; + } + } ; + + // Initially, we create the table + final Action1> createSubscription = new Action1>() { + @Override + public void call( RxMessage message ) { + assertEquals( message.body().getString( "status" ), "ok" ) ; + rxEventBus.send( "test.persistor", insertMsg ).subscribe( insertSubscription ) ; + } + } ; + + // Kick off the chain, and subscribe + final JsonObject createMsg = new JsonObject() {{ + putString( "action", "execute" ) ; + putString( "stmt", "CREATE TABLE IF NOT EXISTS test ( id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1) NOT NULL, name VARCHAR(80), age INTEGER, CONSTRAINT testid PRIMARY KEY ( id ) )" ) ; + }} ; + + final Observable> create = rxEventBus.send( "test.persistor", createMsg ) ; + create.subscribe( createSubscription ) ; + } +} \ No newline at end of file diff --git a/src/test/resources/integration_tests/javascript/test_client.js b/src/test/resources/integration_tests/javascript/test_client.js index ab84138..ec81086 100644 --- a/src/test/resources/integration_tests/javascript/test_client.js +++ b/src/test/resources/integration_tests/javascript/test_client.js @@ -14,13 +14,12 @@ * limitations under the License. */ -var container = require( "container" ) ; +var container = require( "vertx/container" ) ; +var eb = require( "vertx/event_bus" ) ; var vertx = require( "vertx" ) ; var vertxTests = require( "vertx_tests" ) ; var vassert = require( "vertx_assert" ) ; -var eb = vertx.eventBus; - var script = this ; var persistorConfig = { address: 'test.persistor', url: 'jdbc:hsqldb:mem:testdb?shutdown=true' } java.lang.System.out.println( persistorConfig.url ) ;