mirror of
https://github.com/corda/corda.git
synced 2025-06-19 07:38:22 +00:00
Use in-memory H2 for integration test (#2508)
* Default integration tests running with in-memory H2
This commit is contained in:
committed by
GitHub
parent
02978fc174
commit
f7dd4f7880
@ -234,7 +234,8 @@ fun <A> driver(defaultParameters: DriverParameters = DriverParameters(), dsl: Dr
|
||||
jmxPolicy = defaultParameters.jmxPolicy,
|
||||
compatibilityZone = null,
|
||||
networkParameters = defaultParameters.networkParameters,
|
||||
notaryCustomOverrides = defaultParameters.notaryCustomOverrides
|
||||
notaryCustomOverrides = defaultParameters.notaryCustomOverrides,
|
||||
inMemoryDB = defaultParameters.inMemoryDB
|
||||
),
|
||||
coerce = { it },
|
||||
dsl = dsl,
|
||||
@ -267,6 +268,10 @@ 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.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
data class DriverParameters(
|
||||
@ -283,7 +288,8 @@ data class DriverParameters(
|
||||
val jmxPolicy: JmxPolicy = JmxPolicy(),
|
||||
val networkParameters: NetworkParameters = testNetworkParameters(notaries = emptyList()),
|
||||
val notaryCustomOverrides: Map<String, Any?> = emptyMap(),
|
||||
val initialiseSerialization: Boolean = true
|
||||
val initialiseSerialization: Boolean = true,
|
||||
val inMemoryDB: Boolean = true
|
||||
) {
|
||||
constructor(
|
||||
isDebug: Boolean,
|
||||
@ -312,6 +318,7 @@ data class DriverParameters(
|
||||
jmxPolicy,
|
||||
networkParameters,
|
||||
emptyMap(),
|
||||
true,
|
||||
true
|
||||
)
|
||||
|
||||
@ -328,7 +335,8 @@ data class DriverParameters(
|
||||
extraCordappPackagesToScan: List<String>,
|
||||
jmxPolicy: JmxPolicy,
|
||||
networkParameters: NetworkParameters,
|
||||
initialiseSerialization: Boolean
|
||||
initialiseSerialization: Boolean,
|
||||
inMemoryDB: Boolean
|
||||
) : this(
|
||||
isDebug,
|
||||
driverDirectory,
|
||||
@ -343,7 +351,8 @@ data class DriverParameters(
|
||||
jmxPolicy,
|
||||
networkParameters,
|
||||
emptyMap(),
|
||||
initialiseSerialization
|
||||
initialiseSerialization,
|
||||
inMemoryDB
|
||||
)
|
||||
|
||||
fun withIsDebug(isDebug: Boolean): DriverParameters = copy(isDebug = isDebug)
|
||||
@ -360,6 +369,7 @@ data class DriverParameters(
|
||||
fun withJmxPolicy(jmxPolicy: JmxPolicy): DriverParameters = copy(jmxPolicy = jmxPolicy)
|
||||
fun withNetworkParameters(networkParameters: NetworkParameters): DriverParameters = copy(networkParameters = networkParameters)
|
||||
fun withNotaryCustomOverrides(notaryCustomOverrides: Map<String, Any?>): DriverParameters = copy(notaryCustomOverrides = notaryCustomOverrides)
|
||||
fun withInMemoryDB(inMemoryDB: Boolean): DriverParameters = copy(inMemoryDB = inMemoryDB)
|
||||
|
||||
fun copy(
|
||||
isDebug: Boolean,
|
||||
|
@ -73,6 +73,7 @@ import java.util.*
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledExecutorService
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.concurrent.thread
|
||||
@ -92,7 +93,8 @@ class DriverDSLImpl(
|
||||
val notarySpecs: List<NotarySpec>,
|
||||
val compatibilityZone: CompatibilityZoneParams?,
|
||||
val networkParameters: NetworkParameters,
|
||||
val notaryCustomOverrides: Map<String, Any?>
|
||||
val notaryCustomOverrides: Map<String, Any?>,
|
||||
val inMemoryDB: Boolean
|
||||
) : InternalDriverDSL {
|
||||
|
||||
private var _executorService: ScheduledExecutorService? = null
|
||||
@ -111,6 +113,9 @@ class DriverDSLImpl(
|
||||
private lateinit var _notaries: CordaFuture<List<NotaryHandle>>
|
||||
override val notaryHandles: List<NotaryHandle> get() = _notaries.getOrThrow()
|
||||
|
||||
// While starting with inProcess mode, we need to have different names to avoid clashes
|
||||
private val inMemoryCounter = AtomicInteger()
|
||||
|
||||
interface Waitable {
|
||||
@Throws(InterruptedException::class)
|
||||
fun waitFor()
|
||||
@ -127,6 +132,16 @@ class DriverDSLImpl(
|
||||
|
||||
private val jolokiaJarPath: String by lazy { resolveJar(".*jolokia-jvm-.*-agent\\.jar$") }
|
||||
|
||||
private fun NodeConfig.checkAndOverrideForInMemoryDB(): NodeConfig = this.run {
|
||||
if (inMemoryDB && corda.dataSourceProperties.getProperty("dataSource.url").startsWith("jdbc:h2:")) {
|
||||
val jdbcUrl = "jdbc:h2:mem:persistence${inMemoryCounter.getAndIncrement()};DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=10000;WRITE_DELAY=100"
|
||||
corda.dataSourceProperties.setProperty("dataSource.url", jdbcUrl)
|
||||
NodeConfig(typesafe = typesafe + mapOf("dataSourceProperties" to mapOf("dataSource.url" to jdbcUrl)), corda = corda)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveJar(jarNamePattern: String): String {
|
||||
return try {
|
||||
val cl = ClassLoader.getSystemClassLoader()
|
||||
@ -234,7 +249,7 @@ class DriverDSLImpl(
|
||||
baseDirectory = baseDirectory(name),
|
||||
allowMissingConfig = true,
|
||||
configOverrides = if (overrides.hasPath("devMode")) overrides else overrides + mapOf("devMode" to true)
|
||||
))
|
||||
)).checkAndOverrideForInMemoryDB()
|
||||
return startNodeInternal(config, webAddress, startInSameProcess, maximumHeapSize, localNetworkMap)
|
||||
}
|
||||
|
||||
@ -252,7 +267,7 @@ class DriverDSLImpl(
|
||||
"adminAddress" to portAllocation.nextHostAndPort().toString()
|
||||
),
|
||||
"devMode" to false)
|
||||
))
|
||||
)).checkAndOverrideForInMemoryDB()
|
||||
|
||||
val versionInfo = VersionInfo(1, "1", "1", "1")
|
||||
config.corda.certificatesDirectory.createDirectories()
|
||||
@ -375,7 +390,7 @@ class DriverDSLImpl(
|
||||
configOverrides = rawConfig.toNodeOnly()
|
||||
)
|
||||
val cordaConfig = typesafe.parseAsNodeConfiguration()
|
||||
val config = NodeConfig(rawConfig, cordaConfig)
|
||||
val config = NodeConfig(rawConfig, cordaConfig).checkAndOverrideForInMemoryDB()
|
||||
return startNodeInternal(config, webAddress, null, "512m", localNetworkMap)
|
||||
}
|
||||
|
||||
@ -1056,7 +1071,8 @@ fun <DI : DriverDSL, D : InternalDriverDSL, A> genericDriver(
|
||||
notarySpecs = defaultParameters.notarySpecs,
|
||||
compatibilityZone = null,
|
||||
networkParameters = defaultParameters.networkParameters,
|
||||
notaryCustomOverrides = defaultParameters.notaryCustomOverrides
|
||||
notaryCustomOverrides = defaultParameters.notaryCustomOverrides,
|
||||
inMemoryDB = defaultParameters.inMemoryDB
|
||||
)
|
||||
)
|
||||
val shutdownHook = addShutdownHook(driverDsl::shutdown)
|
||||
@ -1135,6 +1151,7 @@ fun <A> internalDriver(
|
||||
networkParameters: NetworkParameters = DriverParameters().networkParameters,
|
||||
compatibilityZone: CompatibilityZoneParams? = null,
|
||||
notaryCustomOverrides: Map<String, Any?> = DriverParameters().notaryCustomOverrides,
|
||||
inMemoryDB: Boolean = DriverParameters().inMemoryDB,
|
||||
dsl: DriverDSLImpl.() -> A
|
||||
): A {
|
||||
return genericDriver(
|
||||
@ -1152,7 +1169,8 @@ fun <A> internalDriver(
|
||||
jmxPolicy = jmxPolicy,
|
||||
compatibilityZone = compatibilityZone,
|
||||
networkParameters = networkParameters,
|
||||
notaryCustomOverrides = notaryCustomOverrides
|
||||
notaryCustomOverrides = notaryCustomOverrides,
|
||||
inMemoryDB = inMemoryDB
|
||||
),
|
||||
coerce = { it },
|
||||
dsl = dsl,
|
||||
|
@ -115,6 +115,7 @@ fun <A> rpcDriver(
|
||||
jmxPolicy: JmxPolicy = JmxPolicy(),
|
||||
networkParameters: NetworkParameters = testNetworkParameters(),
|
||||
notaryCustomOverrides: Map<String, Any?> = emptyMap(),
|
||||
inMemoryDB: Boolean = true,
|
||||
dsl: RPCDriverDSL.() -> A
|
||||
): A {
|
||||
return genericDriver(
|
||||
@ -133,7 +134,8 @@ fun <A> rpcDriver(
|
||||
jmxPolicy = jmxPolicy,
|
||||
compatibilityZone = null,
|
||||
networkParameters = networkParameters,
|
||||
notaryCustomOverrides = notaryCustomOverrides
|
||||
notaryCustomOverrides = notaryCustomOverrides,
|
||||
inMemoryDB = inMemoryDB
|
||||
), externalTrace
|
||||
),
|
||||
coerce = { it },
|
||||
|
Reference in New Issue
Block a user