Skip to content

Commit

Permalink
make loading more async
Browse files Browse the repository at this point in the history
  • Loading branch information
roastario committed Dec 3, 2021
1 parent 44bb986 commit cb03bf7
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 353 deletions.
2 changes: 1 addition & 1 deletion freighter-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ configurations {

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

freighterTestCompile project(":contracts")
freighterTestCompile project(":workflows")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ class NullHolderOnObserverTest : DockerRemoteMachineBasedTest() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.MS_SQL)
}

@Test
@OracleTest
fun `tokens can be observed on node that does not know CI running oracle 12 r2`() {
runTokensOnNodeRunningDatabase(DeploymentMachineProvider.DatabaseType.ORACLE_12_R2)
}

private fun runTokensOnNodeRunningDatabase(db: DeploymentMachineProvider.DatabaseType) {
val randomString = generateRandomString()
val deploymentContext = DeploymentContext(machineProvider, nms, artifactoryUsername, artifactoryPassword)
Expand All @@ -83,7 +77,7 @@ class NullHolderOnObserverTest : DockerRemoteMachineBasedTest() {
.withCordapp(modernCiV1)
.withCordapp(freighterHelperCordapp)
.withDatabase(machineProvider.requestDatabase(db))
).withVersion(UnitOfDeployment.CORDA_4_6)
).withVersion(UnitOfDeployment.CORDA_4_7)
.deploy(deploymentContext)

val node2 = SingleNodeDeployment(
Expand All @@ -93,7 +87,7 @@ class NullHolderOnObserverTest : DockerRemoteMachineBasedTest() {
.withCordapp(modernCiV1)
.withCordapp(freighterHelperCordapp)
.withDatabase(machineProvider.requestDatabase(db))
).withVersion(UnitOfDeployment.CORDA_4_6)
).withVersion(UnitOfDeployment.CORDA_4_7)
.deploy(deploymentContext)

val nodeMachine1 = node1.getOrThrow().nodeMachines.single()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ internal fun sortByStateRefAscending(): Sort {
return Sort(setOf(Sort.SortColumn(sortAttribute, Sort.Direction.ASC)))
}

internal fun sortByTimeStampAscending(): Sort {
val sortAttribute = SortAttribute.Standard(Sort.VaultStateAttribute.RECORDED_TIME)
return Sort(setOf(Sort.SortColumn(sortAttribute, Sort.Direction.ASC)))
}

// Returns all held token amounts of a specified token with given issuer.
// We need to discriminate on the token type as well as the symbol as different tokens might use the same symbols.
@Suspendable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,68 @@ import net.corda.core.cordapp.CordappConfigException
import net.corda.core.node.ServiceHub
import org.slf4j.LoggerFactory

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

data class InMemorySelectionConfig @JvmOverloads constructor(val enabled: Boolean,
val indexingStrategies: List<VaultWatcherService.IndexingType>,
val cacheSize: Int = CACHE_SIZE_DEFAULT) : StateSelectionConfig {
companion object {
private val logger = LoggerFactory.getLogger("inMemoryConfigSelectionLogger")
data class InMemorySelectionConfig @JvmOverloads constructor(
val enabled: Boolean,
val indexingStrategies: List<VaultWatcherService.IndexingType>,
val cacheSize: Int = CACHE_SIZE_DEFAULT,
val pageSize: Int = 1000
) : StateSelectionConfig {
companion object {
private val logger = LoggerFactory.getLogger("inMemoryConfigSelectionLogger")

@JvmStatic
fun parse(config: CordappConfig): InMemorySelectionConfig {
val enabled = if (!config.exists("stateSelection.inMemory.enabled")) {
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")
true
} else {
config.getBoolean("stateSelection.inMemory.enabled")
}
val cacheSize = config.getIntOrNull("stateSelection.inMemory.cacheSize")
?: CACHE_SIZE_DEFAULT
val indexingType = try {
(config.get("stateSelection.inMemory.indexingStrategies") as List<Any>).map { VaultWatcherService.IndexingType.valueOf(it.toString()) }
} catch (e: CordappConfigException) {
logger.warn("No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens")
emptyList<VaultWatcherService.IndexingType>()
} catch (e: ClassCastException) {
logger.warn("No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens")
emptyList<VaultWatcherService.IndexingType>()
}
logger.info("Found in memory token selection configuration with values indexing strategy: $indexingType, cacheSize: $cacheSize")
return InMemorySelectionConfig(enabled, indexingType, cacheSize)
}
@JvmStatic
fun parse(config: CordappConfig): InMemorySelectionConfig {
val enabled = if (!config.exists("stateSelection.inMemory.enabled")) {
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")
true
} else {
config.getBoolean("stateSelection.inMemory.enabled")
}
val cacheSize = config.getIntOrNull("stateSelection.inMemory.cacheSize")
?: CACHE_SIZE_DEFAULT
val pageSize: Int = config.getIntOrNull("stateSelection.inMemory.cacheSize")?: PAGE_SIZE_DEFAULT
val indexingType = try {
(config.get("stateSelection.inMemory.indexingStrategies") as List<Any>).map { VaultWatcherService.IndexingType.valueOf(it.toString()) }
} catch (e: CordappConfigException) {
logger.warn("No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens")
emptyList<VaultWatcherService.IndexingType>()
} catch (e: ClassCastException) {
logger.warn("No indexing method specified. Indexes will be created at run-time for each invocation of selectTokens")
emptyList<VaultWatcherService.IndexingType>()
}
logger.info("Found in memory token selection configuration with values indexing strategy: $indexingType, cacheSize: $cacheSize")
return InMemorySelectionConfig(enabled, indexingType, cacheSize, pageSize)
}

fun defaultConfig(): InMemorySelectionConfig {
return InMemorySelectionConfig(true, emptyList())
}
}
fun defaultConfig(): InMemorySelectionConfig {
return InMemorySelectionConfig(true, emptyList())
}
}

@Suspendable
override fun toSelector(services: ServiceHub): LocalTokenSelector {
return try {
val vaultObserver = services.cordaService(VaultWatcherService::class.java)
LocalTokenSelector(services, vaultObserver, state = null)
} catch (e: IllegalArgumentException) {
throw IllegalArgumentException("Couldn't find VaultWatcherService in CordaServices, please make sure that it was installed in node.")
}
}
@Suspendable
override fun toSelector(services: ServiceHub): LocalTokenSelector {
return try {
val vaultObserver = services.cordaService(VaultWatcherService::class.java)
LocalTokenSelector(services, vaultObserver, state = null)
} catch (e: IllegalArgumentException) {
throw IllegalArgumentException("Couldn't find VaultWatcherService in CordaServices, please make sure that it was installed in node.")
}
}
}

// Helpers for configuration parsing.

fun CordappConfig.getIntOrNull(path: String): Int? {
return try {
getInt(path)
} catch (e: CordappConfigException) {
if (exists(path)) {
throw IllegalArgumentException("Provide correct database selection configuration for config path: $path")
} else {
null
}
}
return try {
getInt(path)
} catch (e: CordappConfigException) {
if (exists(path)) {
throw IllegalArgumentException("Provide correct database selection configuration for config path: $path")
} else {
null
}
}
}
Loading

0 comments on commit cb03bf7

Please sign in to comment.