Permalink
Browse files

added testCase

  • Loading branch information...
1 parent aa06a0b commit 344d0ff4d6901e63d68c8904be72cf853e4ed728 @leonlee committed Dec 14, 2012
File renamed without changes.
View
@@ -1,4 +1,4 @@
-allprojects {
+subprojects {
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
@@ -26,8 +26,22 @@ allprojects {
}
dependencies {
- compile group: 'org.codehaus.groovy', name: 'groovy', version: '2.0.0'
- compile 'org.vert-x:vertx-lang-groovy:1.3.0.final'
+ compile "org.vert-x:vertx-core:$vertxVsn"
+ compile "org.vert-x:vertx-platform:$vertxVsn"
+ compile "org.vert-x:vertx-lang-java:$vertxVsn"
+ compile "org.vert-x:vertx-lang-groovy:$vertxVsn"
+ compile "org.vert-x:vertx-lang-rhino:$vertxVsn"
+ compile "org.mozilla:rhino:$rhinoVsn"
+
+ groovy "org.codehaus.groovy:groovy:$groovyVsn"
+
+ compile "org.msgpack:msgpack:$msgpackVsn"
+ compile "org.slf4j:slf4j-log4j12:$slf4jVsn"
+ compile "log4j:log4j:$log4jVsn"
+ compile "com.google.code.gson:gson:$gsonVsn"
+
+ testCompile "junit:junit:$junitVsn"
+ testCompile "org.vert-x:vertx-junit-annotations:$junitAnnoVsn"
}
@@ -41,34 +55,34 @@ allprojects {
}
}
- task copyMod( type:Copy, dependsOn: 'classes' ) {
+ task copyMod(type: Copy, dependsOn: 'classes') {
into "build/mod/$modulename-v$version"
from 'build/classes/main'
from 'src/main/resources'
from 'src/main/scripts'
- into( 'lib' ) {
+ into('lib') {
from configurations.compile
- exclude {jar -> jar.file.name.startsWith('groovy') || jar.file.name.startsWith('vertx')}
+ exclude { jar -> jar.file.name.startsWith('groovy') || jar.file.name.startsWith('vertx') }
}
}
// Package into build/libs/mod.zip
- task dist( type: Zip, dependsOn: 'copyMod' ) {
+ task dist(type: Zip, dependsOn: 'copyMod') {
destinationDir = project.file('build/libs')
archiveName = "$modulename-v${version}.zip"
from project.file("build/mod")
}
- task prepareVertxTest(type: Sync, dependsOn: 'copyMod' ) {
+ task prepareVertxTest(type: Sync, dependsOn: 'copyMod') {
from 'build/mod'
into 'build/tmp/mod-test'
}
test {
// Can't have the app on the vert.x classpath
- classpath = files( classpath.findAll {
- !( it.toString() ==~ /.+build\/(classes|resources)\/main$/ )
- } )
+ classpath = files(classpath.findAll {
+ !(it.toString() ==~ /.+build\/(classes|resources)\/main$/)
+ })
// Some vert.x properties
systemProperty 'vertx.test.timeout', 15
@@ -79,7 +93,7 @@ allprojects {
testLogging.showStandardStreams = true
// No idea why we need to depend on testClasses...
- dependsOn << [ 'testClasses', 'copyMod', 'prepareVertxTest' ]
+ dependsOn << ['testClasses', 'copyMod', 'prepareVertxTest']
}
}
View
@@ -1,4 +1,12 @@
modulename=org.riderzen.ogs
version=1.0
-vertxVersion=1.3.0.final
+vertxVsn=1.3.0.final
+groovyVsn=2.0.0
+slf4jVsn=1.6.6
+log4jVsn=1.2.16
+junitAnnoVsn=1.3.0.final
+junitVsn=4.10
+msgpackVsn=0.6.7
+rhinoVsn=1.7R4
+gsonVsn=2.2.2
View
@@ -1,3 +1,3 @@
dependencies {
- compile 'org.msgpack:msgpack:0.6.7'
+ testCompile 'org.msgpack:msgpack:0.6.7'
}
@@ -1,10 +1,17 @@
package org.riderzen.ogs.protocol
+import org.json.simple.JSONArray
+import org.json.simple.JSONObject
+import org.json.simple.parser.JSONParser
import org.msgpack.MessagePack
import org.msgpack.unpacker.Unpacker
-import org.vertx.groovy.core.buffer.Buffer
-import org.vertx.groovy.core.parsetools.RecordParser
+import org.msgpack.util.json.JSON
import org.vertx.java.busmods.BusModBase
+import org.vertx.java.core.Handler
+import org.vertx.java.core.buffer.Buffer
+import org.vertx.java.core.eventbus.Message
+import org.vertx.java.core.parsetools.RecordParser
+import com.google.gson.Gson
/**
* User: Leon Lee <mail.lgq@gmail.com>
@@ -23,26 +30,27 @@ class ProtocolParser extends BusModBase {
def init() {
address = getOptionalStringConfig("address", "org.riderzen.ogs.protocol")
- eb.registerHandler(address) {Buffer message ->
- logger.debug("received message length $message.length")
-
- MessagePack messagePack = new MessagePack()
- Unpacker unpacker = messagePack.createUnpacker(new ByteArrayInputStream(message.getBytes()))
- int size = unpacker.readArrayBegin()
- String operation;
- Object[] params;
- for (i in 0..size) {
- operation = unpacker.readString()
- int pSize = unpacker.readArrayBegin()
- params = new Object[pSize]
- for (j in 0..pSize) {
- params[j] = unpacker.read(Object.class)
- }
- unpacker.readArrayEnd()
- }
- unpacker.readArrayEnd()
- logger.debug("operation: $operation, params: $params")
+ def msgHandler = { Buffer message ->
+
}
+
+ eb.registerHandler(address, new Handler<Message<Buffer>>() {
+ @Override
+ void handle(Message<Buffer> event) {
+ Buffer message = event.body
+ logger.debug("received message length ${message.length()}")
+ println("received message length ${message.length()}")
+
+ MessagePack messagePack = new MessagePack()
+ Unpacker unpacker = messagePack.createUnpacker(new ByteArrayInputStream(message.getBytes()))
+ String messagString = unpacker.read(String.class)
+ Gson gson = new Gson()
+ Object[] tokens = gson.fromJson(messagString, Object[].class)
+
+ logger.debug("message: $gson")
+ println("message: $tokens")
+ }
+ })
}
}
@@ -0,0 +1,8 @@
+log4j.rootCategory=ERROR, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n
+
+log4j.category.org.vertx=ERROR
+log4j.category.org.riderzen=DEBUG
@@ -0,0 +1,3 @@
+{
+ "main": "org.riderzen.ogs.protocol.ProtocolParser"
+}
@@ -0,0 +1,45 @@
+package org.riderzen.ogs.protocol
+
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.msgpack.MessagePack
+import org.msgpack.packer.Packer
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.vertx.java.core.buffer.Buffer
+import org.vertx.java.test.TestVerticle
+import org.vertx.java.test.VertxConfiguration
+import org.vertx.java.test.VertxTestBase
+import org.vertx.java.test.junit.VertxJUnit4ClassRunner
+
+/**
+ * User: Leon Lee <mail.lgq@gmail.com>
+ * Created On: 12-12-14
+ */
+@RunWith(VertxJUnit4ClassRunner.class)
+@VertxConfiguration
+//@TestModule(name = 'org.riderzen.ogs.protocol-v1.0')
+@TestVerticle(main = 'deployer.js')
+class ProtocolParserTest extends VertxTestBase {
+ static Logger logger = LoggerFactory.getLogger(ProtocolParserTest.class)
+ long timeout = 10L
+
+ @Before
+ def void setup() {
+ timeout = Long.parseLong(System.getProperty("vertx.test.timeout", "15"))
+ logger.debug("rock on vertx!")
+ }
+
+ @Test
+ def void testModulePP() {
+ MessagePack messagePack = new MessagePack()
+ Packer packer = messagePack.createBufferPacker()
+
+ packer.write("['hello', [1, 2, 3, 'world']]")
+
+ getVertx().eventBus().send("org.riderzen.ogs.protocol", new Buffer(packer.toByteArray()))
+
+
+ }
+}
@@ -0,0 +1,9 @@
+load('vertx.js');
+
+var config = {
+
+};
+
+vertx.deployModule('org.riderzen.ogs.protocol-v1.0', config, 1, function(id) {
+ console.log('deployed module: org.riderzen.ogs.protocol-v1.0 with id:' + id);
+});
@@ -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
@@ -0,0 +1,8 @@
+log4j.rootCategory=ERROR, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n
+
+log4j.category.org.vertx=ERROR
+log4j.category.org.riderzen=DEBUG

0 comments on commit 344d0ff

Please sign in to comment.