Skip to content

Commit

Permalink
Merge branch 'rxtests'
Browse files Browse the repository at this point in the history
* rxtests:
  Clean up imports
  Added MapMany Rx test
  Initial commit of an Rx based test
  Added extra info to mod.json for the module repo
  Added pom name
  Fixed JS require statements
  Up to beta5 and newer c3p0
  • Loading branch information
timyates committed Jun 13, 2013
2 parents 8dcd4d8 + a142205 commit 22c1146
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 7 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
Expand Down
9 changes: 6 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,15 +26,18 @@ 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

# 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
8 changes: 7 additions & 1 deletion src/main/resources/mod.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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<String>() {
@Override
public void handle(AsyncResult<String> 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<RxMessage<JsonObject>, Observable<RxMessage<JsonObject>>>() {
@Override
public Observable<RxMessage<JsonObject>> call(RxMessage<JsonObject> message) {
assertEquals( message.body().getString( "status" ), "ok" ) ;
return rxEventBus.send( "test.persistor", insertMsg ) ;
}
} )
.mapMany( new Func1<RxMessage<JsonObject>, Observable<RxMessage<JsonObject>>>() {
@Override
public Observable<RxMessage<JsonObject>> call(RxMessage<JsonObject> 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<RxMessage<JsonObject>, Observable<RxMessage<JsonObject>>>() {
@Override
public Observable<RxMessage<JsonObject>> call(RxMessage<JsonObject> 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<RxMessage<JsonObject>>() {
@Override
public void call( RxMessage<JsonObject> message ) {
assertEquals( message.body().getString( "status" ), "ok" ) ;
testComplete() ;
}
} ) ;
}

@Test
public void testCreateInsertSelectAndDrop() {
// Last subscription in the chain; drop the table
final Action1<RxMessage<JsonObject>> dropSubscription = new Action1<RxMessage<JsonObject>>() {
@Override
public void call( RxMessage<JsonObject> message ) {
assertEquals( message.body().getString( "status" ), "ok" ) ;
testComplete() ;
}
} ;

// Thirdly we select the data from the table
final Action1<RxMessage<JsonObject>> selectSubscription = new Action1<RxMessage<JsonObject>>() {
@Override
public void call( RxMessage<JsonObject> 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<RxMessage<JsonObject>> insertSubscription = new Action1<RxMessage<JsonObject>>() {
@Override
public void call( RxMessage<JsonObject> 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<RxMessage<JsonObject>> createSubscription = new Action1<RxMessage<JsonObject>>() {
@Override
public void call( RxMessage<JsonObject> 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<RxMessage<JsonObject>> create = rxEventBus.send( "test.persistor", createMsg ) ;
create.subscribe( createSubscription ) ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ;
Expand Down

0 comments on commit 22c1146

Please sign in to comment.