diff --git a/core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt b/core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt index b12ea8353d..dd76afb644 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/KotlinUtils.kt @@ -14,7 +14,7 @@ import kotlin.reflect.KProperty // READ ME FIRST: // This is a collection of public utilities useful only for Kotlin code. Think carefully before adding anything here and // make sure it's tested and documented. If you're looking to add a public utility that is also relevant to Java then -// don't put it here but in a seperate file called Utils.kt +// don't put it here but in a separate file called Utils.kt // /** Like the + operator but throws [ArithmeticException] in case of integer overflow. */ diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt index 50daaa1d8d..025d0bc94e 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt @@ -16,6 +16,7 @@ import net.corda.core.utilities.loggerFor import net.corda.node.internal.classloading.requireAnnotation import net.corda.node.services.config.NodeConfiguration import net.corda.nodeapi.internal.serialization.DefaultWhitelist +import org.apache.commons.collections4.map.LRUMap import java.io.File import java.io.FileOutputStream import java.lang.reflect.Modifier @@ -67,6 +68,9 @@ class CordappLoader private constructor(private val cordappJarPaths: List, CordappLoader>(1000) + /** * Create a dev mode CordappLoader for test environments that creates and loads cordapps from the classpath * and cordapps directory. This is intended mostly for use by the driver. @@ -77,7 +81,8 @@ class CordappLoader private constructor(private val cordappJarPaths: List): CordappLoader { check(configuration.devMode) { "Package scanning can only occur in dev mode" } - return CordappLoader(getCordappsInDirectory(getCordappsPath(configuration.baseDirectory)) + testPackages.flatMap(this::createScanPackage)) + val paths = getCordappsInDirectory(getCordappsPath(configuration.baseDirectory)) + testPackages.flatMap(this::createScanPackage) + return cordappLoadersCache.computeIfAbsent(paths, { CordappLoader(paths) }) } /** @@ -89,7 +94,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List) - = CordappLoader(testPackages.flatMap(this::createScanPackage)) + = cordappLoadersCache.computeIfAbsent(testPackages, { CordappLoader(testPackages.flatMap(this::createScanPackage)) }) /** * Creates a dev mode CordappLoader intended only to be used in test environments @@ -242,9 +247,12 @@ class CordappLoader private constructor(private val cordappJarPaths: List(1000) private fun scanCordapp(cordappJarPath: RestrictedURL): RestrictedScanResult { logger.info("Scanning CorDapp in $cordappJarPath") - return RestrictedScanResult(FastClasspathScanner().addClassLoader(appClassLoader).overrideClasspath(cordappJarPath.url).scan(), cordappJarPath.qualifiedNamePrefix) + return cachedScanResult.computeIfAbsent(cordappJarPath, { + RestrictedScanResult(FastClasspathScanner().addClassLoader(appClassLoader).overrideClasspath(cordappJarPath.url).scan(), cordappJarPath.qualifiedNamePrefix) + }) } private class FlowTypeHierarchyComparator(val initiatingFlow: Class>) : Comparator>> { diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt index 0a51b019ab..3f45d3dd4c 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt @@ -169,7 +169,7 @@ class MockNetwork(defaultParameters: MockNetworkParameters = MockNetworkParamete * @see defaultNotaryNode */ val defaultNotaryIdentityAndCert: PartyAndCertificate get() { - return defaultNotaryNode.info.legalIdentitiesAndCerts.singleOrNull() ?: throw IllegalStateException("Default notary has multiple identities") + return defaultNotaryNode.info.legalIdentitiesAndCerts[1] // TODO Resolve once network parameters is merged back in } /**