mirror of
https://github.com/corda/corda.git
synced 2025-06-21 16:49:45 +00:00
Retire DriverBasedTest. (#1986)
This commit is contained in:
@ -31,11 +31,10 @@ import net.corda.node.services.Permissions.Companion.startFlow
|
|||||||
import net.corda.nodeapi.User
|
import net.corda.nodeapi.User
|
||||||
import net.corda.testing.*
|
import net.corda.testing.*
|
||||||
import net.corda.testing.driver.driver
|
import net.corda.testing.driver.driver
|
||||||
import net.corda.testing.node.DriverBasedTest
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
|
||||||
class NodeMonitorModelTest : DriverBasedTest() {
|
class NodeMonitorModelTest {
|
||||||
lateinit var aliceNode: NodeInfo
|
lateinit var aliceNode: NodeInfo
|
||||||
lateinit var bobNode: NodeInfo
|
lateinit var bobNode: NodeInfo
|
||||||
lateinit var notaryParty: Party
|
lateinit var notaryParty: Party
|
||||||
@ -50,8 +49,7 @@ class NodeMonitorModelTest : DriverBasedTest() {
|
|||||||
lateinit var vaultUpdates: Observable<Vault.Update<ContractState>>
|
lateinit var vaultUpdates: Observable<Vault.Update<ContractState>>
|
||||||
lateinit var networkMapUpdates: Observable<NetworkMapCache.MapChange>
|
lateinit var networkMapUpdates: Observable<NetworkMapCache.MapChange>
|
||||||
lateinit var newNode: (CordaX500Name) -> NodeInfo
|
lateinit var newNode: (CordaX500Name) -> NodeInfo
|
||||||
|
private fun setup(runTest: () -> Unit) = driver(extraCordappPackagesToScan = listOf("net.corda.finance")) {
|
||||||
override fun setup() = driver(extraCordappPackagesToScan = listOf("net.corda.finance")) {
|
|
||||||
val cashUser = User("user1", "test", permissions = setOf(
|
val cashUser = User("user1", "test", permissions = setOf(
|
||||||
startFlow<CashIssueFlow>(),
|
startFlow<CashIssueFlow>(),
|
||||||
startFlow<CashPaymentFlow>(),
|
startFlow<CashPaymentFlow>(),
|
||||||
@ -91,7 +89,7 @@ class NodeMonitorModelTest : DriverBasedTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `network map update`() {
|
fun `network map update`() = setup {
|
||||||
val charlieNode = newNode(CHARLIE.name)
|
val charlieNode = newNode(CHARLIE.name)
|
||||||
val nonServiceIdentities = aliceNode.legalIdentitiesAndCerts + bobNode.legalIdentitiesAndCerts + charlieNode.legalIdentitiesAndCerts
|
val nonServiceIdentities = aliceNode.legalIdentitiesAndCerts + bobNode.legalIdentitiesAndCerts + charlieNode.legalIdentitiesAndCerts
|
||||||
networkMapUpdates.filter { it.node.legalIdentitiesAndCerts.any { it in nonServiceIdentities } }
|
networkMapUpdates.filter { it.node.legalIdentitiesAndCerts.any { it in nonServiceIdentities } }
|
||||||
@ -112,7 +110,7 @@ class NodeMonitorModelTest : DriverBasedTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `cash issue works end to end`() {
|
fun `cash issue works end to end`() = setup {
|
||||||
rpc.startFlow(::CashIssueFlow,
|
rpc.startFlow(::CashIssueFlow,
|
||||||
Amount(100, USD),
|
Amount(100, USD),
|
||||||
OpaqueBytes(ByteArray(1, { 1 })),
|
OpaqueBytes(ByteArray(1, { 1 })),
|
||||||
@ -136,7 +134,7 @@ class NodeMonitorModelTest : DriverBasedTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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()
|
val (_, issueIdentity) = rpc.startFlow(::CashIssueFlow, 100.DOLLARS, OpaqueBytes.of(1), notaryParty).returnValue.getOrThrow()
|
||||||
rpc.startFlow(::CashPaymentFlow, 100.DOLLARS, bobNode.chooseIdentity()).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.*
|
||||||
import net.corda.testing.driver.NodeHandle
|
import net.corda.testing.driver.NodeHandle
|
||||||
import net.corda.testing.driver.driver
|
import net.corda.testing.driver.driver
|
||||||
import net.corda.testing.node.DriverBasedTest
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class DistributedServiceTests : DriverBasedTest() {
|
class DistributedServiceTests {
|
||||||
lateinit var alice: NodeHandle
|
lateinit var alice: NodeHandle
|
||||||
lateinit var notaries: List<NodeHandle.OutOfProcess>
|
lateinit var notaries: List<NodeHandle.OutOfProcess>
|
||||||
lateinit var aliceProxy: CordaRPCOps
|
lateinit var aliceProxy: CordaRPCOps
|
||||||
lateinit var raftNotaryIdentity: Party
|
lateinit var raftNotaryIdentity: Party
|
||||||
lateinit var notaryStateMachines: Observable<Pair<Party, StateMachineUpdate>>
|
lateinit var notaryStateMachines: Observable<Pair<Party, StateMachineUpdate>>
|
||||||
|
private fun setup(runTest: () -> Unit) = driver(extraCordappPackagesToScan = listOf("net.corda.finance.contracts")) {
|
||||||
override fun setup() = driver(extraCordappPackagesToScan = listOf("net.corda.finance.contracts")) {
|
|
||||||
// Start Alice and 3 notaries in a RAFT cluster
|
// Start Alice and 3 notaries in a RAFT cluster
|
||||||
val clusterSize = 3
|
val clusterSize = 3
|
||||||
val testUser = User("test", "test", permissions = setOf(
|
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
|
// TODO Use a dummy distributed service rather than a Raft Notary Service as this test is only about Artemis' ability
|
||||||
// to handle distributed services
|
// to handle distributed services
|
||||||
@Test
|
@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
|
// Issue 100 pounds, then pay ourselves 50x2 pounds
|
||||||
issueCash(100.POUNDS)
|
issueCash(100.POUNDS)
|
||||||
|
|
||||||
@ -100,7 +98,7 @@ class DistributedServiceTests : DriverBasedTest() {
|
|||||||
|
|
||||||
// TODO This should be in RaftNotaryServiceTests
|
// TODO This should be in RaftNotaryServiceTests
|
||||||
@Test
|
@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
|
// Issue 100 pounds, then pay ourselves 10x5 pounds
|
||||||
issueCash(100.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()
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user