mirror of
https://github.com/corda/corda.git
synced 2025-06-17 22:58:19 +00:00
Provide an API to register callback on app shutdown (#2402)
Provide an API to register callback on app shutdown.
This commit is contained in:
@ -31,13 +31,6 @@ import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.streams.toList
|
||||
|
||||
|
||||
private fun checkQuasarAgent() {
|
||||
if (!(ManagementFactory.getRuntimeMXBean().inputArguments.any { it.contains("quasar") })) {
|
||||
throw IllegalStateException("No quasar agent")
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Run these locally")
|
||||
class NodePerformanceTests {
|
||||
@StartableByRPC
|
||||
@ -52,11 +45,6 @@ class NodePerformanceTests {
|
||||
val averageMs: Double
|
||||
)
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
checkQuasarAgent()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `empty flow per second`() {
|
||||
driver(startNodesInProcess = true) {
|
||||
|
@ -0,0 +1,48 @@
|
||||
package net.corda.node
|
||||
|
||||
import net.corda.core.node.ServiceHub
|
||||
import net.corda.core.node.services.CordaService
|
||||
import net.corda.core.serialization.SingletonSerializeAsToken
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.testing.DUMMY_BANK_A_NAME
|
||||
import net.corda.testing.driver.driver
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class NodeUnloadHandlerTests {
|
||||
|
||||
companion object {
|
||||
val latch = CountDownLatch(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should be able to register run on stop lambda`() {
|
||||
driver(startNodesInProcess = true, extraCordappPackagesToScan = listOf("net.corda.node"), isDebug = true) {
|
||||
startNode(providedName = DUMMY_BANK_A_NAME).getOrThrow()
|
||||
// just want to fall off the end of this for the mo...
|
||||
}
|
||||
Assert.assertTrue("Timed out waiting for AbstractNode to invoke the test service shutdown callback",latch.await(30, TimeUnit.SECONDS))
|
||||
}
|
||||
|
||||
@CordaService
|
||||
class RunOnStopTestService(serviceHub: ServiceHub) : SingletonSerializeAsToken() {
|
||||
|
||||
companion object {
|
||||
private val log = contextLogger()
|
||||
}
|
||||
|
||||
init {
|
||||
serviceHub.registerUnloadHandler(this::shutdown)
|
||||
}
|
||||
|
||||
fun shutdown() {
|
||||
log.info("shutting down")
|
||||
latch.countDown()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -804,6 +804,11 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
||||
}
|
||||
|
||||
override fun jdbcSession(): Connection = database.createSession()
|
||||
|
||||
// allows services to register handlers to be informed when the node stop method is called
|
||||
override fun registerUnloadHandler(handler: () -> Unit) {
|
||||
runOnStop += handler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user