mirror of
https://github.com/corda/corda.git
synced 2025-03-23 04:25:19 +00:00
INFRA-749 Shut down and delete test H2 databases (#6739)
This commit is contained in:
parent
b6cd4fa997
commit
88a205600d
@ -13,11 +13,12 @@ object DatabaseSnapshot {
|
|||||||
return resourceUri.openStream()
|
return resourceUri.openStream()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun databaseFilename(baseDirectory: Path) = baseDirectory.resolve(databaseName)
|
||||||
|
|
||||||
fun copyDatabaseSnapshot(baseDirectory: Path) {
|
fun copyDatabaseSnapshot(baseDirectory: Path) {
|
||||||
getDatabaseSnapshotStream().use { stream ->
|
getDatabaseSnapshotStream().use { stream ->
|
||||||
Files.createDirectories(baseDirectory)
|
Files.createDirectories(baseDirectory)
|
||||||
val path = baseDirectory.resolve(databaseName)
|
Files.copy(stream, databaseFilename(baseDirectory))
|
||||||
Files.copy(stream, path)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,6 +36,7 @@ import net.corda.core.internal.cordapp.CordappImpl.Companion.MIN_PLATFORM_VERSIO
|
|||||||
import net.corda.core.internal.cordapp.CordappImpl.Companion.TARGET_PLATFORM_VERSION
|
import net.corda.core.internal.cordapp.CordappImpl.Companion.TARGET_PLATFORM_VERSION
|
||||||
import net.corda.core.internal.cordapp.get
|
import net.corda.core.internal.cordapp.get
|
||||||
import net.corda.core.internal.createDirectories
|
import net.corda.core.internal.createDirectories
|
||||||
|
import net.corda.core.internal.deleteIfExists
|
||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.internal.isRegularFile
|
import net.corda.core.internal.isRegularFile
|
||||||
import net.corda.core.internal.list
|
import net.corda.core.internal.list
|
||||||
@ -57,6 +58,7 @@ import net.corda.core.utilities.toHexString
|
|||||||
import net.corda.coretesting.internal.stubs.CertificateStoreStubs
|
import net.corda.coretesting.internal.stubs.CertificateStoreStubs
|
||||||
import net.corda.node.NodeRegistrationOption
|
import net.corda.node.NodeRegistrationOption
|
||||||
import net.corda.node.VersionInfo
|
import net.corda.node.VersionInfo
|
||||||
|
import net.corda.node.internal.DataSourceFactory
|
||||||
import net.corda.node.internal.Node
|
import net.corda.node.internal.Node
|
||||||
import net.corda.node.internal.NodeWithInfo
|
import net.corda.node.internal.NodeWithInfo
|
||||||
import net.corda.node.internal.clientSslOptionsCompatibleWith
|
import net.corda.node.internal.clientSslOptionsCompatibleWith
|
||||||
@ -272,14 +274,17 @@ class DriverDSLImpl(
|
|||||||
val name = parameters.providedName ?: CordaX500Name("${oneOf(names).organisation}-${p2pAddress.port}", "London", "GB")
|
val name = parameters.providedName ?: CordaX500Name("${oneOf(names).organisation}-${p2pAddress.port}", "London", "GB")
|
||||||
|
|
||||||
val config = createConfig(name, parameters, p2pAddress)
|
val config = createConfig(name, parameters, p2pAddress)
|
||||||
if (premigrateH2Database && isH2Database(config)) {
|
if (isH2Database(config) && !inMemoryDB) {
|
||||||
if (!inMemoryDB) {
|
if (premigrateH2Database) {
|
||||||
try {
|
try {
|
||||||
DatabaseSnapshot.copyDatabaseSnapshot(config.corda.baseDirectory)
|
DatabaseSnapshot.copyDatabaseSnapshot(config.corda.baseDirectory)
|
||||||
} catch (ex: java.nio.file.FileAlreadyExistsException) {
|
} catch (ex: java.nio.file.FileAlreadyExistsException) {
|
||||||
log.warn("Database already exists on disk, not attempting to pre-migrate database.")
|
log.warn("Database already exists on disk, not attempting to pre-migrate database.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
shutdownManager.registerShutdown {
|
||||||
|
shutdownAndDeleteDatabase(config.corda)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val registrationFuture = if (compatibilityZone?.rootCert != null) {
|
val registrationFuture = if (compatibilityZone?.rootCert != null) {
|
||||||
// We don't need the network map to be available to be able to register the node
|
// We don't need the network map to be available to be able to register the node
|
||||||
@ -1142,6 +1147,17 @@ class DriverDSLImpl(
|
|||||||
private fun Map<String, Any>.removeResolvedClasspath(): Map<String, Any> {
|
private fun Map<String, Any>.removeResolvedClasspath(): Map<String, Any> {
|
||||||
return filterNot { it.key == "java.class.path" }
|
return filterNot { it.key == "java.class.path" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun shutdownAndDeleteDatabase(config: NodeConfiguration) {
|
||||||
|
DataSourceFactory.createDataSource(config.dataSourceProperties).also { dataSource ->
|
||||||
|
dataSource.connection.use { connection ->
|
||||||
|
connection.createStatement().use { statement ->
|
||||||
|
statement.execute("SHUTDOWN")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DatabaseSnapshot.databaseFilename(config.baseDirectory).deleteIfExists()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import net.corda.core.internal.NetworkParametersStorage
|
|||||||
import net.corda.core.internal.PLATFORM_VERSION
|
import net.corda.core.internal.PLATFORM_VERSION
|
||||||
import net.corda.core.internal.VisibleForTesting
|
import net.corda.core.internal.VisibleForTesting
|
||||||
import net.corda.core.internal.createDirectories
|
import net.corda.core.internal.createDirectories
|
||||||
|
import net.corda.core.internal.deleteIfExists
|
||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.internal.notary.NotaryService
|
import net.corda.core.internal.notary.NotaryService
|
||||||
import net.corda.core.internal.uncheckedCast
|
import net.corda.core.internal.uncheckedCast
|
||||||
@ -64,6 +65,7 @@ import net.corda.nodeapi.internal.network.NetworkParametersCopier
|
|||||||
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
||||||
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
||||||
import net.corda.testing.common.internal.testNetworkParameters
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
|
import net.corda.testing.node.DatabaseSnapshot
|
||||||
import net.corda.testing.node.InMemoryMessagingNetwork
|
import net.corda.testing.node.InMemoryMessagingNetwork
|
||||||
import net.corda.testing.node.MockNetworkNotarySpec
|
import net.corda.testing.node.MockNetworkNotarySpec
|
||||||
import net.corda.testing.node.MockNetworkParameters
|
import net.corda.testing.node.MockNetworkParameters
|
||||||
@ -606,7 +608,10 @@ open class InternalMockNetwork(cordappPackages: List<String> = emptyList(),
|
|||||||
cordappClassLoader.use { _ ->
|
cordappClassLoader.use { _ ->
|
||||||
// Serialization env must be unset even if other parts of this method fail.
|
// Serialization env must be unset even if other parts of this method fail.
|
||||||
serializationEnv.use {
|
serializationEnv.use {
|
||||||
nodes.forEach { it.started?.dispose() }
|
nodes.forEach { node ->
|
||||||
|
node.started?.dispose()
|
||||||
|
DatabaseSnapshot.databaseFilename(node.configuration.baseDirectory).deleteIfExists()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
messagingNetwork.stop()
|
messagingNetwork.stop()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user