mirror of
https://github.com/corda/corda.git
synced 2025-02-01 08:48:09 +00:00
Retire DriverBasedTest. (#1986)
This commit is contained in:
parent
7521675ef2
commit
2e0e78e883
@ -31,11 +31,10 @@ import net.corda.node.services.Permissions.Companion.startFlow
|
||||
import net.corda.nodeapi.User
|
||||
import net.corda.testing.*
|
||||
import net.corda.testing.driver.driver
|
||||
import net.corda.testing.node.DriverBasedTest
|
||||
import org.junit.Test
|
||||
import rx.Observable
|
||||
|
||||
class NodeMonitorModelTest : DriverBasedTest() {
|
||||
class NodeMonitorModelTest {
|
||||
lateinit var aliceNode: NodeInfo
|
||||
lateinit var bobNode: NodeInfo
|
||||
lateinit var notaryParty: Party
|
||||
@ -50,8 +49,7 @@ class NodeMonitorModelTest : DriverBasedTest() {
|
||||
lateinit var vaultUpdates: Observable<Vault.Update<ContractState>>
|
||||
lateinit var networkMapUpdates: Observable<NetworkMapCache.MapChange>
|
||||
lateinit var newNode: (CordaX500Name) -> NodeInfo
|
||||
|
||||
override fun setup() = driver(extraCordappPackagesToScan = listOf("net.corda.finance")) {
|
||||
private fun setup(runTest: () -> Unit) = driver(extraCordappPackagesToScan = listOf("net.corda.finance")) {
|
||||
val cashUser = User("user1", "test", permissions = setOf(
|
||||
startFlow<CashIssueFlow>(),
|
||||
startFlow<CashPaymentFlow>(),
|
||||
@ -91,7 +89,7 @@ class NodeMonitorModelTest : DriverBasedTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `network map update`() {
|
||||
fun `network map update`() = setup {
|
||||
val charlieNode = newNode(CHARLIE.name)
|
||||
val nonServiceIdentities = aliceNode.legalIdentitiesAndCerts + bobNode.legalIdentitiesAndCerts + charlieNode.legalIdentitiesAndCerts
|
||||
networkMapUpdates.filter { it.node.legalIdentitiesAndCerts.any { it in nonServiceIdentities } }
|
||||
@ -112,7 +110,7 @@ class NodeMonitorModelTest : DriverBasedTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cash issue works end to end`() {
|
||||
fun `cash issue works end to end`() = setup {
|
||||
rpc.startFlow(::CashIssueFlow,
|
||||
Amount(100, USD),
|
||||
OpaqueBytes(ByteArray(1, { 1 })),
|
||||
@ -136,7 +134,7 @@ class NodeMonitorModelTest : DriverBasedTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cash issue and move`() {
|
||||
fun `cash issue and move`() = setup {
|
||||
val (_, issueIdentity) = rpc.startFlow(::CashIssueFlow, 100.DOLLARS, OpaqueBytes.of(1), notaryParty).returnValue.getOrThrow()
|
||||
rpc.startFlow(::CashPaymentFlow, 100.DOLLARS, bobNode.chooseIdentity()).returnValue.getOrThrow()
|
||||
|
||||
|
@ -18,20 +18,18 @@ import net.corda.nodeapi.User
|
||||
import net.corda.testing.*
|
||||
import net.corda.testing.driver.NodeHandle
|
||||
import net.corda.testing.driver.driver
|
||||
import net.corda.testing.node.DriverBasedTest
|
||||
import org.junit.Test
|
||||
import rx.Observable
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class DistributedServiceTests : DriverBasedTest() {
|
||||
class DistributedServiceTests {
|
||||
lateinit var alice: NodeHandle
|
||||
lateinit var notaries: List<NodeHandle.OutOfProcess>
|
||||
lateinit var aliceProxy: CordaRPCOps
|
||||
lateinit var raftNotaryIdentity: Party
|
||||
lateinit var notaryStateMachines: Observable<Pair<Party, StateMachineUpdate>>
|
||||
|
||||
override fun setup() = driver(extraCordappPackagesToScan = listOf("net.corda.finance.contracts")) {
|
||||
private fun setup(runTest: () -> Unit) = driver(extraCordappPackagesToScan = listOf("net.corda.finance.contracts")) {
|
||||
// Start Alice and 3 notaries in a RAFT cluster
|
||||
val clusterSize = 3
|
||||
val testUser = User("test", "test", permissions = setOf(
|
||||
@ -72,7 +70,7 @@ class DistributedServiceTests : DriverBasedTest() {
|
||||
// TODO Use a dummy distributed service rather than a Raft Notary Service as this test is only about Artemis' ability
|
||||
// to handle distributed services
|
||||
@Test
|
||||
fun `requests are distributed evenly amongst the nodes`() {
|
||||
fun `requests are distributed evenly amongst the nodes`() = setup {
|
||||
// Issue 100 pounds, then pay ourselves 50x2 pounds
|
||||
issueCash(100.POUNDS)
|
||||
|
||||
@ -100,7 +98,7 @@ class DistributedServiceTests : DriverBasedTest() {
|
||||
|
||||
// TODO This should be in RaftNotaryServiceTests
|
||||
@Test
|
||||
fun `cluster survives if a notary is killed`() {
|
||||
fun `cluster survives if a notary is killed`() = setup {
|
||||
// Issue 100 pounds, then pay ourselves 10x5 pounds
|
||||
issueCash(100.POUNDS)
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
package net.corda.testing.node
|
||||
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.testing.driver.DriverDSLExposedInterface
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
abstract class DriverBasedTest {
|
||||
private val stopDriver = CountDownLatch(1)
|
||||
private var driverThread: Thread? = null
|
||||
private lateinit var driverStarted: SettableFuture<Unit>
|
||||
|
||||
protected sealed class RunTestToken {
|
||||
internal object Token : RunTestToken()
|
||||
}
|
||||
|
||||
protected abstract fun setup(): RunTestToken
|
||||
|
||||
protected fun DriverDSLExposedInterface.runTest(): RunTestToken {
|
||||
driverStarted.set(Unit)
|
||||
stopDriver.await()
|
||||
return RunTestToken.Token
|
||||
}
|
||||
|
||||
@Before
|
||||
fun start() {
|
||||
driverStarted = SettableFuture.create()
|
||||
driverThread = thread {
|
||||
try {
|
||||
setup()
|
||||
} catch (t: Throwable) {
|
||||
driverStarted.setException(t)
|
||||
}
|
||||
}
|
||||
driverStarted.getOrThrow()
|
||||
}
|
||||
|
||||
@After
|
||||
fun stop() {
|
||||
stopDriver.countDown()
|
||||
driverThread?.join()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user