Skip to content
Browse files

tcp-server and protocol passed testing

  • Loading branch information...
1 parent a70c24f commit 732a0ae5b7bc1575d702fc6b96b4e4d9d30f258d @leonlee committed Dec 22, 2012
View
10 bootstrap/src/main/groovy/org/riderzen/ogs/bootStrap.groovy
@@ -1,10 +0,0 @@
-package org.riderzen.ogs
-
-/*
- * User: Leon Lee <mail.lgq@gmail.com>
- * Created On: 2012-12-05
- */
-
-def config = container.config
-
-container.deployModule("org.riderzen.ogs.tcp-server-v1.0", config)
View
31 bootstrap/src/main/resources/bootstrap.groovy
@@ -0,0 +1,31 @@
+/**
+ * User: Leon Lee <mail.lgq@gmail.com>
+ * Date: 12-12-22
+ */
+
+def logger = container.logger
+def config = container.config
+def appConfig = [
+ tcpServerConfig: [
+ id: 1
+ ],
+ protocolConfig: [
+ id: 2
+ ]
+]
+
+logger.info "starting ogs..."
+
+container.deployModule("org.riderzen.ogs.platform.tcp-server-v1.0", appConfig.tcpServerConfig, 1) {
+ container.deployModule("org.riderzen.ogs.platform.protocol-v1.0", appConfig.protocolConfig, 1) {
+ logger.info "ogs was started"
+ if (config['test']) {
+ logger.info 'deploying test mod'
+ container.deployModule('org.riderzen.ogs.platform.test-v1.0', null, 1) {
+ logger.info "starting test... ${it}"
+ vertx.sharedData.getMap('ogs')['test-mod-id'] = it
+ }
+ }
+ }
+}
+
View
3 bootstrap/src/main/resources/config.json
@@ -0,0 +1,3 @@
+{
+ "test": true
+}
View
3 bootstrap/src/main/resources/mod.json
@@ -0,0 +1,3 @@
+{
+ "main": "bootstrap.groovy"
+}
View
5 build.gradle
@@ -78,6 +78,11 @@ configure(subprojects.findAll { project -> !emptyProjects.find {it == project.na
from project.file("build/mod")
}
+ task installMod(type: Copy, dependsOn: 'copyMod') {
+ into "${System.getenv('VERTX_HOME').replaceAll('\\\\', '/')}/mods"
+ from "build/mod"
+ }
+
task prepareVertxTest(type: Sync, dependsOn: 'copyMod') {
from 'build/mod'
into 'build/tmp/mod-test'
View
2 platform/protocol/src/main/resources/log4j.properties
@@ -4,5 +4,5 @@ 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.vertx=DEBUG
log4j.category.org.riderzen=DEBUG
View
6 platform/protocol/src/main/resources/protocol-parser.groovy
@@ -18,8 +18,8 @@ def logger = container.logger
logger.info "starting protocol-parser"
-eb.registerHandler(config?.address ?: Address.appProtocol.val) { Message rawMessage ->
- Buffer buffer = rawMessage.body as Buffer
+eb.registerHandler(config?.address ?: Address.appProtocol.val) { Message upstream ->
+ def buffer = upstream.body
MessagePack msgpack = new MessagePack()
Unpacker unpacker = msgpack.createUnpacker(new ByteArrayInputStream(buffer.getBytes()))
@@ -40,6 +40,6 @@ eb.registerHandler(config?.address ?: Address.appProtocol.val) { Message rawMess
Packer packer = msgpack.createPacker(out)
packer.write((String) reply.body)
- reply.reply new Buffer(out.toByteArray())
+ upstream.reply new Buffer(out.toByteArray())
}
}
View
9 platform/tcp-server/src/main/resources/tcp-server.groovy
@@ -1,5 +1,3 @@
-import org.msgpack.MessagePack
-import org.msgpack.packer.Packer
import org.riderzen.ogs.common.Address
import org.vertx.groovy.core.buffer.Buffer
import org.vertx.groovy.core.eventbus.Message
@@ -42,15 +40,18 @@ if (backlog > 0)
server.acceptBacklog = backlog
server.connectHandler { sock ->
- sock.dataHandler { Buffer buffer ->
+ sock.dataHandler { buffer ->
logger.debug("received ${buffer.getLength()} bytes of data")
+ println("received ${buffer.getLength()} bytes of data")
eb.send(Address.appProtocol.val, buffer) { Message message ->
logger.debug "received message ${message.body}"
- sock << message.body as Buffer
+ println "received message ${message.body}"
+ sock.write(buffer as Buffer)
}
}
sock.exceptionHandler { e ->
logger.error("caught error", e)
+ println("caught error", e)
}
}.listen(port, host)
View
12 platform/tcp-server/src/test/groovy/org/riderzen/ogs/protocol/TcpServerTest.groovy
@@ -40,12 +40,12 @@ class TcpServerTest extends VertxTestBase {
@Test
def void testTcpServer() {
- getVertx().eventBus().registerHandler('ogs.protocol', new Handler<Message>() {
- @Override
- void handle(Message event) {
- logger.debug("get event" + event.body)
- }
- })
+// getVertx().eventBus().registerHandler('ogs.protocol', new Handler<Message>() {
+// @Override
+// void handle(Message event) {
+// logger.debug("get event" + event.body)
+// }
+// })
// sleep(1000000)
View
6 platform/tcp-server/src/test/resources/deployer.js
@@ -4,6 +4,6 @@ var config = {
};
-vertx.deployModule('org.riderzen.ogs.platform.tcp-server-v1.0', config, 1, function(id) {
- console.log('deployed module: org.riderzen.ogs.platform.tcp-server-v1.0 with id:' + id);
-});
+//vertx.deployModule('org.riderzen.ogs.platform.tcp-server-v1.0', config, 1, function(id) {
+// console.log('deployed module: org.riderzen.ogs.platform.tcp-server-v1.0 with id:' + id);
+//});
View
1 platform/test/gradle.properties
@@ -0,0 +1 @@
+modulename=org.riderzen.ogs.platform.test
View
3 platform/test/src/main/resources/mod.json
@@ -0,0 +1,3 @@
+{
+ "main": "test.groovy"
+}
View
49 platform/test/src/main/resources/test.groovy
@@ -0,0 +1,49 @@
+import com.google.gson.Gson
+import org.msgpack.MessagePack
+import org.msgpack.packer.Packer
+import org.msgpack.unpacker.Unpacker
+import org.vertx.groovy.core.buffer.Buffer
+
+/**
+ * User: Leon Lee <mail.lgq@gmail.com>
+ * Date: 12-12-22
+ */
+def logger = container.logger
+def eb = vertx.eventBus
+def client = vertx.createNetClient()
+
+def testAddress = 'test.tcp.protocol'
+eb.registerHandler(testAddress) { message ->
+ println "received message in $testAddress ${message.body}"
+
+ message.reply new Gson().toJson([status: 200, data: 'ok'])
+}
+
+client.connect(6543, "127.0.0.1") { socket ->
+ println "started test client"
+
+ socket.exceptionHandler { ex -> println "Failed to connect $ex" }
+
+ MessagePack msgpack = new MessagePack()
+ socket.dataHandler { buffer ->
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer.getBytes())
+ Unpacker upacker = msgpack.createUnpacker(inputStream)
+ def message = upacker.read(String.class)
+ println "Received message ${message}"
+
+ logger.debug "Received message ${message}"
+
+ def mod_id = vertx.sharedData.getMap('ogs')['test-mod-id']
+ vertx.sharedData.getMap('ogs').remove('test-mod-id')
+ container.undeployModule(mod_id) {
+ logger.info "testing was done!"
+ }
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream()
+ Packer packer = msgpack.createPacker(out)
+ packer.write(new Gson().toJson([endpoint: testAddress, params: [id: 1, name: 'test']]))
+
+ Buffer buffer = new Buffer(out.toByteArray())
+ socket << buffer
+}
View
2 settings.gradle
@@ -1,5 +1,5 @@
include 'bootstrap', 'platform', 'modules'
-include 'platform:common', 'platform:protocol', 'platform:tcp-server'
+include 'platform:common', 'platform:protocol', 'platform:tcp-server', 'platform:test'
include 'modules:sys-auth'

0 comments on commit 732a0ae

Please sign in to comment.
Something went wrong with that request. Please try again.