Skip to content

Commit e12f36f

Browse files
committed
added file handles test (thanks to Jochen Bedersdorfer!)
1 parent 16619ad commit e12f36f

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package io.vertx.asyncsql.test
2+
3+
import scala.collection.JavaConversions.iterableAsScalaIterable
4+
import scala.concurrent.Future
5+
import org.vertx.scala.core.json.{ Json, JsonArray }
6+
import org.vertx.testtools.VertxAssert._
7+
import scala.concurrent.Promise
8+
import org.vertx.scala.testtools.TestVerticle
9+
import org.vertx.scala.core.AsyncResult
10+
import org.vertx.scala.core.eventbus.Message
11+
import org.vertx.java.core.json.JsonObject
12+
import org.junit.Test
13+
14+
class FileHandlesTests extends TestVerticle {
15+
16+
val config = Json.obj(
17+
"address" -> "backend",
18+
"connection" -> "PostgreSQL",
19+
"host" -> "localhost",
20+
"port" -> 5432,
21+
"username" -> "vertx",
22+
"password" -> "test",
23+
"database" -> "testdb")
24+
25+
val expected = 10000
26+
var count = 0
27+
var startedAt: Long = 0
28+
29+
override def asyncBefore(): Future[Unit] = {
30+
startedAt = System.currentTimeMillis()
31+
32+
val p = Promise[Unit]
33+
container.deployModule(System.getProperty("vertx.modulename"), config, 1, { deploymentID: AsyncResult[String] =>
34+
if (deploymentID.failed()) {
35+
logger.info(deploymentID.cause())
36+
p.failure(deploymentID.cause())
37+
}
38+
assertTrue("deploymentID should not be null", deploymentID.succeeded())
39+
40+
p.success()
41+
})
42+
p.future
43+
}
44+
45+
def sendEvent(): Unit = {
46+
vertx.eventBus.send("query.me", "select '' || count(*) from pg_tables;", { event: Message[String] =>
47+
count += 1
48+
if (count == expected) {
49+
logger.info(s"Received ${count} messages in ${System.currentTimeMillis() - startedAt}")
50+
testComplete()
51+
}
52+
})
53+
}
54+
55+
@Test
56+
def filehandleTest(): Unit = {
57+
vertx.eventBus.registerHandler("query.me", { msg: Message[String] =>
58+
val json = Json.obj(
59+
"action" -> "raw",
60+
"command" -> msg.body())
61+
62+
vertx.eventBus.send("backend", json, { dbMsg: Message[JsonObject] =>
63+
val result = dbMsg.body()
64+
msg.reply(result.getArray("results").get[JsonArray](0).get(0).toString());
65+
})
66+
})
67+
68+
logger.info(s"Sending ${expected} times.")
69+
for (i <- 0 until expected) sendEvent()
70+
}
71+
}

0 commit comments

Comments
 (0)