Skip to content

Commit cb03bf7

Browse files
committed
make loading more async
1 parent 44bb986 commit cb03bf7

File tree

5 files changed

+411
-353
lines changed

5 files changed

+411
-353
lines changed

freighter-tests/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ configurations {
3737

3838
dependencies {
3939
freighterTestCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
40-
freighterTestCompile "freighter:freighter-testing-core-junit5:0.7.3-TEST-SNAPSHOT"
40+
freighterTestCompile "freighter:freighter-testing-core-junit5:0.9.0-SNAPSHOT"
4141

4242
freighterTestCompile project(":contracts")
4343
freighterTestCompile project(":workflows")

freighter-tests/src/freighterTest/kotlin/freighter/testing/NullHolderOnObserverTest.kt

+2-8
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ class NullHolderOnObserverTest : DockerRemoteMachineBasedTest() {
6767
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.MS_SQL)
6868
}
6969

70-
@Test
71-
@OracleTest
72-
fun `tokens can be observed on node that does not know CI running oracle 12 r2`() {
73-
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.ORACLE_12_R2)
74-
}
75-
7670
private fun runTokensOnNodeRunningDatabase(db: DeploymentMachineProvider.DatabaseType) {
7771
val randomString = generateRandomString()
7872
val deploymentContext = DeploymentContext(machineProvider, nms, artifactoryUsername, artifactoryPassword)
@@ -83,7 +77,7 @@ class NullHolderOnObserverTest : DockerRemoteMachineBasedTest() {
8377
.withCordapp(modernCiV1)
8478
.withCordapp(freighterHelperCordapp)
8579
.withDatabase(machineProvider.requestDatabase(db))
86-
).withVersion(UnitOfDeployment.CORDA_4_6)
80+
).withVersion(UnitOfDeployment.CORDA_4_7)
8781
.deploy(deploymentContext)
8882

8983
val node2 = SingleNodeDeployment(
@@ -93,7 +87,7 @@ class NullHolderOnObserverTest : DockerRemoteMachineBasedTest() {
9387
.withCordapp(modernCiV1)
9488
.withCordapp(freighterHelperCordapp)
9589
.withDatabase(machineProvider.requestDatabase(db))
96-
).withVersion(UnitOfDeployment.CORDA_4_6)
90+
).withVersion(UnitOfDeployment.CORDA_4_7)
9791
.deploy(deploymentContext)
9892

9993
val nodeMachine1 = node1.getOrThrow().nodeMachines.single()

modules/selection/src/main/kotlin/com.r3.corda.lib.tokens.selection/SelectionUtilities.kt

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ internal fun sortByStateRefAscending(): Sort {
1919
return Sort(setOf(Sort.SortColumn(sortAttribute, Sort.Direction.ASC)))
2020
}
2121

22+
internal fun sortByTimeStampAscending(): Sort {
23+
val sortAttribute = SortAttribute.Standard(Sort.VaultStateAttribute.RECORDED_TIME)
24+
return Sort(setOf(Sort.SortColumn(sortAttribute, Sort.Direction.ASC)))
25+
}
26+
2227
// Returns all held token amounts of a specified token with given issuer.
2328
// We need to discriminate on the token type as well as the symbol as different tokens might use the same symbols.
2429
@Suspendable

modules/selection/src/main/kotlin/com.r3.corda.lib.tokens.selection/memory/config/InMemorySelectionConfig.kt

+55-50
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,68 @@ import net.corda.core.cordapp.CordappConfigException
99
import net.corda.core.node.ServiceHub
1010
import org.slf4j.LoggerFactory
1111

12-
const val CACHE_SIZE_DEFAULT = 1024 // TODO Return good default, for now it's not wired, it will be done in separate PR.
12+
const val CACHE_SIZE_DEFAULT = 1024
13+
const val PAGE_SIZE_DEFAULT = 1024
1314

