This is an automated email from the ASF dual-hosted git repository.
toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git
The following commit(s) were added to refs/heads/master by this push:
new 2ee0f68 Add a test that checks stopping the app
new 1c77957 Merge pull request #113 from atoulme/add_test_to_close_app
2ee0f68 is described below
commit 2ee0f68d128d5113558edb23ab33471aa88b70db
Author: Antoine Toulme <[email protected]>
AuthorDate: Thu Jul 2 17:15:02 2020 -0700
Add a test that checks stopping the app
---
.../org/apache/tuweni/relayer/RelayerAppTest.kt | 7 +++++++
.../kotlin/org/apache/tuweni/relayer/RelayerApp.kt | 20 ++++++++++++--------
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git
a/hobbits-relayer/src/integrationTest/kotlin/org/apache/tuweni/relayer/RelayerAppTest.kt
b/hobbits-relayer/src/integrationTest/kotlin/org/apache/tuweni/relayer/RelayerAppTest.kt
index a8794df..4607d8c 100644
---
a/hobbits-relayer/src/integrationTest/kotlin/org/apache/tuweni/relayer/RelayerAppTest.kt
+++
b/hobbits-relayer/src/integrationTest/kotlin/org/apache/tuweni/relayer/RelayerAppTest.kt
@@ -22,6 +22,7 @@ import org.apache.tuweni.bytes.Bytes
import org.apache.tuweni.hobbits.HobbitsTransport
import org.apache.tuweni.hobbits.Message
import org.apache.tuweni.hobbits.Protocol
+import org.apache.tuweni.hobbits.Relayer
import org.apache.tuweni.hobbits.Transport
import org.apache.tuweni.junit.VertxExtension
import org.apache.tuweni.junit.VertxInstance
@@ -55,4 +56,10 @@ class RelayerAppTest {
client1.stop()
client2.stop()
}
+
+ @Test
+ fun testClose(@VertxInstance vertx: Vertx) {
+ val relayer = Relayer(vertx, "tcp://localhost:21000",
"tcp://localhost:21001", {})
+ RelayerApp(vertx, relayer)
+ }
}
diff --git
a/hobbits-relayer/src/main/kotlin/org/apache/tuweni/relayer/RelayerApp.kt
b/hobbits-relayer/src/main/kotlin/org/apache/tuweni/relayer/RelayerApp.kt
index d94f868..a0fea43 100644
--- a/hobbits-relayer/src/main/kotlin/org/apache/tuweni/relayer/RelayerApp.kt
+++ b/hobbits-relayer/src/main/kotlin/org/apache/tuweni/relayer/RelayerApp.kt
@@ -22,13 +22,14 @@ import org.apache.tuweni.hobbits.Relayer
import org.bouncycastle.jce.provider.BouncyCastleProvider
import picocli.CommandLine
import java.security.Security
+import kotlin.system.exitProcess
/**
* Relayer application, allowing to set a relay between two hobbits endpoints.
*
* The relayer runs as a Java application using the main method defined herein.
*/
-class RelayerApp {
+class RelayerApp(val vertx: Vertx, val relayer: Relayer) {
companion object {
/**
* Runs a relayer between two hobbits endpoints.
@@ -36,18 +37,16 @@ class RelayerApp {
@JvmStatic
fun main(args: Array<String>) {
Security.addProvider(BouncyCastleProvider())
- val opts =
CommandLine.populateCommand<RelayerAppCommandlineArguments>(RelayerAppCommandlineArguments(),
*args)
+ val opts = CommandLine.populateCommand(RelayerAppCommandlineArguments(),
*args)
if (opts.help) {
CommandLine(opts).usage(System.out)
- System.exit(0)
+ exitProcess(0)
}
val vertx = Vertx.vertx()
- val relayer = Relayer(vertx, opts.bind, opts.to, {
- System.out.println(it)
- })
+ val relayer = Relayer(vertx, opts.bind, opts.to, ::println)
+ val app = RelayerApp(vertx, relayer)
Runtime.getRuntime().addShutdownHook(Thread {
- relayer.stop()
- vertx.close()
+ app.close()
})
runBlocking {
relayer.start()
@@ -55,4 +54,9 @@ class RelayerApp {
}
}
}
+
+ fun close() {
+ relayer.stop()
+ vertx.close()
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]