Reformat files in testing

This commit is contained in:
Tommy Lillehagen
2017-10-06 15:32:23 +01:00
parent f98942d7ad
commit fcc4bdae7e
47 changed files with 1327 additions and 1269 deletions

View File

@ -117,8 +117,8 @@ fun freePort(): Int = freePortCounter.getAndAccumulate(0) { prev, _ -> 30000 + (
* to the Node, some other process else could allocate the returned ports.
*/
fun getFreeLocalPorts(hostName: String, numberToAlloc: Int): List<NetworkHostAndPort> {
val freePort = freePortCounter.getAndAccumulate(0) { prev, _ -> 30000 + (prev - 30000 + numberToAlloc) % 10000 }
return (freePort .. freePort + numberToAlloc - 1).map { NetworkHostAndPort(hostName, it) }
val freePort = freePortCounter.getAndAccumulate(0) { prev, _ -> 30000 + (prev - 30000 + numberToAlloc) % 10000 }
return (freePort..freePort + numberToAlloc - 1).map { NetworkHostAndPort(hostName, it) }
}
@JvmOverloads
@ -147,17 +147,17 @@ fun getTestPartyAndCertificate(name: CordaX500Name, publicKey: PublicKey, trustR
}
@Suppress("unused")
inline fun <reified T : Any> T.kryoSpecific(reason: String, function: () -> Unit) = if(!AMQP_ENABLED) {
inline fun <reified T : Any> T.kryoSpecific(reason: String, function: () -> Unit) = if (!AMQP_ENABLED) {
function()
} else {
loggerFor<T>().info("Ignoring Kryo specific test, reason: $reason" )
loggerFor<T>().info("Ignoring Kryo specific test, reason: $reason")
}
@Suppress("unused")
inline fun <reified T : Any> T.amqpSpecific(reason: String, function: () -> Unit) = if(AMQP_ENABLED) {
inline fun <reified T : Any> T.amqpSpecific(reason: String, function: () -> Unit) = if (AMQP_ENABLED) {
function()
} else {
loggerFor<T>().info("Ignoring AMQP specific test, reason: $reason" )
loggerFor<T>().info("Ignoring AMQP specific test, reason: $reason")
}
/**
@ -165,6 +165,7 @@ inline fun <reified T : Any> T.amqpSpecific(reason: String, function: () -> Unit
* TODO: Should be removed after multiple identities are introduced.
*/
fun NodeInfo.chooseIdentityAndCert(): PartyAndCertificate = legalIdentitiesAndCerts.first()
fun NodeInfo.chooseIdentity(): Party = chooseIdentityAndCert().party
/** Returns the identity of the first notary found on the network */
fun ServiceHub.getDefaultNotary(): Party = networkMapCache.notaryIdentities.first()

View File

@ -6,15 +6,16 @@ import java.time.Duration
* Ideas borrowed from "io.kotlintest" with some improvements made
* This is meant for use from Kotlin code use only mainly due to it's inline/reified nature
*/
inline fun <reified E : Throwable, R>eventually(duration: Duration, f: () -> R): R {
inline fun <reified E : Throwable, R> eventually(duration: Duration, f: () -> R): R {
val end = System.nanoTime() + duration.toNanos()
var times = 0
while (System.nanoTime() < end) {
try {
return f()
} catch (e: Throwable) {
when(e) {
is E -> {}// ignore and continue
when (e) {
is E -> {
}// ignore and continue
else -> throw e // unexpected exception type - rethrow
}
}

View File

@ -78,14 +78,15 @@ class FlowStackSnapshotFactoryImpl : FlowStackSnapshotFactory {
return FlowStackSnapshot(Instant.now(), flowClass.name, frames)
}
private val StackTraceElement.instrumentedAnnotation: Instrumented? get() {
Class.forName(className).methods.forEach {
if (it.name == methodName && it.isAnnotationPresent(Instrumented::class.java)) {
return it.getAnnotation(Instrumented::class.java)
private val StackTraceElement.instrumentedAnnotation: Instrumented?
get() {
Class.forName(className).methods.forEach {
if (it.name == methodName && it.isAnnotationPresent(Instrumented::class.java)) {
return it.getAnnotation(Instrumented::class.java)
}
}
return null
}
return null
}
private fun removeConstructorStackTraceElements(stackTrace: List<StackTraceElement>): List<StackTraceElement> {
val newStackTrace = ArrayList<StackTraceElement>()

View File

@ -12,10 +12,13 @@ import kotlin.reflect.jvm.reflect
fun <A : Any, R> measure(a: Iterable<A>, f: (A) -> R) =
measure(listOf(a), f.reflect()!!) { f(uncheckedCast(it[0])) }
fun <A : Any, B : Any, R> measure(a: Iterable<A>, b: Iterable<B>, f: (A, B) -> R) =
measure(listOf(a, b), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1])) }
fun <A : Any, B : Any, C : Any, R> measure(a: Iterable<A>, b: Iterable<B>, c: Iterable<C>, f: (A, B, C) -> R) =
measure(listOf(a, b, c), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1]), uncheckedCast(it[2])) }
fun <A : Any, B : Any, C : Any, D : Any, R> measure(a: Iterable<A>, b: Iterable<B>, c: Iterable<C>, d: Iterable<D>, f: (A, B, C, D) -> R) =
measure(listOf(a, b, c, d), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1]), uncheckedCast(it[2]), uncheckedCast(it[3])) }
@ -30,8 +33,8 @@ private fun <R> measure(paramIterables: List<Iterable<Any?>>, kCallable: KCallab
}
data class MeasureResult<out R>(
val parameters: List<Pair<String, Any?>>,
val result: R
val parameters: List<Pair<String, Any?>>,
val result: R
)
fun <A> iterateLexical(iterables: List<Iterable<A>>): Iterable<List<A>> {

View File

@ -22,32 +22,32 @@ fun initialiseTestSerialization() {
// Check that everything is configured for testing with mutable delegating instances.
try {
check(SerializationDefaults.SERIALIZATION_FACTORY is TestSerializationFactory)
} catch(e: IllegalStateException) {
} catch (e: IllegalStateException) {
SerializationDefaults.SERIALIZATION_FACTORY = TestSerializationFactory()
}
try {
check(SerializationDefaults.P2P_CONTEXT is TestSerializationContext)
} catch(e: IllegalStateException) {
} catch (e: IllegalStateException) {
SerializationDefaults.P2P_CONTEXT = TestSerializationContext()
}
try {
check(SerializationDefaults.RPC_SERVER_CONTEXT is TestSerializationContext)
} catch(e: IllegalStateException) {
} catch (e: IllegalStateException) {
SerializationDefaults.RPC_SERVER_CONTEXT = TestSerializationContext()
}
try {
check(SerializationDefaults.RPC_CLIENT_CONTEXT is TestSerializationContext)
} catch(e: IllegalStateException) {
} catch (e: IllegalStateException) {
SerializationDefaults.RPC_CLIENT_CONTEXT = TestSerializationContext()
}
try {
check(SerializationDefaults.STORAGE_CONTEXT is TestSerializationContext)
} catch(e: IllegalStateException) {
} catch (e: IllegalStateException) {
SerializationDefaults.STORAGE_CONTEXT = TestSerializationContext()
}
try {
check(SerializationDefaults.CHECKPOINT_CONTEXT is TestSerializationContext)
} catch(e: IllegalStateException) {
} catch (e: IllegalStateException) {
SerializationDefaults.CHECKPOINT_CONTEXT = TestSerializationContext()
}

View File

@ -274,7 +274,7 @@ data class TestLedgerDSLInterpreter private constructor(
transactionLabel: String?,
transactionBuilder: TransactionBuilder,
dsl: TransactionDSL<TestTransactionDSLInterpreter>.() -> Unit
) = recordTransactionWithTransactionMap(transactionLabel, transactionBuilder, dsl, nonVerifiedTransactionWithLocations, fillTransaction = true)
) = recordTransactionWithTransactionMap(transactionLabel, transactionBuilder, dsl, nonVerifiedTransactionWithLocations, fillTransaction = true)
override fun tweak(
dsl: LedgerDSL<TestTransactionDSLInterpreter,

View File

@ -119,7 +119,7 @@ class TransactionDSL<out T : TransactionDSLInterpreter>(val interpreter: T) : Tr
*/
@JvmOverloads
fun output(contractClassName: ContractClassName, contractState: ContractState, attachmentConstraint: AttachmentConstraint = AutomaticHashConstraint) =
_output(contractClassName,null, DUMMY_NOTARY, null, attachmentConstraint, contractState)
_output(contractClassName, null, DUMMY_NOTARY, null, attachmentConstraint, contractState)
/**
* Adds a command to the transaction.
@ -146,5 +146,5 @@ class TransactionDSL<out T : TransactionDSLInterpreter>(val interpreter: T) : Tr
*/
fun attachment(contractClassName: ContractClassName) = _attachment(contractClassName)
fun attachments(vararg contractClassNames: ContractClassName) = contractClassNames.forEach { attachment(it)}
fun attachments(vararg contractClassNames: ContractClassName) = contractClassNames.forEach { attachment(it) }
}

View File

@ -19,8 +19,7 @@ class DummyDealContract : Contract {
data class State(
override val participants: List<AbstractParty>,
override val linearId: UniqueIdentifier) : DealState, QueryableState
{
override val linearId: UniqueIdentifier) : DealState, QueryableState {
constructor(participants: List<AbstractParty> = listOf(),
ref: String) : this(participants, UniqueIdentifier(ref))

View File

@ -32,7 +32,7 @@ import java.util.*
@JvmOverloads
fun ServiceHub.fillWithSomeTestDeals(dealIds: List<String>,
participants: List<AbstractParty> = emptyList(),
notary: Party = DUMMY_NOTARY) : Vault<DealState> {
notary: Party = DUMMY_NOTARY): Vault<DealState> {
val myKey: PublicKey = myInfo.chooseIdentity().owningKey
val me = AnonymousParty(myKey)
@ -63,7 +63,7 @@ fun ServiceHub.fillWithSomeTestLinearStates(numberToCreate: Int,
linearString: String = "",
linearNumber: Long = 0L,
linearBoolean: Boolean = false,
linearTimestamp: Instant = now()) : Vault<LinearState> {
linearTimestamp: Instant = now()): Vault<LinearState> {
val myKey: PublicKey = myInfo.chooseIdentity().owningKey
val me = AnonymousParty(myKey)
val issuerKey = DUMMY_NOTARY_KEY
@ -196,7 +196,7 @@ fun calculateRandomlySizedAmounts(howMuch: Amount<Currency>, min: Int, max: Int,
fun <T : LinearState> ServiceHub.consume(states: List<StateAndRef<T>>, notary: Party) {
// Create a txn consuming different contract types
states.forEach {
val builder = TransactionBuilder(notary = notary).apply {
val builder = TransactionBuilder(notary = notary).apply {
addInputState(it)
addCommand(dummyCommand(notary.owningKey))
}
@ -238,7 +238,7 @@ fun <T : LinearState> ServiceHub.consumeAndProduce(states: List<StateAndRef<T>>,
fun ServiceHub.consumeDeals(dealStates: List<StateAndRef<DealState>>, notary: Party) = consume(dealStates, notary)
fun ServiceHub.consumeLinearStates(linearStates: List<StateAndRef<LinearState>>, notary: Party) = consume(linearStates, notary)
fun ServiceHub.evolveLinearStates(linearStates: List<StateAndRef<LinearState>>, notary: Party) = consumeAndProduce(linearStates, notary)
fun ServiceHub.evolveLinearState(linearState: StateAndRef<LinearState>, notary: Party) : StateAndRef<LinearState> = consumeAndProduce(linearState, notary)
fun ServiceHub.evolveLinearState(linearState: StateAndRef<LinearState>, notary: Party): StateAndRef<LinearState> = consumeAndProduce(linearState, notary)
/**
* Consume cash, sending any change to the default identity for this node. Only suitable for use in test scenarios,
@ -254,7 +254,7 @@ fun ServiceHub.consumeCash(amount: Amount<Currency>, to: Party = CHARLIE, notary
*/
@JvmOverloads
fun ServiceHub.consumeCash(amount: Amount<Currency>, ourIdentity: PartyAndCertificate, to: Party = CHARLIE, notary: Party): Vault.Update<ContractState> {
val update = vaultService.rawUpdates.toFuture()
val update = vaultService.rawUpdates.toFuture()
val services = this
// A tx that spends our money.

View File

@ -29,6 +29,7 @@ class HttpApi(val root: URL, val mapper: ObjectMapper = defaultMapper) {
companion object {
fun fromHostAndPort(hostAndPort: NetworkHostAndPort, base: String, protocol: String = "http", mapper: ObjectMapper = defaultMapper): HttpApi
= HttpApi(URL("$protocol://$hostAndPort/$base/"), mapper)
private val defaultMapper: ObjectMapper by lazy {
net.corda.client.jackson.JacksonSupport.createNonRpcMapper()
}

View File

@ -20,8 +20,8 @@ object DummyLinearStateSchema
object DummyLinearStateSchemaV1 : MappedSchema(schemaFamily = DummyLinearStateSchema.javaClass, version = 1, mappedTypes = listOf(PersistentDummyLinearState::class.java)) {
@Entity
@Table(name = "dummy_linear_states",
indexes = arrayOf(Index(name = "external_id_idx", columnList = "external_id"),
Index(name = "uuid_idx", columnList = "uuid")))
indexes = arrayOf(Index(name = "external_id_idx", columnList = "external_id"),
Index(name = "uuid_idx", columnList = "uuid")))
class PersistentDummyLinearState(
/** [ContractState] attributes */