Skip to content

Commit 129e743

Browse files
committed
start of port to lang-scala 0.2.0-SNAPSHOT
1 parent 712131d commit 129e743

File tree

9 files changed

+36
-40
lines changed

9 files changed

+36
-40
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pullInDeps=true
2020
produceJar=false
2121

2222
# The version of the Scala module
23-
scalaLangModVersion=0.1.0
23+
scalaLangModVersion=0.2.0-SNAPSHOT
2424

2525
# The version of Scala to use
2626
scalaVersion=2.10.2

src/main/resources/langs.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
scala=io.vertx~lang-scala~0.1.0:org.vertx.scala.platform.impl.ScalaVerticleFactory
1+
scala=io.vertx~lang-scala~0.2.0-SNAPSHOT:org.vertx.scala.platform.impl.ScalaVerticleFactory
22
.scala=scala

src/main/scala/io/vertx/asyncsql/Starter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Starter extends Verticle {
2828
case "postgresql" => new PostgreSqlConnectionHandler(this, configuration)
2929
case "mysql" => new MySqlConnectionHandler(this, configuration)
3030
}
31-
vertx.eventBus.registerHandler(address)(handler)
31+
vertx.eventBus.registerHandler(address, handler)
3232

3333
logger.error("Async database module for MySQL and PostgreSQL started with config " + configuration)
3434

