diff --git a/.ci/api-current.txt b/.ci/api-current.txt index 37a43f06ce..f76e1a94bd 100644 --- a/.ci/api-current.txt +++ b/.ci/api-current.txt @@ -5893,8 +5893,6 @@ public interface net.corda.testing.driver.DriverDSL public final class net.corda.testing.driver.DriverParameters extends java.lang.Object public () public (boolean, java.nio.file.Path, net.corda.testing.driver.PortAllocation, net.corda.testing.driver.PortAllocation, java.util.Map, boolean, boolean, boolean, java.util.List, java.util.List, net.corda.testing.driver.JmxPolicy, net.corda.core.node.NetworkParameters) - public (boolean, java.nio.file.Path, net.corda.testing.driver.PortAllocation, net.corda.testing.driver.PortAllocation, java.util.Map, boolean, boolean, boolean, java.util.List, java.util.List, net.corda.testing.driver.JmxPolicy, net.corda.core.node.NetworkParameters, java.util.Map, boolean, boolean) - public (boolean, java.nio.file.Path, net.corda.testing.driver.PortAllocation, net.corda.testing.driver.PortAllocation, java.util.Map, boolean, boolean, boolean, java.util.List, java.util.List, net.corda.testing.driver.JmxPolicy, net.corda.core.node.NetworkParameters, boolean, boolean) public final boolean component1() @NotNull public final java.util.List component10() diff --git a/core/src/main/kotlin/net/corda/core/serialization/internal/SerializationEnvironment.kt b/core/src/main/kotlin/net/corda/core/serialization/internal/SerializationEnvironment.kt index b213b6322d..9a6e461df9 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/internal/SerializationEnvironment.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/internal/SerializationEnvironment.kt @@ -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("nodeSerializationEnv", true) -@VisibleForTesting -val _globalSerializationEnv = SimpleToggleField("globalSerializationEnv") -@VisibleForTesting +/** Should be set once in main. */ +var nodeSerializationEnv by _nodeSerializationEnv + +val _driverSerializationEnv = SimpleToggleField("driverSerializationEnv") + val _contextSerializationEnv = ThreadLocalToggleField("contextSerializationEnv") -@VisibleForTesting + val _inheritableContextSerializationEnv = InheritableThreadLocalToggleField("inheritableContextSerializationEnv") { stack -> stack.fold(false) { isAGlobalThreadBeingCreated, e -> isAGlobalThreadBeingCreated || @@ -83,12 +84,17 @@ val _inheritableContextSerializationEnv = InheritableThreadLocalToggleField> + 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 diff --git a/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt index 4547efe023..4fc3911265 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt @@ -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()) ) { diff --git a/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt b/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt index 3b4c2c617d..e679aa5a8b 100644 --- a/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt @@ -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) diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt index 3b6aa454cb..20df97e927 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt @@ -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 driver(defaultParameters: DriverParameters = DriverParameters(), dsl: Dr signCordapps = false ), coerce = { it }, - dsl = dsl, - initialiseSerialization = defaultParameters.initialiseSerialization + dsl = dsl ) } @@ -189,7 +187,6 @@ fun 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 = emptyMap(), - val initialiseSerialization: Boolean = true, val inMemoryDB: Boolean = true, val cordappsForAllNodes: Collection? = null ) { @@ -228,7 +224,6 @@ data class DriverParameters( @Suppress("DEPRECATION") jmxPolicy: JmxPolicy = JmxPolicy(), networkParameters: NetworkParameters = testNetworkParameters(notaries = emptyList()), notaryCustomOverrides: Map = 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, 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, jmxPolicy: JmxPolicy, networkParameters: NetworkParameters, - initialiseSerialization: Boolean, inMemoryDB: Boolean, cordappsForAllNodes: Set? = 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): 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): 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, - useTestClock: Boolean, - startNodesInProcess: Boolean, - waitForAllNodesToFinish: Boolean, - notarySpecs: List, - extraCordappPackagesToScan: List, - 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, - useTestClock: Boolean, - startNodesInProcess: Boolean, - waitForAllNodesToFinish: Boolean, - notarySpecs: List, - extraCordappPackagesToScan: List, - jmxPolicy: JmxPolicy, - networkParameters: NetworkParameters, - initialiseSerialization: Boolean, - cordappsForAllNodes: Set? - ) = 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 ) } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt index 6326319f8d..92e6e370d3 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt @@ -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 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 genericDriver( } finally { driverDsl.shutdown() shutdownHook.cancel() - serializationEnv.unset() + serializationEnv?.close() } } @@ -988,7 +986,7 @@ fun 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 genericDriver( } finally { driverDsl.shutdown() shutdownHook.cancel() - serializationEnv.unset() + serializationEnv?.close() } } @@ -1090,7 +1088,6 @@ fun internalDriver( debugPortAllocation: PortAllocation = DriverParameters().debugPortAllocation, systemProperties: Map = DriverParameters().systemProperties, useTestClock: Boolean = DriverParameters().useTestClock, - initialiseSerialization: Boolean = true, startNodesInProcess: Boolean = DriverParameters().startNodesInProcess, waitForAllNodesToFinish: Boolean = DriverParameters().waitForAllNodesToFinish, notarySpecs: List = DriverParameters().notarySpecs, @@ -1123,8 +1120,7 @@ fun internalDriver( signCordapps = signCordapps ), coerce = { it }, - dsl = dsl, - initialiseSerialization = initialiseSerialization + dsl = dsl ) } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalMockNetwork.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalMockNetwork.kt index b549219f05..ad11d62368 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalMockNetwork.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalMockNetwork.kt @@ -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() - 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() } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt index e052e2b36c..21160e78fc 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt @@ -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 { - - return rpc.waitForShutdown().doAfterTerminate(::stop) -} +fun NodeHandle.waitForShutdown(): Observable = rpc.waitForShutdown().doAfterTerminate(::stop) fun CordaRPCOps.waitForShutdown(): Observable { - val completable = AsyncSubject.create() - stateMachinesFeed().updates.subscribe({ _ -> }, { error -> + stateMachinesFeed().updates.subscribe({ }, { error -> if (error is ConnectionFailureException) { completable.onCompleted() } else { @@ -131,4 +132,23 @@ fun CordaRPCOps.waitForShutdown(): Observable { } }) return completable -} \ No newline at end of file +} + +/** + * 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) + } +} diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt index effce01dfa..90f47892b6 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt @@ -146,8 +146,7 @@ fun rpcDriver( ), externalTrace ), coerce = { it }, - dsl = dsl, - initialiseSerialization = false + dsl = dsl ) } diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/internal/InternalSerializationTestHelpers.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/internal/InternalSerializationTestHelpers.kt index 3257cca802..9ed3da7fd1 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/internal/InternalSerializationTestHelpers.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/internal/InternalSerializationTestHelpers.kt @@ -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 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().also { - doNothing().whenever(it).unset() - } - } -} - -@DoNotImplement -interface GlobalSerializationEnvironment : SerializationEnvironment { - /** Unset this environment. */ - fun unset() -} -