mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
CORDA-2269: Removed DriverParameters.initialiseSerialization as it's not needed (#4321)
This commit is contained in:
parent
5d1652bacb
commit
9100636b8c
@ -5893,8 +5893,6 @@ public interface net.corda.testing.driver.DriverDSL
|
||||
public final class net.corda.testing.driver.DriverParameters extends java.lang.Object
|
||||
public <init>()
|
||||
public <init>(boolean, java.nio.file.Path, net.corda.testing.driver.PortAllocation, net.corda.testing.driver.PortAllocation, java.util.Map<String, String>, boolean, boolean, boolean, java.util.List<net.corda.testing.node.NotarySpec>, java.util.List<String>, net.corda.testing.driver.JmxPolicy, net.corda.core.node.NetworkParameters)
|
||||
public <init>(boolean, java.nio.file.Path, net.corda.testing.driver.PortAllocation, net.corda.testing.driver.PortAllocation, java.util.Map<String, String>, boolean, boolean, boolean, java.util.List<net.corda.testing.node.NotarySpec>, java.util.List<String>, net.corda.testing.driver.JmxPolicy, net.corda.core.node.NetworkParameters, java.util.Map<String, ?>, boolean, boolean)
|
||||
public <init>(boolean, java.nio.file.Path, net.corda.testing.driver.PortAllocation, net.corda.testing.driver.PortAllocation, java.util.Map<String, String>, boolean, boolean, boolean, java.util.List<net.corda.testing.node.NotarySpec>, java.util.List<String>, net.corda.testing.driver.JmxPolicy, net.corda.core.node.NetworkParameters, boolean, boolean)
|
||||
public final boolean component1()
|
||||
@NotNull
|
||||
public final java.util.List<String> component10()
|
||||
|
@ -5,7 +5,6 @@ import net.corda.core.KeepForDJVM
|
||||
import net.corda.core.internal.InheritableThreadLocalToggleField
|
||||
import net.corda.core.internal.SimpleToggleField
|
||||
import net.corda.core.internal.ThreadLocalToggleField
|
||||
import net.corda.core.internal.VisibleForTesting
|
||||
import net.corda.core.serialization.SerializationContext
|
||||
import net.corda.core.serialization.SerializationFactory
|
||||
|
||||
@ -71,11 +70,13 @@ private class SerializationEnvironmentImpl(
|
||||
}
|
||||
|
||||
private val _nodeSerializationEnv = SimpleToggleField<SerializationEnvironment>("nodeSerializationEnv", true)
|
||||
@VisibleForTesting
|
||||
val _globalSerializationEnv = SimpleToggleField<SerializationEnvironment>("globalSerializationEnv")
|
||||
@VisibleForTesting
|
||||
/** Should be set once in main. */
|
||||
var nodeSerializationEnv by _nodeSerializationEnv
|
||||
|
||||
val _driverSerializationEnv = SimpleToggleField<SerializationEnvironment>("driverSerializationEnv")
|
||||
|
||||
val _contextSerializationEnv = ThreadLocalToggleField<SerializationEnvironment>("contextSerializationEnv")
|
||||
@VisibleForTesting
|
||||
|
||||
val _inheritableContextSerializationEnv = InheritableThreadLocalToggleField<SerializationEnvironment>("inheritableContextSerializationEnv") { stack ->
|
||||
stack.fold(false) { isAGlobalThreadBeingCreated, e ->
|
||||
isAGlobalThreadBeingCreated ||
|
||||
@ -83,12 +84,17 @@ val _inheritableContextSerializationEnv = InheritableThreadLocalToggleField<Seri
|
||||
(e.className == "java.util.concurrent.ForkJoinPool\$DefaultForkJoinWorkerThreadFactory" && e.methodName == "newThread")
|
||||
}
|
||||
}
|
||||
private val serializationEnvProperties = listOf(_nodeSerializationEnv, _globalSerializationEnv, _contextSerializationEnv, _inheritableContextSerializationEnv)
|
||||
|
||||
private val serializationEnvFields = listOf(_nodeSerializationEnv, _driverSerializationEnv, _contextSerializationEnv, _inheritableContextSerializationEnv)
|
||||
|
||||
val _allEnabledSerializationEnvs: List<Pair<String, SerializationEnvironment>>
|
||||
get() = serializationEnvFields.mapNotNull { it.get()?.let { env -> Pair(it.name, env) } }
|
||||
|
||||
val effectiveSerializationEnv: SerializationEnvironment
|
||||
get() = serializationEnvProperties.map { Pair(it, it.get()) }.filter { it.second != null }.run {
|
||||
singleOrNull()?.run {
|
||||
second!!
|
||||
} ?: throw IllegalStateException("Expected exactly 1 of {${serializationEnvProperties.joinToString(", ") { it.name }}} but got: {${joinToString(", ") { it.first.name }}}")
|
||||
get() {
|
||||
return _allEnabledSerializationEnvs.let {
|
||||
checkNotNull(it.singleOrNull()?.second) {
|
||||
"Expected exactly 1 of {${serializationEnvFields.joinToString(", ") { it.name }}} but got: {${it.joinToString(", ") { it.first }}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Should be set once in main. */
|
||||
var nodeSerializationEnv by _nodeSerializationEnv
|
||||
|
@ -90,7 +90,6 @@ class NetworkMapTest(var initFunc: (URL, NetworkMapServer) -> CompatibilityZoneP
|
||||
internalDriver(
|
||||
portAllocation = portAllocation,
|
||||
compatibilityZone = compatibilityZone,
|
||||
initialiseSerialization = false,
|
||||
notarySpecs = emptyList()
|
||||
) {
|
||||
val alice = startNode(providedName = ALICE_NAME, devMode = false).getOrThrow() as NodeHandleInternal
|
||||
@ -143,7 +142,6 @@ class NetworkMapTest(var initFunc: (URL, NetworkMapServer) -> CompatibilityZoneP
|
||||
internalDriver(
|
||||
portAllocation = portAllocation,
|
||||
compatibilityZone = compatibilityZone,
|
||||
initialiseSerialization = false,
|
||||
notarySpecs = emptyList()
|
||||
) {
|
||||
val alice = startNode(providedName = ALICE_NAME, devMode = false).getOrThrow()
|
||||
@ -161,7 +159,6 @@ class NetworkMapTest(var initFunc: (URL, NetworkMapServer) -> CompatibilityZoneP
|
||||
internalDriver(
|
||||
portAllocation = portAllocation,
|
||||
compatibilityZone = compatibilityZone,
|
||||
initialiseSerialization = false,
|
||||
notarySpecs = emptyList()
|
||||
) {
|
||||
val (aliceNode, bobNode) = listOf(
|
||||
@ -179,7 +176,6 @@ class NetworkMapTest(var initFunc: (URL, NetworkMapServer) -> CompatibilityZoneP
|
||||
internalDriver(
|
||||
portAllocation = portAllocation,
|
||||
compatibilityZone = compatibilityZone,
|
||||
initialiseSerialization = false,
|
||||
notarySpecs = emptyList()
|
||||
) {
|
||||
val aliceNode = startNode(providedName = ALICE_NAME, devMode = false).getOrThrow()
|
||||
@ -201,7 +197,6 @@ class NetworkMapTest(var initFunc: (URL, NetworkMapServer) -> CompatibilityZoneP
|
||||
internalDriver(
|
||||
portAllocation = portAllocation,
|
||||
compatibilityZone = compatibilityZone,
|
||||
initialiseSerialization = false,
|
||||
notarySpecs = emptyList()
|
||||
) {
|
||||
val (aliceNode, bobNode) = listOf(
|
||||
@ -226,7 +221,6 @@ class NetworkMapTest(var initFunc: (URL, NetworkMapServer) -> CompatibilityZoneP
|
||||
internalDriver(
|
||||
portAllocation = portAllocation,
|
||||
compatibilityZone = compatibilityZone,
|
||||
initialiseSerialization = false,
|
||||
notarySpecs = emptyList(),
|
||||
systemProperties = mapOf("net.corda.node.internal.nodeinfo.publish.interval" to 1.seconds.toString())
|
||||
) {
|
||||
|
@ -87,7 +87,6 @@ class NodeRegistrationTest {
|
||||
internalDriver(
|
||||
portAllocation = portAllocation,
|
||||
compatibilityZone = compatibilityZone,
|
||||
initialiseSerialization = false,
|
||||
notarySpecs = listOf(NotarySpec(notaryName)),
|
||||
cordappsForAllNodes = cordappsInCurrentAndAdditionalPackages("net.corda.finance"),
|
||||
notaryCustomOverrides = mapOf("devMode" to false)
|
||||
|
@ -98,8 +98,7 @@ data class WebserverHandle(
|
||||
)
|
||||
|
||||
/**
|
||||
* An abstract helper class which is used within the driver to allocate unused ports for testing. Use either
|
||||
* the [Incremental] or [RandomFree] concrete implementations.
|
||||
* An abstract helper class which is used within the driver to allocate unused ports for testing.
|
||||
*/
|
||||
@DoNotImplement
|
||||
abstract class PortAllocation {
|
||||
@ -159,8 +158,7 @@ fun <A> driver(defaultParameters: DriverParameters = DriverParameters(), dsl: Dr
|
||||
signCordapps = false
|
||||
),
|
||||
coerce = { it },
|
||||
dsl = dsl,
|
||||
initialiseSerialization = defaultParameters.initialiseSerialization
|
||||
dsl = dsl
|
||||
)
|
||||
}
|
||||
|
||||
@ -189,7 +187,6 @@ fun <A> driver(defaultParameters: DriverParameters = DriverParameters(), dsl: Dr
|
||||
* @property networkParameters The network parameters to be used by all the nodes. [NetworkParameters.notaries] must be
|
||||
* empty as notaries are defined by [notarySpecs].
|
||||
* @property notaryCustomOverrides Extra settings that need to be passed to the notary.
|
||||
* @property initialiseSerialization Indicates whether to initialized the serialization subsystem.
|
||||
* @property inMemoryDB Whether to use in-memory H2 for new nodes rather then on-disk (the node starts quicker, however
|
||||
* the data is not persisted between node restarts). Has no effect if node is configured
|
||||
* in any way to use database other than H2.
|
||||
@ -210,7 +207,6 @@ data class DriverParameters(
|
||||
@Suppress("DEPRECATION") val jmxPolicy: JmxPolicy = JmxPolicy(),
|
||||
val networkParameters: NetworkParameters = testNetworkParameters(notaries = emptyList()),
|
||||
val notaryCustomOverrides: Map<String, Any?> = emptyMap(),
|
||||
val initialiseSerialization: Boolean = true,
|
||||
val inMemoryDB: Boolean = true,
|
||||
val cordappsForAllNodes: Collection<TestCordapp>? = null
|
||||
) {
|
||||
@ -228,7 +224,6 @@ data class DriverParameters(
|
||||
@Suppress("DEPRECATION") jmxPolicy: JmxPolicy = JmxPolicy(),
|
||||
networkParameters: NetworkParameters = testNetworkParameters(notaries = emptyList()),
|
||||
notaryCustomOverrides: Map<String, Any?> = emptyMap(),
|
||||
initialiseSerialization: Boolean = true,
|
||||
inMemoryDB: Boolean = true
|
||||
) : this(
|
||||
isDebug,
|
||||
@ -244,7 +239,6 @@ data class DriverParameters(
|
||||
jmxPolicy,
|
||||
networkParameters,
|
||||
notaryCustomOverrides,
|
||||
initialiseSerialization,
|
||||
inMemoryDB,
|
||||
cordappsForAllNodes = null
|
||||
)
|
||||
@ -277,7 +271,6 @@ data class DriverParameters(
|
||||
networkParameters,
|
||||
emptyMap(),
|
||||
true,
|
||||
true,
|
||||
cordappsForAllNodes = null
|
||||
)
|
||||
|
||||
@ -310,7 +303,6 @@ data class DriverParameters(
|
||||
networkParameters,
|
||||
emptyMap(),
|
||||
true,
|
||||
true,
|
||||
cordappsForAllNodes
|
||||
)
|
||||
|
||||
@ -327,7 +319,6 @@ data class DriverParameters(
|
||||
extraCordappPackagesToScan: List<String>,
|
||||
jmxPolicy: JmxPolicy,
|
||||
networkParameters: NetworkParameters,
|
||||
initialiseSerialization: Boolean,
|
||||
inMemoryDB: Boolean
|
||||
) : this(
|
||||
isDebug,
|
||||
@ -343,7 +334,6 @@ data class DriverParameters(
|
||||
jmxPolicy,
|
||||
networkParameters,
|
||||
emptyMap(),
|
||||
initialiseSerialization,
|
||||
inMemoryDB,
|
||||
cordappsForAllNodes = null
|
||||
)
|
||||
@ -361,7 +351,6 @@ data class DriverParameters(
|
||||
extraCordappPackagesToScan: List<String>,
|
||||
jmxPolicy: JmxPolicy,
|
||||
networkParameters: NetworkParameters,
|
||||
initialiseSerialization: Boolean,
|
||||
inMemoryDB: Boolean,
|
||||
cordappsForAllNodes: Set<TestCordapp>? = null
|
||||
) : this(
|
||||
@ -378,7 +367,6 @@ data class DriverParameters(
|
||||
jmxPolicy,
|
||||
networkParameters,
|
||||
emptyMap(),
|
||||
initialiseSerialization,
|
||||
inMemoryDB,
|
||||
cordappsForAllNodes
|
||||
)
|
||||
@ -389,7 +377,6 @@ data class DriverParameters(
|
||||
fun withDebugPortAllocation(debugPortAllocation: PortAllocation): DriverParameters = copy(debugPortAllocation = debugPortAllocation)
|
||||
fun withSystemProperties(systemProperties: Map<String, String>): DriverParameters = copy(systemProperties = systemProperties)
|
||||
fun withUseTestClock(useTestClock: Boolean): DriverParameters = copy(useTestClock = useTestClock)
|
||||
fun withInitialiseSerialization(initialiseSerialization: Boolean): DriverParameters = copy(initialiseSerialization = initialiseSerialization)
|
||||
fun withStartNodesInProcess(startNodesInProcess: Boolean): DriverParameters = copy(startNodesInProcess = startNodesInProcess)
|
||||
fun withWaitForAllNodesToFinish(waitForAllNodesToFinish: Boolean): DriverParameters = copy(waitForAllNodesToFinish = waitForAllNodesToFinish)
|
||||
fun withNotarySpecs(notarySpecs: List<NotarySpec>): DriverParameters = copy(notarySpecs = notarySpecs)
|
||||
@ -426,39 +413,7 @@ data class DriverParameters(
|
||||
extraCordappPackagesToScan = extraCordappPackagesToScan,
|
||||
jmxPolicy = jmxPolicy,
|
||||
networkParameters = networkParameters,
|
||||
notaryCustomOverrides = emptyMap(),
|
||||
initialiseSerialization = true
|
||||
)
|
||||
|
||||
fun copy(
|
||||
isDebug: Boolean,
|
||||
driverDirectory: Path,
|
||||
portAllocation: PortAllocation,
|
||||
debugPortAllocation: PortAllocation,
|
||||
systemProperties: Map<String, String>,
|
||||
useTestClock: Boolean,
|
||||
startNodesInProcess: Boolean,
|
||||
waitForAllNodesToFinish: Boolean,
|
||||
notarySpecs: List<NotarySpec>,
|
||||
extraCordappPackagesToScan: List<String>,
|
||||
jmxPolicy: JmxPolicy,
|
||||
networkParameters: NetworkParameters,
|
||||
initialiseSerialization: Boolean
|
||||
) = this.copy(
|
||||
isDebug = isDebug,
|
||||
driverDirectory = driverDirectory,
|
||||
portAllocation = portAllocation,
|
||||
debugPortAllocation = debugPortAllocation,
|
||||
systemProperties = systemProperties,
|
||||
useTestClock = useTestClock,
|
||||
startNodesInProcess = startNodesInProcess,
|
||||
waitForAllNodesToFinish = waitForAllNodesToFinish,
|
||||
notarySpecs = notarySpecs,
|
||||
extraCordappPackagesToScan = extraCordappPackagesToScan,
|
||||
jmxPolicy = jmxPolicy,
|
||||
networkParameters = networkParameters,
|
||||
notaryCustomOverrides = emptyMap(),
|
||||
initialiseSerialization = initialiseSerialization
|
||||
notaryCustomOverrides = emptyMap()
|
||||
)
|
||||
|
||||
fun copy(
|
||||
@ -489,40 +444,6 @@ data class DriverParameters(
|
||||
jmxPolicy = jmxPolicy,
|
||||
networkParameters = networkParameters,
|
||||
notaryCustomOverrides = emptyMap(),
|
||||
initialiseSerialization = true,
|
||||
cordappsForAllNodes = cordappsForAllNodes
|
||||
)
|
||||
|
||||
fun copy(
|
||||
isDebug: Boolean,
|
||||
driverDirectory: Path,
|
||||
portAllocation: PortAllocation,
|
||||
debugPortAllocation: PortAllocation,
|
||||
systemProperties: Map<String, String>,
|
||||
useTestClock: Boolean,
|
||||
startNodesInProcess: Boolean,
|
||||
waitForAllNodesToFinish: Boolean,
|
||||
notarySpecs: List<NotarySpec>,
|
||||
extraCordappPackagesToScan: List<String>,
|
||||
jmxPolicy: JmxPolicy,
|
||||
networkParameters: NetworkParameters,
|
||||
initialiseSerialization: Boolean,
|
||||
cordappsForAllNodes: Set<TestCordapp>?
|
||||
) = this.copy(
|
||||
isDebug = isDebug,
|
||||
driverDirectory = driverDirectory,
|
||||
portAllocation = portAllocation,
|
||||
debugPortAllocation = debugPortAllocation,
|
||||
systemProperties = systemProperties,
|
||||
useTestClock = useTestClock,
|
||||
startNodesInProcess = startNodesInProcess,
|
||||
waitForAllNodesToFinish = waitForAllNodesToFinish,
|
||||
notarySpecs = notarySpecs,
|
||||
extraCordappPackagesToScan = extraCordappPackagesToScan,
|
||||
jmxPolicy = jmxPolicy,
|
||||
networkParameters = networkParameters,
|
||||
notaryCustomOverrides = emptyMap(),
|
||||
initialiseSerialization = initialiseSerialization,
|
||||
cordappsForAllNodes = cordappsForAllNodes
|
||||
)
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ import net.corda.testing.driver.*
|
||||
import net.corda.testing.driver.internal.InProcessImpl
|
||||
import net.corda.testing.driver.internal.NodeHandleInternal
|
||||
import net.corda.testing.driver.internal.OutOfProcessImpl
|
||||
import net.corda.testing.internal.setGlobalSerialization
|
||||
import net.corda.testing.internal.stubs.CertificateStoreStubs
|
||||
import net.corda.testing.node.ClusterSpec
|
||||
import net.corda.testing.node.NotarySpec
|
||||
@ -956,11 +955,10 @@ interface InternalDriverDSL : DriverDSL {
|
||||
*/
|
||||
fun <DI : DriverDSL, D : InternalDriverDSL, A> genericDriver(
|
||||
driverDsl: D,
|
||||
initialiseSerialization: Boolean = true,
|
||||
coerce: (D) -> DI,
|
||||
dsl: DI.() -> A
|
||||
): A {
|
||||
val serializationEnv = setGlobalSerialization(initialiseSerialization)
|
||||
val serializationEnv = setDriverSerialization()
|
||||
val shutdownHook = addShutdownHook(driverDsl::shutdown)
|
||||
try {
|
||||
driverDsl.start()
|
||||
@ -971,7 +969,7 @@ fun <DI : DriverDSL, D : InternalDriverDSL, A> genericDriver(
|
||||
} finally {
|
||||
driverDsl.shutdown()
|
||||
shutdownHook.cancel()
|
||||
serializationEnv.unset()
|
||||
serializationEnv?.close()
|
||||
}
|
||||
}
|
||||
|
||||
@ -988,7 +986,7 @@ fun <DI : DriverDSL, D : InternalDriverDSL, A> genericDriver(
|
||||
driverDslWrapper: (DriverDSLImpl) -> D,
|
||||
coerce: (D) -> DI, dsl: DI.() -> A
|
||||
): A {
|
||||
val serializationEnv = setGlobalSerialization(true)
|
||||
val serializationEnv = setDriverSerialization()
|
||||
val driverDsl = driverDslWrapper(
|
||||
DriverDSLImpl(
|
||||
portAllocation = defaultParameters.portAllocation,
|
||||
@ -1019,7 +1017,7 @@ fun <DI : DriverDSL, D : InternalDriverDSL, A> genericDriver(
|
||||
} finally {
|
||||
driverDsl.shutdown()
|
||||
shutdownHook.cancel()
|
||||
serializationEnv.unset()
|
||||
serializationEnv?.close()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1090,7 +1088,6 @@ fun <A> internalDriver(
|
||||
debugPortAllocation: PortAllocation = DriverParameters().debugPortAllocation,
|
||||
systemProperties: Map<String, String> = DriverParameters().systemProperties,
|
||||
useTestClock: Boolean = DriverParameters().useTestClock,
|
||||
initialiseSerialization: Boolean = true,
|
||||
startNodesInProcess: Boolean = DriverParameters().startNodesInProcess,
|
||||
waitForAllNodesToFinish: Boolean = DriverParameters().waitForAllNodesToFinish,
|
||||
notarySpecs: List<NotarySpec> = DriverParameters().notarySpecs,
|
||||
@ -1123,8 +1120,7 @@ fun <A> internalDriver(
|
||||
signCordapps = signCordapps
|
||||
),
|
||||
coerce = { it },
|
||||
dsl = dsl,
|
||||
initialiseSerialization = initialiseSerialization
|
||||
dsl = dsl
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,6 @@ import net.corda.nodeapi.internal.persistence.CordaPersistence
|
||||
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
||||
import net.corda.testing.common.internal.testNetworkParameters
|
||||
import net.corda.testing.internal.rigorousMock
|
||||
import net.corda.testing.internal.setGlobalSerialization
|
||||
import net.corda.testing.internal.stubs.CertificateStoreStubs
|
||||
import net.corda.testing.internal.testThreadFactory
|
||||
import net.corda.testing.node.*
|
||||
@ -169,11 +168,7 @@ open class InternalMockNetwork(defaultParameters: MockNetworkParameters = MockNe
|
||||
private val networkId = random63BitValue()
|
||||
private val networkParametersCopier: NetworkParametersCopier
|
||||
private val _nodes = mutableListOf<MockNode>()
|
||||
private val serializationEnv = try {
|
||||
setGlobalSerialization(true)
|
||||
} catch (e: IllegalStateException) {
|
||||
throw IllegalStateException("Using more than one InternalMockNetwork simultaneously is not supported.", e)
|
||||
}
|
||||
private val serializationEnv = checkNotNull(setDriverSerialization()) { "Using more than one mock network simultaneously is not supported." }
|
||||
private val sharedUserCount = AtomicInteger(0)
|
||||
|
||||
/** A read only view of the current set of nodes. */
|
||||
@ -566,10 +561,9 @@ open class InternalMockNetwork(defaultParameters: MockNetworkParameters = MockNe
|
||||
}
|
||||
|
||||
fun stopNodes() {
|
||||
try {
|
||||
// Serialization env must be unset even if other parts of this method fail.
|
||||
serializationEnv.use {
|
||||
nodes.forEach { it.started?.dispose() }
|
||||
} finally {
|
||||
serializationEnv.unset() // Must execute even if other parts of this method fail.
|
||||
}
|
||||
messagingNetwork.stop()
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ import net.corda.core.internal.FlowStateMachine
|
||||
import net.corda.core.internal.concurrent.openFuture
|
||||
import net.corda.core.internal.times
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.serialization.internal.SerializationEnvironment
|
||||
import net.corda.core.serialization.internal._allEnabledSerializationEnvs
|
||||
import net.corda.core.serialization.internal._driverSerializationEnv
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.core.utilities.millis
|
||||
@ -18,6 +21,8 @@ import net.corda.node.services.api.StartedNodeServices
|
||||
import net.corda.node.services.messaging.Message
|
||||
import net.corda.testing.driver.NodeHandle
|
||||
import net.corda.testing.internal.chooseIdentity
|
||||
import net.corda.testing.internal.createTestSerializationEnv
|
||||
import net.corda.testing.internal.inVMExecutors
|
||||
import net.corda.testing.node.InMemoryMessagingNetwork
|
||||
import net.corda.testing.node.User
|
||||
import net.corda.testing.node.testContext
|
||||
@ -115,15 +120,11 @@ fun InMemoryMessagingNetwork.MessageTransfer.getMessage(): Message = message
|
||||
|
||||
fun CordaRPCClient.start(user: User) = start(user.username, user.password)
|
||||
|
||||
fun NodeHandle.waitForShutdown(): Observable<Unit> {
|
||||
|
||||
return rpc.waitForShutdown().doAfterTerminate(::stop)
|
||||
}
|
||||
fun NodeHandle.waitForShutdown(): Observable<Unit> = rpc.waitForShutdown().doAfterTerminate(::stop)
|
||||
|
||||
fun CordaRPCOps.waitForShutdown(): Observable<Unit> {
|
||||
|
||||
val completable = AsyncSubject.create<Unit>()
|
||||
stateMachinesFeed().updates.subscribe({ _ -> }, { error ->
|
||||
stateMachinesFeed().updates.subscribe({ }, { error ->
|
||||
if (error is ConnectionFailureException) {
|
||||
completable.onCompleted()
|
||||
} else {
|
||||
@ -131,4 +132,23 @@ fun CordaRPCOps.waitForShutdown(): Observable<Unit> {
|
||||
}
|
||||
})
|
||||
return completable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be used by Driver and MockNode.
|
||||
*/
|
||||
fun setDriverSerialization(): AutoCloseable? {
|
||||
return if (_allEnabledSerializationEnvs.isEmpty()) {
|
||||
DriverSerializationEnvironment().enable()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private class DriverSerializationEnvironment : SerializationEnvironment by createTestSerializationEnv(), AutoCloseable {
|
||||
fun enable() = apply { _driverSerializationEnv.set(this) }
|
||||
override fun close() {
|
||||
_driverSerializationEnv.set(null)
|
||||
inVMExecutors.remove(this)
|
||||
}
|
||||
}
|
||||
|
@ -146,8 +146,7 @@ fun <A> rpcDriver(
|
||||
), externalTrace
|
||||
),
|
||||
coerce = { it },
|
||||
dsl = dsl,
|
||||
initialiseSerialization = false
|
||||
dsl = dsl
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.corda.testing.internal
|
||||
|
||||
import com.nhaarman.mockito_kotlin.doNothing
|
||||
import com.nhaarman.mockito_kotlin.whenever
|
||||
import net.corda.client.rpc.internal.serialization.amqp.AMQPClientSerializationScheme
|
||||
import net.corda.core.DoNotImplement
|
||||
import net.corda.core.serialization.internal.*
|
||||
import net.corda.core.serialization.internal.SerializationEnvironment
|
||||
import net.corda.core.serialization.internal._contextSerializationEnv
|
||||
import net.corda.core.serialization.internal._inheritableContextSerializationEnv
|
||||
import net.corda.node.serialization.amqp.AMQPServerSerializationScheme
|
||||
import net.corda.node.serialization.kryo.KRYO_CHECKPOINT_CONTEXT
|
||||
import net.corda.node.serialization.kryo.KryoCheckpointSerializer
|
||||
@ -29,7 +28,7 @@ fun <T> withoutTestSerialization(callable: () -> T): T { // TODO: Delete this, s
|
||||
}
|
||||
}
|
||||
|
||||
internal fun createTestSerializationEnv(): SerializationEnvironment {
|
||||
fun createTestSerializationEnv(): SerializationEnvironment {
|
||||
val factory = SerializationFactoryImpl().apply {
|
||||
registerScheme(AMQPClientSerializationScheme(emptyList()))
|
||||
registerScheme(AMQPServerSerializationScheme(emptyList()))
|
||||
@ -45,30 +44,3 @@ internal fun createTestSerializationEnv(): SerializationEnvironment {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be used by Driver and MockNode.
|
||||
* @param armed true to install, false to do nothing and return a dummy env.
|
||||
*/
|
||||
fun setGlobalSerialization(armed: Boolean): GlobalSerializationEnvironment {
|
||||
return if (armed) {
|
||||
object : GlobalSerializationEnvironment, SerializationEnvironment by createTestSerializationEnv() {
|
||||
override fun unset() {
|
||||
_globalSerializationEnv.set(null)
|
||||
inVMExecutors.remove(this)
|
||||
}
|
||||
}.also {
|
||||
_globalSerializationEnv.set(it)
|
||||
}
|
||||
} else {
|
||||
rigorousMock<GlobalSerializationEnvironment>().also {
|
||||
doNothing().whenever(it).unset()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DoNotImplement
|
||||
interface GlobalSerializationEnvironment : SerializationEnvironment {
|
||||
/** Unset this environment. */
|
||||
fun unset()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user