Skip to content

Commit

Permalink
fetchSize config (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
arndey authored Dec 15, 2023
1 parent 4d74923 commit 3d8f56b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import jp.co.soramitsu.iroha2.generated.AssetDefinitionId
import jp.co.soramitsu.iroha2.generated.AssetId
import jp.co.soramitsu.iroha2.generated.AssetValue
import jp.co.soramitsu.iroha2.generated.AssetValueType
import jp.co.soramitsu.iroha2.generated.BatchedResponseOfValue
import jp.co.soramitsu.iroha2.generated.BatchedResponseV1OfValue
import jp.co.soramitsu.iroha2.generated.DomainId
import jp.co.soramitsu.iroha2.generated.IdBox
import jp.co.soramitsu.iroha2.generated.InstructionExpr
import jp.co.soramitsu.iroha2.generated.Metadata
import jp.co.soramitsu.iroha2.generated.Name
import jp.co.soramitsu.iroha2.generated.PermissionToken
Expand Down Expand Up @@ -66,6 +69,9 @@ import java.math.RoundingMode
import java.security.SecureRandom
import java.time.Instant
import java.util.UUID
import kotlin.reflect.full.callSuspend
import kotlin.reflect.full.declaredMemberFunctions
import kotlin.reflect.jvm.isAccessible
import kotlin.test.assertEquals
import kotlin.test.assertFails
import kotlin.test.assertFailsWith
Expand Down Expand Up @@ -936,6 +942,51 @@ class InstructionsTest : IrohaTest<Iroha2Client>() {
}
}

@Test
@WithIroha([DefaultGenesis::class], fetchSize = 111)
fun `iroha respond with given fetch size`(): Unit = runBlocking {
val fetchSize = 111
repeat(2) { i ->
val isi = mutableListOf<InstructionExpr>()
val tx = TransactionBuilder {
account(ALICE_ACCOUNT_ID)
}
repeat(100) { j ->
val definitionId = AssetDefinitionId("ASSET_${j}_$i".asName(), DEFAULT_DOMAIN_ID)
isi.add(Instructions.registerAssetDefinition(definitionId, AssetValueType.Store()))
isi.add(
Instructions.setKeyValue(
AssetId(definitionId, ALICE_ACCOUNT_ID),
randomAlphabetic(10).asName(),
randomAlphabetic(100).asValue(),
),
)
}
tx.instructions(isi)

client.sendTransaction { tx.buildSigned(ALICE_KEYPAIR) }.let {
withTimeout(txTimeout) {
it.await()
}
}
}

val query = QueryBuilder.findAllAssets()
.account(ALICE_ACCOUNT_ID)
.buildSigned(ALICE_KEYPAIR)
val method = Iroha2Client::class.declaredMemberFunctions.firstOrNull { it.name == "sendQueryRequest" }

val response = method?.let {
it.isAccessible = true
it.callSuspend(client, query, null, null, null, null)
}
val vec = response?.cast<BatchedResponseOfValue.V1>()?.batchedResponseV1OfValue
?.cast<BatchedResponseV1OfValue>()?.batch
?.cast<Value.Vec>()?.vec

assertEquals(fetchSize, vec?.size)
}

@Test
@WithIroha([DefaultGenesis::class])
@Feature("Domains")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class IrohaConfig(
var waitStrategy: Boolean = true,
var submitGenesis: Boolean = true,
var envs: Map<String, String> = emptyMap(),
var fetchSize: Int = 10,
) {
companion object {
const val P2P_PORT_IDX = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ open class IrohaContainer : GenericContainer<IrohaContainer> {
.withEnv("TORII_P2P_ADDR", "${config.alias}:$p2pPort")
.withEnv("TORII_API_URL", "${config.alias}:$apiPort")
.withEnv("TORII_TELEMETRY_URL", "${config.alias}:$telemetryPort")
.withEnv("TORII_FETCH_SIZE", config.fetchSize.toString())
.withEnv("WSV_WASM_RUNTIME_CONFIG", "{\"FUEL_LIMIT\":20000000, \"MAX_MEMORY\": 524288000}")
.also { container -> config.envs.forEach { (k, v) -> container.withEnv(k, v) } }
.withExposedPorts(p2pPort, apiPort, telemetryPort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,24 @@ class IrohaRunnerExtension : InvocationInterceptor, BeforeEachCallback {
async {
val p2pPort = portsList[n][IrohaConfig.P2P_PORT_IDX]
val container = IrohaContainer {
networkToJoin = network
this.networkToJoin = network
when {
withIroha.source.isNotEmpty() -> genesisPath = withIroha.source
else -> genesis = withIroha.sources.map { it.createInstance() }.toSingle()
}
alias = IrohaContainer.NETWORK_ALIAS + p2pPort
keyPair = keyPairs[n]
this.alias = IrohaContainer.NETWORK_ALIAS + p2pPort
this.keyPair = keyPairs[n]
this.genesisKeyPair = genesisKeyPair
trustedPeers = peerIds
ports = portsList[n]
envs = withIroha.configs.associate { config ->
this.trustedPeers = peerIds
this.ports = portsList[n]
this.fetchSize = withIroha.fetchSize
this.envs = withIroha.configs.associate { config ->
config.split(IROHA_CONFIG_DELIMITER).let {
it.first() to it.last()
}
}
// only first peer should have --submit-genesis in peer start command
submitGenesis = n == 0
this.submitGenesis = n == 0
}
container.start()
containers.add(container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ annotation class WithIroha(
val configs: Array<String> = [],
val source: String = "",
val amount: Int = 1,
val fetchSize: Int = 10,
)

@MustBeDocumented
Expand Down

0 comments on commit 3d8f56b

Please sign in to comment.