diff --git a/.ci/api-current.txt b/.ci/api-current.txt index 52e9092d84..ec11b37730 100644 --- a/.ci/api-current.txt +++ b/.ci/api-current.txt @@ -6328,7 +6328,7 @@ public class net.corda.testing.node.MockServices extends java.lang.Object implem @NotNull public final net.corda.testing.services.MockAttachmentStorage getAttachments() @NotNull - public java.time.Clock getClock() + public net.corda.testing.node.TestClock getClock() @NotNull public net.corda.core.node.services.ContractUpgradeService getContractUpgradeService() @NotNull diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt index 980f79b29d..60a5628773 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -40,7 +40,7 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.ExpectedException import org.junit.rules.ExternalResource -import java.lang.Thread.sleep +import java.time.Duration import java.time.Instant import java.time.LocalDate import java.time.ZoneOffset @@ -198,7 +198,7 @@ abstract class VaultQueryTestsBase : VaultQueryParties { vaultFiller.fillWithSomeTestLinearStates(3, "ABC") val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // Total unconsumed states = 10 + 1 + 2 + 3 + 3 = 19 - sleep(delay) + services.clock.advanceBy(Duration.ofMillis(delay)) // consume some states vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList()) @@ -1806,12 +1806,11 @@ abstract class VaultQueryTestsBase : VaultQueryParties { // specifying Query on Linear state attributes @Test fun `unconsumed linear heads for linearId between two timestamps`() { - val start = Instant.now() - val end = start.plus(1, ChronoUnit.SECONDS) - database.transaction { + val start = services.clock.instant() vaultFiller.fillWithSomeTestLinearStates(1, "TEST") - sleep(1000) + services.clock.advanceBy(1.seconds) + val end = services.clock.instant() vaultFiller.fillWithSomeTestLinearStates(1, "TEST") // 2 unconsumed states with same external ID val recordedBetweenExpression = TimeCondition(TimeInstantType.RECORDED, builder { between(start, end) }) @@ -1842,13 +1841,12 @@ abstract class VaultQueryTestsBase : VaultQueryParties { // specifying Query on Linear state attributes @Test fun `unconsumed linear heads for linearId between two timestamps for a given external id`() { - val start = Instant.now() - val end = start.plus(1, ChronoUnit.SECONDS) - database.transaction { + val start = services.clock.instant() vaultFiller.fillWithSomeTestLinearStates(1, "TEST1") vaultFiller.fillWithSomeTestLinearStates(1, "TEST2") - sleep(1000) + services.clock.advanceBy(1.seconds) + val end = services.clock.instant() vaultFiller.fillWithSomeTestLinearStates(1, "TEST3") // 2 unconsumed states with same external ID diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt index 5b1d0c0362..c6d99267b4 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt @@ -230,7 +230,7 @@ open class MockServices private constructor( override val vaultService: VaultService get() = throw UnsupportedOperationException() override val contractUpgradeService: ContractUpgradeService get() = throw UnsupportedOperationException() override val networkMapCache: NetworkMapCache get() = throw UnsupportedOperationException() - override val clock: Clock get() = Clock.systemUTC() + override val clock: TestClock get() = TestClock(Clock.systemUTC()) override val myInfo: NodeInfo get() { return NodeInfo(listOf(NetworkHostAndPort("mock.node.services", 10000)), listOf(initialIdentity.identity), 1, serial = 1L) @@ -242,7 +242,7 @@ open class MockServices private constructor( protected val servicesForResolution: ServicesForResolution get() = ServicesForResolutionImpl(identityService, attachments, cordappProvider, networkParameters, validatedTransactions) internal fun makeVaultService(hibernateConfig: HibernateConfiguration, schemaService: SchemaService, database: CordaPersistence): VaultServiceInternal { - val vaultService = NodeVaultService(Clock.systemUTC(), keyManagementService, servicesForResolution, hibernateConfig, database) + val vaultService = NodeVaultService(clock, keyManagementService, servicesForResolution, hibernateConfig, database) HibernateObserver.install(vaultService.rawUpdates, hibernateConfig, schemaService) return vaultService }