[CORDA-860]: Retrieving state by recordTime.max() throws a cast exception (fixed) ()

This commit is contained in:
Michele Sollecito 2018-05-08 19:16:19 +07:00 committed by GitHub
parent 173d0f2ada
commit 5318c395ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 4 deletions
docs/source
changelog.rst
example-code/src/test/kotlin/net/corda/docs
node/src/main/kotlin/net/corda/node/services/vault
testing/test-utils

View File

@ -7,6 +7,8 @@ release, see :doc:`upgrade-notes`.
Unreleased
==========
* Fixed incorrect computation of ``totalStates`` from ``otherResults`` in ``NodeVaultService``.
* Refactor AMQP Serializer to pass context object down the serialization call hierarchy. Will allow per thread
extensions to be set and used by the RPC work (Observable Context Key)

View File

@ -1,15 +1,31 @@
package net.corda.docs
import net.corda.core.contracts.Amount
import net.corda.core.contracts.ContractState
import net.corda.core.identity.Party
import net.corda.core.node.services.queryBy
import net.corda.core.node.services.vault.DEFAULT_PAGE_NUM
import net.corda.core.node.services.vault.DEFAULT_PAGE_SIZE
import net.corda.core.node.services.vault.PageSpecification
import net.corda.core.node.services.vault.QueryCriteria
import net.corda.core.node.services.vault.builder
import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.getOrThrow
import net.corda.finance.*
import net.corda.docs.java.tutorial.helloworld.IOUFlow
import net.corda.finance.CHF
import net.corda.finance.DOLLARS
import net.corda.finance.GBP
import net.corda.finance.POUNDS
import net.corda.finance.SWISS_FRANCS
import net.corda.finance.USD
import net.corda.finance.contracts.getCashBalances
import net.corda.finance.flows.CashIssueFlow
import net.corda.node.services.vault.VaultSchemaV1
import net.corda.testing.core.singleIdentity
import net.corda.testing.node.MockNetwork
import net.corda.testing.node.StartedMockNode
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatCode
import org.junit.After
import org.junit.Assert
import org.junit.Before
@ -24,7 +40,7 @@ class CustomVaultQueryTest {
@Before
fun setup() {
mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.finance", "net.corda.docs"))
mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.finance", "net.corda.docs", "com.template"))
nodeA = mockNet.createPartyNode()
nodeB = mockNet.createPartyNode()
nodeA.registerInitiatedFlow(TopupIssuerFlow.TopupIssuer::class.java)
@ -36,6 +52,22 @@ class CustomVaultQueryTest {
mockNet.stopNodes()
}
@Test
fun `query by max recorded time`() {
nodeA.startFlow(IOUFlow(1000, nodeB.info.singleIdentity())).getOrThrow()
nodeA.startFlow(IOUFlow(500, nodeB.info.singleIdentity())).getOrThrow()
val max = builder { VaultSchemaV1.VaultStates::recordedTime.max() }
val maxCriteria = QueryCriteria.VaultCustomQueryCriteria(max)
val results = nodeA.transaction {
val pageSpecification = PageSpecification(pageNumber = DEFAULT_PAGE_NUM, pageSize = DEFAULT_PAGE_SIZE)
nodeA.services.vaultService.queryBy<ContractState>(criteria = maxCriteria, paging = pageSpecification)
}
assertThatCode { results.otherResults.single() }.doesNotThrowAnyException()
}
@Test
fun `test custom vault query`() {
// issue some cash in several currencies
@ -82,4 +114,4 @@ class CustomVaultQueryTest {
return Pair(balancesNodesA, balancesNodesB)
}
}
}

View File

@ -395,7 +395,7 @@ class NodeVaultService(
val count = builder { VaultSchemaV1.VaultStates::recordedTime.count() }
val countCriteria = QueryCriteria.VaultCustomQueryCriteria(count, Vault.StateStatus.ALL)
val results = queryBy(contractStateType, criteria.and(countCriteria))
totalStates = results.otherResults[0] as Long
totalStates = results.otherResults.last() as Long
}
val session = getSession()

View File

@ -22,6 +22,7 @@ dependencies {
compile "junit:junit:$junit_version"
compile 'org.hamcrest:hamcrest-library:1.3'
compile "com.nhaarman:mockito-kotlin:1.1.0"
compile "org.assertj:assertj-core:$assertj_version"
// Guava: Google test library (collections test suite)
compile "com.google.guava:guava-testlib:$guava_version"