mirror of
https://github.com/corda/corda.git
synced 2024-12-20 05:28:21 +00:00
Made NodeUnloadHandlerTests a unit test by using mock node (#3572)
This commit is contained in:
parent
7f42a9b48c
commit
ab08ce21f4
@ -1,13 +1,12 @@
|
|||||||
package net.corda.node
|
package net.corda.node.internal
|
||||||
|
|
||||||
|
import net.corda.core.internal.packageName
|
||||||
import net.corda.core.node.ServiceHub
|
import net.corda.core.node.ServiceHub
|
||||||
import net.corda.core.node.services.CordaService
|
import net.corda.core.node.services.CordaService
|
||||||
import net.corda.core.serialization.SingletonSerializeAsToken
|
import net.corda.core.serialization.SingletonSerializeAsToken
|
||||||
import net.corda.core.utilities.contextLogger
|
import net.corda.core.utilities.contextLogger
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.testing.node.internal.InternalMockNetwork
|
||||||
import net.corda.testing.core.DUMMY_BANK_A_NAME
|
import org.junit.After
|
||||||
import net.corda.testing.driver.DriverParameters
|
|
||||||
import net.corda.testing.driver.driver
|
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
@ -15,16 +14,23 @@ import java.util.concurrent.TimeUnit
|
|||||||
|
|
||||||
class NodeUnloadHandlerTests {
|
class NodeUnloadHandlerTests {
|
||||||
companion object {
|
companion object {
|
||||||
val latch = CountDownLatch(1)
|
val registerLatch = CountDownLatch(1)
|
||||||
|
val shutdownLatch = CountDownLatch(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val mockNet = InternalMockNetwork(cordappPackages = listOf(javaClass.packageName), notarySpecs = emptyList())
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun cleanUp() {
|
||||||
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `should be able to register run on stop lambda`() {
|
fun `should be able to register run on stop lambda`() {
|
||||||
driver(DriverParameters(startNodesInProcess = true, extraCordappPackagesToScan = listOf("net.corda.node"), notarySpecs = emptyList())) {
|
val node = mockNet.createNode()
|
||||||
startNode(providedName = DUMMY_BANK_A_NAME).getOrThrow()
|
registerLatch.await() // Make sure the handler is registered on node start up
|
||||||
// just want to fall off the end of this for the mo...
|
node.dispose()
|
||||||
}
|
assertTrue("Timed out waiting for AbstractNode to invoke the test service shutdown callback", shutdownLatch.await(30, TimeUnit.SECONDS))
|
||||||
assertTrue("Timed out waiting for AbstractNode to invoke the test service shutdown callback", latch.await(30, TimeUnit.SECONDS))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@ -36,11 +42,12 @@ class NodeUnloadHandlerTests {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
serviceHub.registerUnloadHandler(this::shutdown)
|
serviceHub.registerUnloadHandler(this::shutdown)
|
||||||
|
registerLatch.countDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shutdown() {
|
private fun shutdown() {
|
||||||
log.info("shutting down")
|
log.info("shutting down")
|
||||||
latch.countDown()
|
shutdownLatch.countDown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user