mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
Moved the various extension methods for creating Durations from Utils.kt to KotlinUtils.kt
This commit is contained in:
@ -7,7 +7,7 @@ import net.corda.core.contracts.DOLLARS
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.StartableByRPC
|
||||
import net.corda.core.messaging.startFlow
|
||||
import net.corda.core.minutes
|
||||
import net.corda.core.utilities.minutes
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.core.utilities.div
|
||||
|
@ -10,6 +10,7 @@ import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.node.internal.Node
|
||||
import net.corda.node.services.api.DEFAULT_SESSION_ID
|
||||
import net.corda.node.services.messaging.*
|
||||
|
@ -6,7 +6,7 @@ import net.corda.core.crypto.cert
|
||||
import net.corda.core.crypto.random63BitValue
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.core.utilities.NonEmptySet
|
||||
import net.corda.node.internal.NetworkMapInfo
|
||||
import net.corda.node.services.config.configureWithDevSSLCertificate
|
||||
|
@ -8,11 +8,7 @@ import net.corda.core.*
|
||||
import net.corda.core.messaging.RPCOps
|
||||
import net.corda.core.node.ServiceHub
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.core.utilities.parseNetworkHostAndPort
|
||||
import net.corda.core.utilities.trace
|
||||
import net.corda.core.utilities.*
|
||||
import net.corda.node.VersionInfo
|
||||
import net.corda.node.serialization.NodeClock
|
||||
import net.corda.node.services.RPCUserService
|
||||
|
@ -4,17 +4,15 @@ import net.corda.core.crypto.*
|
||||
import net.corda.core.identity.AnonymousParty
|
||||
import net.corda.core.identity.PartyAndCertificate
|
||||
import net.corda.core.node.services.IdentityService
|
||||
import net.corda.core.utilities.days
|
||||
import net.corda.flows.AnonymisedIdentity
|
||||
import org.bouncycastle.cert.X509CertificateHolder
|
||||
import org.bouncycastle.operator.ContentSigner
|
||||
import java.security.KeyPair
|
||||
import java.security.PublicKey
|
||||
import java.security.Security
|
||||
import java.security.cert.CertPath
|
||||
import java.security.cert.CertificateFactory
|
||||
import java.security.cert.X509Certificate
|
||||
import java.time.Duration
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Generates a new random [KeyPair], adds it to the internal key storage, then generates a corresponding
|
||||
@ -33,7 +31,7 @@ fun freshCertificate(identityService: IdentityService,
|
||||
issuerSigner: ContentSigner,
|
||||
revocationEnabled: Boolean = false): AnonymisedIdentity {
|
||||
val issuerCertificate = issuer.certificate
|
||||
val window = X509Utilities.getCertificateValidityWindow(Duration.ZERO, Duration.ofDays(10 * 365), issuerCertificate)
|
||||
val window = X509Utilities.getCertificateValidityWindow(Duration.ZERO, 3650.days, issuerCertificate)
|
||||
val ourCertificate = Crypto.createCertificate(CertificateType.IDENTITY, issuerCertificate.subject, issuerSigner, issuer.name, subjectPublicKey, window)
|
||||
val certFactory = CertificateFactory.getInstance("X509")
|
||||
val ourCertPath = certFactory.generateCertPath(listOf(ourCertificate.cert) + issuer.certPath.certificates)
|
||||
|
@ -11,9 +11,7 @@ import net.corda.core.internal.div
|
||||
import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.node.services.NetworkMapCache
|
||||
import net.corda.core.node.services.NetworkMapCache.MapChange
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.debug
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.core.utilities.*
|
||||
import net.corda.node.internal.Node
|
||||
import net.corda.node.services.RPCUserService
|
||||
import net.corda.node.services.config.NodeConfiguration
|
||||
|
@ -14,7 +14,7 @@ import com.google.common.collect.SetMultimap
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder
|
||||
import net.corda.core.crypto.random63BitValue
|
||||
import net.corda.core.messaging.RPCOps
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.core.serialization.KryoPoolWithContext
|
||||
import net.corda.core.utilities.*
|
||||
import net.corda.node.services.RPCUserService
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.corda.node.utilities.registration
|
||||
|
||||
import net.corda.core.*
|
||||
import net.corda.core.crypto.CertificateType
|
||||
import net.corda.core.crypto.Crypto
|
||||
import net.corda.core.crypto.X509Utilities
|
||||
@ -9,6 +8,7 @@ import net.corda.core.crypto.X509Utilities.CORDA_CLIENT_TLS
|
||||
import net.corda.core.crypto.X509Utilities.CORDA_ROOT_CA
|
||||
import net.corda.core.crypto.cert
|
||||
import net.corda.core.internal.*
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.node.services.config.NodeConfiguration
|
||||
import net.corda.node.utilities.*
|
||||
import org.bouncycastle.cert.path.CertPath
|
||||
|
@ -8,7 +8,6 @@ import net.corda.core.contracts.*
|
||||
import net.corda.core.crypto.DigitalSignature
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.sign
|
||||
import net.corda.core.crypto.toStringShort
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.InitiatedBy
|
||||
import net.corda.core.flows.InitiatingFlow
|
||||
@ -27,6 +26,7 @@ import net.corda.core.serialization.serialize
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.core.transactions.WireTransaction
|
||||
import net.corda.core.utilities.days
|
||||
import net.corda.core.utilities.toNonEmptySet
|
||||
import net.corda.core.utilities.unwrap
|
||||
import net.corda.flows.TwoPartyTradeFlow.Buyer
|
||||
|
@ -6,7 +6,7 @@ import net.corda.core.crypto.generateKeyPair
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.core.transactions.WireTransaction
|
||||
import net.corda.core.flows.NotaryChangeFlow
|
||||
import net.corda.core.flows.StateReplacementException
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.corda.node.services.events
|
||||
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.days
|
||||
import net.corda.core.utilities.days
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.FlowLogicRef
|
||||
import net.corda.core.flows.FlowLogicRefFactory
|
||||
|
@ -10,7 +10,7 @@ import net.corda.core.flows.NotaryException
|
||||
import net.corda.core.flows.NotaryFlow
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.node.internal.AbstractNode
|
||||
import net.corda.node.services.network.NetworkMapService
|
||||
|
@ -8,12 +8,12 @@ import net.corda.contracts.asset.DUMMY_CASH_ISSUER
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.crypto.entropyToKeyPair
|
||||
import net.corda.core.crypto.toBase58String
|
||||
import net.corda.core.days
|
||||
import net.corda.core.utilities.days
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.node.services.*
|
||||
import net.corda.core.node.services.vault.*
|
||||
import net.corda.core.node.services.vault.QueryCriteria.*
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.core.utilities.NonEmptySet
|
||||
|
@ -6,6 +6,8 @@ import co.paralleluniverse.fibers.Suspendable
|
||||
import co.paralleluniverse.strands.Strand
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.utilities.hours
|
||||
import net.corda.core.utilities.minutes
|
||||
import net.corda.testing.node.TestClock
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
@ -44,7 +46,7 @@ class ClockUtilsTest {
|
||||
|
||||
@Test
|
||||
fun `test waiting negative time for a deadline`() {
|
||||
assertFalse(stoppedClock.awaitWithDeadline(stoppedClock.instant().minus(Duration.ofHours(1))), "Should have reached deadline")
|
||||
assertFalse(stoppedClock.awaitWithDeadline(stoppedClock.instant().minus(1.hours)), "Should have reached deadline")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -56,13 +58,13 @@ class ClockUtilsTest {
|
||||
@Test
|
||||
fun `test waiting negative time for a deadline with incomplete future`() {
|
||||
val future = SettableFuture.create<Boolean>()
|
||||
assertFalse(stoppedClock.awaitWithDeadline(stoppedClock.instant().minus(Duration.ofHours(1)), future), "Should have reached deadline")
|
||||
assertFalse(stoppedClock.awaitWithDeadline(stoppedClock.instant().minus(1.hours), future), "Should have reached deadline")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `test waiting for a deadline with future completed before wait`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val future = SettableFuture.create<Boolean>()
|
||||
completeNow(future)
|
||||
assertTrue(stoppedClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline")
|
||||
@ -70,7 +72,7 @@ class ClockUtilsTest {
|
||||
|
||||
@Test
|
||||
fun `test waiting for a deadline with future completed after wait`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val future = SettableFuture.create<Boolean>()
|
||||
completeAfterWaiting(future)
|
||||
assertTrue(stoppedClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline")
|
||||
@ -78,38 +80,38 @@ class ClockUtilsTest {
|
||||
|
||||
@Test
|
||||
fun `test waiting for a deadline with clock advance`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
advanceClockAfterWait(testClock, Duration.ofHours(1))
|
||||
advanceClockAfterWait(testClock, 1.hours)
|
||||
assertFalse(testClock.awaitWithDeadline(advancedClock.instant()), "Should have reached deadline")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test waiting for a deadline with clock advance and incomplete future`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
val future = SettableFuture.create<Boolean>()
|
||||
advanceClockAfterWait(testClock, Duration.ofHours(1))
|
||||
advanceClockAfterWait(testClock, 1.hours)
|
||||
assertFalse(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should have reached deadline")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test waiting for a deadline with clock advance and complete future`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(2))
|
||||
val advancedClock = Clock.offset(stoppedClock, 2.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
val future = SettableFuture.create<Boolean>()
|
||||
advanceClockAfterWait(testClock, Duration.ofHours(1))
|
||||
advanceClockAfterWait(testClock, 1.hours)
|
||||
completeAfterWaiting(future)
|
||||
assertTrue(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should not have reached deadline")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test waiting for a deadline with multiple clock advance and incomplete future`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
val future = SettableFuture.create<Boolean>()
|
||||
for (advance in 1..6) {
|
||||
advanceClockAfterWait(testClock, Duration.ofMinutes(10))
|
||||
advanceClockAfterWait(testClock, 10.minutes)
|
||||
}
|
||||
assertFalse(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should have reached deadline")
|
||||
}
|
||||
@ -126,7 +128,7 @@ class ClockUtilsTest {
|
||||
}
|
||||
|
||||
val testClock = TestClock(stoppedClock)
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(10))
|
||||
val advancedClock = Clock.offset(stoppedClock, 10.hours)
|
||||
|
||||
try {
|
||||
testClock.awaitWithDeadline(advancedClock.instant(), SettableFuture.create<Boolean>())
|
||||
@ -138,7 +140,7 @@ class ClockUtilsTest {
|
||||
@Test
|
||||
@Suspendable
|
||||
fun `test waiting for a deadline with multiple clock advance and incomplete JDK8 future on Fibers`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
val future = CompletableFuture<Boolean>()
|
||||
val scheduler = FiberExecutorScheduler("test", executor)
|
||||
@ -151,7 +153,7 @@ class ClockUtilsTest {
|
||||
while (fiber.state != Strand.State.TIMED_WAITING) {
|
||||
Strand.sleep(1)
|
||||
}
|
||||
testClock.advanceBy(Duration.ofMinutes(10))
|
||||
testClock.advanceBy(10.minutes)
|
||||
}).start()
|
||||
}
|
||||
assertFalse(future.getOrThrow(), "Should have reached deadline")
|
||||
@ -160,7 +162,7 @@ class ClockUtilsTest {
|
||||
@Test
|
||||
@Suspendable
|
||||
fun `test waiting for a deadline with multiple clock advance and incomplete Guava future on Fibers`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
val future = SettableFuture.create<Boolean>()
|
||||
val scheduler = FiberExecutorScheduler("test", executor)
|
||||
@ -173,7 +175,7 @@ class ClockUtilsTest {
|
||||
while (fiber.state != Strand.State.TIMED_WAITING) {
|
||||
Strand.sleep(1)
|
||||
}
|
||||
testClock.advanceBy(Duration.ofMinutes(10))
|
||||
testClock.advanceBy(10.minutes)
|
||||
}).start()
|
||||
}
|
||||
assertFalse(future.getOrThrow(), "Should have reached deadline")
|
||||
|
@ -5,6 +5,8 @@ import co.paralleluniverse.fibers.Suspendable
|
||||
import co.paralleluniverse.strands.Strand
|
||||
import net.corda.core.RetryableException
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.utilities.hours
|
||||
import net.corda.core.utilities.minutes
|
||||
import net.corda.testing.node.TestClock
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
@ -50,7 +52,7 @@ class FiberBoxTest {
|
||||
|
||||
@Test
|
||||
fun `readWithDeadline with no wait`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
|
||||
mutex.write { integer = 1 }
|
||||
assertEquals(1, mutex.readWithDeadline(realClock, advancedClock.instant()) { integer })
|
||||
@ -58,7 +60,7 @@ class FiberBoxTest {
|
||||
|
||||
@Test
|
||||
fun `readWithDeadline with stopped clock and background write`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
|
||||
assertEquals(1, mutex.readWithDeadline(stoppedClock, advancedClock.instant()) {
|
||||
backgroundWrite()
|
||||
@ -68,22 +70,22 @@ class FiberBoxTest {
|
||||
|
||||
@Test(expected = TestRetryableException::class)
|
||||
fun `readWithDeadline with clock advanced`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
|
||||
assertEquals(1, mutex.readWithDeadline(testClock, advancedClock.instant()) {
|
||||
backgroundAdvanceClock(testClock, Duration.ofHours(1))
|
||||
backgroundAdvanceClock(testClock, 1.hours)
|
||||
if (integer == 1) 0 else throw TestRetryableException("Not 1")
|
||||
})
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `readWithDeadline with clock advanced 5x and background write`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
|
||||
assertEquals(5, mutex.readWithDeadline(testClock, advancedClock.instant()) {
|
||||
backgroundAdvanceClock(testClock, Duration.ofMinutes(10))
|
||||
backgroundAdvanceClock(testClock, 10.minutes)
|
||||
backgroundWrite()
|
||||
if (integer == 5) 5 else throw TestRetryableException("Not 5")
|
||||
})
|
||||
@ -97,7 +99,7 @@ class FiberBoxTest {
|
||||
@Test(expected = TestRetryableException::class)
|
||||
@Suspendable
|
||||
fun `readWithDeadline with clock advanced on Fibers`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
val future = CompletableFuture<Int>()
|
||||
val scheduler = FiberExecutorScheduler("test", executor)
|
||||
@ -116,7 +118,7 @@ class FiberBoxTest {
|
||||
while (fiber.state != Strand.State.TIMED_WAITING) {
|
||||
Strand.sleep(1)
|
||||
}
|
||||
testClock.advanceBy(Duration.ofMinutes(10))
|
||||
testClock.advanceBy(10.minutes)
|
||||
}).start()
|
||||
}
|
||||
assertEquals(2, future.getOrThrow())
|
||||
@ -130,7 +132,7 @@ class FiberBoxTest {
|
||||
@Test
|
||||
@Suspendable
|
||||
fun `readWithDeadline with background write on Fibers`() {
|
||||
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(1))
|
||||
val advancedClock = Clock.offset(stoppedClock, 1.hours)
|
||||
val testClock = TestClock(stoppedClock)
|
||||
val future = CompletableFuture<Int>()
|
||||
val scheduler = FiberExecutorScheduler("test", executor)
|
||||
|
Reference in New Issue
Block a user