14-
data class InMemorySelectionConfig @JvmOverloads constructor(val enabled: Boolean,
15-
val indexingStrategies: List<VaultWatcherService.IndexingType>,
16-
val cacheSize: Int = CACHE_SIZE_DEFAULT) : StateSelectionConfig {
17-
companion object {
18-
private val logger = LoggerFactory.getLogger("inMemoryConfigSelectionLogger")
15+
data class InMemorySelectionConfig @JvmOverloads constructor(
16+
val enabled: Boolean,
17+
val indexingStrategies: List<VaultWatcherService.IndexingType>,
18+
val cacheSize: Int = CACHE_SIZE_DEFAULT,
19+
val pageSize: Int = 1000
20+
) : StateSelectionConfig {
21+
companion object {
22+
private val logger = LoggerFactory.getLogger("inMemoryConfigSelectionLogger")
1923

20-
@JvmStatic
21-
fun parse(config: CordappConfig): InMemorySelectionConfig {
22-
val enabled = if (!config.exists("stateSelection.inMemory.enabled")) {
23-
logger.warn("Did not detect a configuration for InMemory selection - enabling memory usage for token indexing. Please set stateSelection.inMemory.enabled to \"false\" to disable this")
24-
true
25-
} else {
26-
config.getBoolean("stateSelection.inMemory.enabled")
27-
}
28-
val cacheSize = config.getIntOrNull("stateSelection.inMemory.cacheSize")
29-
?: CACHE_SIZE_DEFAULT
30-
val indexingType = try {
31-
(config.get("stateSelection.inMemory.indexingStrategies") as List<Any>).map { VaultWatcherService.IndexingType.valueOf(it.toString()) }
32-
} catch (e: CordappConfigException) {
33-
logger.warn("No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens")
34-
emptyList<VaultWatcherService.IndexingType>()
35-
} catch (e: ClassCastException) {
36-
logger.warn("No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens")
37-
emptyList<VaultWatcherService.IndexingType>()
38-
}
39-
logger.info("Found in memory token selection configuration with values indexing strategy: $indexingType, cacheSize: $cacheSize")
40-
return InMemorySelectionConfig(enabled, indexingType, cacheSize)
41-
}
24+
@JvmStatic
25+
fun parse(config: CordappConfig): InMemorySelectionConfig {
26+
val enabled = if (!config.exists("stateSelection.inMemory.enabled")) {
27+
logger.warn("Did not detect a configuration for InMemory selection - enabling memory usage for token indexing. Please set stateSelection.inMemory.enabled to \"false\" to disable this")
28+
true
29+
} else {
30+
config.getBoolean("stateSelection.inMemory.enabled")
31+
}
32+
val cacheSize = config.getIntOrNull("stateSelection.inMemory.cacheSize")
33+
?: CACHE_SIZE_DEFAULT
34+
val pageSize: Int = config.getIntOrNull("stateSelection.inMemory.cacheSize")?: PAGE_SIZE_DEFAULT
35+
val indexingType = try {
36+
(config.get("stateSelection.inMemory.indexingStrategies") as List<Any>).map { VaultWatcherService.IndexingType.valueOf(it.toString()) }
37+
} catch (e: CordappConfigException) {
38+
logger.warn("No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens")
39+
emptyList<VaultWatcherService.IndexingType>()
40+
} catch (e: ClassCastException) {
41+
logger.warn("No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens")
42+
emptyList<VaultWatcherService.IndexingType>()
43+
}
44+
logger.info("Found in memory token selection configuration with values indexing strategy: $indexingType, cacheSize: $cacheSize")
45+
return InMemorySelectionConfig(enabled, indexingType, cacheSize, pageSize)
46+
}
4247

43-
fun defaultConfig(): InMemorySelectionConfig {
44-
return InMemorySelectionConfig(true, emptyList())
45-
}
46-
}
48+
fun defaultConfig(): InMemorySelectionConfig {
49+
return InMemorySelectionConfig(true, emptyList())
50+
}
51+
}
4752

48-
@Suspendable
49-
override fun toSelector(services: ServiceHub): LocalTokenSelector {
50-
return try {
51-
val vaultObserver = services.cordaService(VaultWatcherService::class.java)
52-
LocalTokenSelector(services, vaultObserver, state = null)
53-
} catch (e: IllegalArgumentException) {
54-
throw IllegalArgumentException("Couldn't find VaultWatcherService in CordaServices, please make sure that it was installed in node.")
55-
}
56-
}
53+
@Suspendable
54+
override fun toSelector(services: ServiceHub): LocalTokenSelector {
55+
return try {
56+
val vaultObserver = services.cordaService(VaultWatcherService::class.java)
57+
LocalTokenSelector(services, vaultObserver, state = null)
58+
} catch (e: IllegalArgumentException) {
59+
throw IllegalArgumentException("Couldn't find VaultWatcherService in CordaServices, please make sure that it was installed in node.")
60+
}
61+
}
5762
}
5863

5964
// Helpers for configuration parsing.
6065

6166
fun CordappConfig.getIntOrNull(path: String): Int? {
62-
return try {
63-
getInt(path)
64-
} catch (e: CordappConfigException) {
65-
if (exists(path)) {
66-
throw IllegalArgumentException("Provide correct database selection configuration for config path: $path")
67-
} else {
68-
null
69-
}
70-
}
67+
return try {
68+
getInt(path)
69+
} catch (e: CordappConfigException) {
70+
if (exists(path)) {
71+
throw IllegalArgumentException("Provide correct database selection configuration for config path: $path")
72+
} else {
73+
null
74+
}
75+
}
7176
}

0 commit comments

Comments
 (0)