From b188bfda52a82be26f3b7dda3afaffd3bf2c02d4 Mon Sep 17 00:00:00 2001 From: "rick.parker" Date: Tue, 1 Nov 2016 16:00:31 +0000 Subject: [PATCH] Speed up JDBCHashMapTestSuite by 3min on my laptop by avoiding Exposed table existence checks each time a map/table is created by re-using the map/sets across tests (after clear()-ing to reset their state). --- .../r3corda/node/utilities/JDBCHashMapTestSuite.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/node/src/integration-test/kotlin/com/r3corda/node/utilities/JDBCHashMapTestSuite.kt b/node/src/integration-test/kotlin/com/r3corda/node/utilities/JDBCHashMapTestSuite.kt index ff183b343c..3ee5f5504c 100644 --- a/node/src/integration-test/kotlin/com/r3corda/node/utilities/JDBCHashMapTestSuite.kt +++ b/node/src/integration-test/kotlin/com/r3corda/node/utilities/JDBCHashMapTestSuite.kt @@ -24,6 +24,10 @@ class JDBCHashMapTestSuite { lateinit var dataSource: Closeable lateinit var transaction: Transaction lateinit var database: Database + lateinit var loadOnInitFalseMap: JDBCHashMap + lateinit var loadOnInitTrueMap: JDBCHashMap + lateinit var loadOnInitFalseSet: JDBCHashSet + lateinit var loadOnInitTrueSet: JDBCHashSet @JvmStatic @BeforeClass @@ -32,6 +36,10 @@ class JDBCHashMapTestSuite { dataSource = dataSourceAndDatabase.first database = dataSourceAndDatabase.second setUpDatabaseTx() + loadOnInitFalseMap = JDBCHashMap("test_map_false", loadOnInit = false) + loadOnInitTrueMap = JDBCHashMap("test_map_true", loadOnInit = true) + loadOnInitFalseSet = JDBCHashSet("test_set_false", loadOnInit = false) + loadOnInitTrueSet = JDBCHashSet("test_set_true", loadOnInit = true) } @JvmStatic @@ -112,7 +120,8 @@ class JDBCHashMapTestSuite { */ class JDBCHashMapTestGenerator(val loadOnInit: Boolean) : com.google.common.collect.testing.TestStringMapGenerator() { override fun create(elements: Array>): Map { - val map = JDBCHashMap("test_map_${System.nanoTime()}", loadOnInit = loadOnInit) + val map = if (loadOnInit) loadOnInitTrueMap else loadOnInitFalseMap + map.clear() map.putAll(elements.associate { Pair(it.key, it.value) }) return map } @@ -143,7 +152,8 @@ class JDBCHashMapTestSuite { */ class JDBCHashSetTestGenerator(val loadOnInit: Boolean) : com.google.common.collect.testing.TestStringSetGenerator() { override fun create(elements: Array): Set { - val set = JDBCHashSet("test_set_${System.nanoTime()}", loadOnInit = loadOnInit) + val set = if (loadOnInit) loadOnInitTrueSet else loadOnInitFalseSet + set.clear() set.addAll(elements) return set }