src/main/scala/io/vertx/asyncsql/database/ConnectionHandler.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ trait ConnectionHandler extends ScalaBusMod with VertxScalaHelpers {
2929
def transactionEnd: String = "COMMIT;"
3030
def statementDelimiter: String = ";"
3131

32+
import org.vertx.scala.core.eventbus._
3233
override def asyncReceive(msg: Message[JsonObject]) = {
33-
case "select" => select(msg.body)
34-
case "insert" => insert(msg.body)
35-
case "prepared" => prepared(msg.body)
36-
case "transaction" => transaction(msg.body)
37-
case "raw" => rawCommand(msg.body.getString("command"))
34+
case "select" => select(msg.body.asInstanceOf[JsonObject])
35+
case "insert" => insert(msg.body.asInstanceOf[JsonObject])
36+
case "prepared" => prepared(msg.body.asInstanceOf[JsonObject])
37+
case "transaction" => transaction(msg.body.asInstanceOf[JsonObject])
38+
case "raw" => rawCommand(msg.body.asInstanceOf[JsonObject].getString("command"))
3839
}
3940

4041
def close() = pool.close

src/main/scala/io/vertx/busmod/ScalaBusMod.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.vertx.asyncsql.messages.MessageHelper
1111
trait ScalaBusMod extends MessageHelper with VertxExecutionContext with (Message[JsonObject] => Unit) {
1212

1313
override def apply(msg: Message[JsonObject]) = {
14-
val action = msg.body.getString("action")
14+
val action = msg.body.asInstanceOf[JsonObject].getString("action")
1515

1616
val fut: Future[Reply] = try {
1717
if (receive(msg).isDefinedAt(action)) {

src/test/scala/io/vertx/asyncsql/test/BaseSqlTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import scala.concurrent.Future
44
import org.vertx.scala.core.json.JsonArray
55
import org.vertx.testtools.VertxAssert._
66
import org.vertx.scala.core.json.Json
7+
import org.vertx.scala.core.logging.Logger
78

89
trait BaseSqlTests { this: SqlTestVerticle =>
9-
lazy val logger = getContainer().logger()
10+
lazy val logger = new Logger(container.logger())
1011

1112
def withTable[X](tableName: String)(fn: => Future[X]) = {
1213
(for {

src/test/scala/io/vertx/asyncsql/test/BaseVertxIntegrationTest.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package io.vertx.asyncsql.test
22

3-
import org.vertx.java.core.json.JsonObject
3+
import org.vertx.scala.core.json.JsonObject
44
import scala.concurrent.Future
55
import scala.concurrent.Promise
66
import org.vertx.scala.core.Vertx
7-
import org.vertx.testtools.TestVerticle
7+
import org.vertx.scala.testtools.TestVerticle
88
import org.vertx.testtools.VertxAssert._
99
import io.vertx.helpers.VertxExecutionContext
1010
import org.vertx.scala.core.eventbus.Message
1111
import java.util.concurrent.atomic.AtomicInteger
1212
import org.vertx.scala.core.logging.Logger
1313

14-
trait BaseVertxIntegrationTest extends VertxExecutionContext { this: TestVerticle =>
14+
trait BaseVertxIntegrationTest { this: TestVerticle =>
1515
var log: Logger = null
1616

1717
val address: String
@@ -29,10 +29,10 @@ trait BaseVertxIntegrationTest extends VertxExecutionContext { this: TestVerticl
2929
protected def ebSend(q: JsonObject): Future[JsonObject] = {
3030
val p = Promise[JsonObject]
3131
log.info("sending " + q.encode() + " to " + address)
32-
Vertx(getVertx()).eventBus.send(address, q) { reply: Message[JsonObject] =>
33-
log.info("got a reply: " + reply.body.encode())
34-
p.success(reply.body)
35-
}
32+
vertx.eventBus.send(address, q, { reply: Message[JsonObject] =>
33+
log.info("got a reply: " + reply.body.asInstanceOf[JsonObject].encode())
34+
p.success(reply.body.asInstanceOf[JsonObject])
35+
})
3636
p.future
3737
}
3838

src/test/scala/io/vertx/asyncsql/test/SqlTestVerticle.scala

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ package io.vertx.asyncsql.test
22

33
import io.vertx.helpers.VertxExecutionContext
44
import scala.concurrent.Future
5-
import org.vertx.java.core.Handler
6-
import org.vertx.java.core.AsyncResult
75
import org.vertx.testtools.VertxAssert._
86
import org.vertx.scala.platform.Verticle
97
import org.junit.runner.RunWith
10-
import org.vertx.testtools.JavaClassRunner
118
import java.lang.reflect.InvocationTargetException
129
import org.vertx.java.core.logging.impl.LoggerFactory
1310
import scala.concurrent.Promise
@@ -16,32 +13,29 @@ import org.vertx.scala.core.Vertx
1613
import io.vertx.helpers.VertxScalaHelpers
1714
import org.vertx.scala.core.json._
1815
import org.vertx.scala.core.logging.Logger
16+
import org.vertx.scala.testtools.TestVerticle
17+
import org.vertx.scala.core.AsyncResult
1918

20-
abstract class SqlTestVerticle extends org.vertx.testtools.TestVerticle with BaseVertxIntegrationTest with VertxScalaHelpers {
19+
abstract class SqlTestVerticle extends TestVerticle with BaseVertxIntegrationTest with VertxScalaHelpers {
2120

22-
override def start() = {
23-
initialize()
24-
25-
log = new Logger(getContainer().logger())
26-
27-
log.info("starting module " + System.getProperty("vertx.modulename"))
28-
29-
container.deployModule(System.getProperty("vertx.modulename"), getConfig(), new Handler[AsyncResult[String]]() {
30-
override def handle(deploymentID: AsyncResult[String]) = {
31-
if (deploymentID.failed()) {
32-
log.info(deploymentID.cause())
33-
}
34-
assertTrue("deploymentID should not be null", deploymentID.succeeded())
21+
override final def before() {}
22+
override def asyncBefore(): Future[Unit] = {
23+
val p = Promise[Unit]
24+
container.deployModule(System.getProperty("vertx.modulename"), getConfig(), 1, { deploymentID: AsyncResult[String] =>
25+
if (deploymentID.failed()) {
26+
log.info(deploymentID.cause())
27+
}
28+
assertTrue("deploymentID should not be null", deploymentID.succeeded())
3529

36-
before() map { _ =>
37-
log.info("starting tests")
38-
startTests()
39-
}
30+
doBefore() map { _ =>
31+
log.info("starting tests")
32+
p.success()
4033
}
4134
})
35+
p.future
4236
}
4337

44-
def before(): Future[_] = {
38+
def doBefore(): Future[_] = {
4539
Future.successful()
4640
}
4741

src/test/scala/io/vertx/asyncsql/test/mysql/MySqlTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MySqlTest extends SqlTestVerticle with BaseSqlTests {
1010
val address = "campudus.asyncdb"
1111
val config = Json.obj("address" -> address, "connection" -> "MySQL")
1212

13-
override def before() = expectOk(raw("DROP TABLE IF EXISTS `some_test`"))
13+
override def doBefore() = expectOk(raw("DROP TABLE IF EXISTS `some_test`"))
1414
override def getConfig = config
1515

1616
override def createTableStatement(tableName: String) = """

0 commit comments

Comments
 (0)