mirror of
https://github.com/corda/corda.git
synced 2025-06-22 17:09:00 +00:00
CORDA-716 Retire withTestSerialization (#2240)
This commit is contained in:
@ -55,25 +55,6 @@ interface GlobalSerializationEnvironment : SerializationEnvironment {
|
||||
fun unset()
|
||||
}
|
||||
|
||||
/** @param inheritable whether new threads inherit the environment, use sparingly. */
|
||||
fun <T> withTestSerialization(inheritable: Boolean = false, callable: (SerializationEnvironment) -> T): T {
|
||||
return createTestSerializationEnv("<context>").asContextEnv(inheritable, callable)
|
||||
}
|
||||
|
||||
/**
|
||||
* For example your test class uses [SerializationEnvironmentRule] but you want to turn it off for one method.
|
||||
* Use sparingly, ideally a test class shouldn't mix serializers init mechanisms.
|
||||
*/
|
||||
fun <T> withoutTestSerialization(callable: () -> T): T {
|
||||
val (property, env) = listOf(_contextSerializationEnv, _inheritableContextSerializationEnv).map { Pair(it, it.get()) }.single { it.second != null }
|
||||
property.set(null)
|
||||
try {
|
||||
return callable()
|
||||
} finally {
|
||||
property.set(env)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be used by Driver and MockNode.
|
||||
* @param armed true to install, false to do nothing and return a dummy env.
|
||||
|
@ -0,0 +1,19 @@
|
||||
package net.corda.testing.internal
|
||||
|
||||
import net.corda.core.serialization.internal._contextSerializationEnv
|
||||
import net.corda.core.serialization.internal._inheritableContextSerializationEnv
|
||||
import net.corda.testing.SerializationEnvironmentRule
|
||||
|
||||
/**
|
||||
* For example your test class uses [SerializationEnvironmentRule] but you want to turn it off for one method.
|
||||
* Use sparingly, ideally a test class shouldn't mix serializers init mechanisms.
|
||||
*/
|
||||
fun <T> withoutTestSerialization(callable: () -> T): T { // TODO: Delete this, see CORDA-858.
|
||||
val (property, env) = listOf(_contextSerializationEnv, _inheritableContextSerializationEnv).map { Pair(it, it.get()) }.single { it.second != null }
|
||||
property.set(null)
|
||||
try {
|
||||
return callable()
|
||||
} finally {
|
||||
property.set(env)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user