mirror of
https://github.com/corda/corda.git
synced 2025-03-13 15:56:36 +00:00
Add test to check references are restored correctly
This commit is contained in:
parent
296202d541
commit
050a36a677
@ -29,17 +29,30 @@ class MockNetworkCustomSerializerCheckpointTest{
|
|||||||
mockNetwork.stopNodes()
|
mockNetwork.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
|
||||||
@Test(timeout = 300_000)
|
@Test(timeout = 300_000)
|
||||||
fun `flow suspend with custom kryo serializer`() {
|
fun `flow suspend with custom kryo serializer`() {
|
||||||
val node = mockNetwork.createPartyNode()
|
val node = mockNetwork.createPartyNode()
|
||||||
val expected = 5
|
val expected = 5
|
||||||
val actual = node.startFlow(TestFlow(5)).get()
|
val actual = node.startFlow(TestFlowWithDifficultToSerializeLocalVariable(5)).get()
|
||||||
|
|
||||||
Assertions.assertThat(actual).isEqualTo(expected)
|
Assertions.assertThat(actual).isEqualTo(expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 300_000)
|
||||||
|
fun `check references are restored correctly`() {
|
||||||
|
val node = mockNetwork.createPartyNode()
|
||||||
|
val expectedReference = immutableMapOf(1 to 1)
|
||||||
|
val actualReference = node.startFlow(TestFlowCheckingReferencesWork(expectedReference)).get()
|
||||||
|
|
||||||
|
Assertions.assertThat(actualReference).isSameAs(expectedReference)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flows
|
||||||
|
|
||||||
@StartableByRPC
|
@StartableByRPC
|
||||||
class TestFlow(private val purchase: Int) : FlowLogic<Int>() {
|
class TestFlowWithDifficultToSerializeLocalVariable(private val purchase: Int) : FlowLogic<Int>() {
|
||||||
@Suspendable
|
@Suspendable
|
||||||
override fun call(): Int {
|
override fun call(): Int {
|
||||||
|
|
||||||
@ -54,14 +67,38 @@ class MockNetworkCustomSerializerCheckpointTest{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@StartableByRPC
|
||||||
|
class TestFlowCheckingReferencesWork<T>(private val reference: T) : FlowLogic<T>() {
|
||||||
|
|
||||||
|
private val referenceField = reference
|
||||||
|
|
||||||
|
@Suspendable
|
||||||
|
override fun call(): T {
|
||||||
|
|
||||||
|
val ref = referenceField
|
||||||
|
|
||||||
|
// Force a checkpoint
|
||||||
|
sleep(Duration.ofSeconds(0), maySkipCheckpoint = false)
|
||||||
|
|
||||||
|
// Check all objects refer to same object
|
||||||
|
Assertions.assertThat(reference).isSameAs(referenceField)
|
||||||
|
Assertions.assertThat(referenceField).isSameAs(ref)
|
||||||
|
|
||||||
|
// Return deserialized object
|
||||||
|
return ref
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom serializers
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class TestSerializer : SerializationCustomSerializer<ImmutableMap<String, Int>, HashMap<String, Int>> {
|
class TestSerializer : SerializationCustomSerializer<ImmutableMap<Any, Any>, HashMap<Any, Any>> {
|
||||||
override fun toProxy(obj: ImmutableMap<String, Int>): HashMap<String, Int> {
|
override fun toProxy(obj: ImmutableMap<Any, Any>): HashMap<Any, Any> {
|
||||||
val proxy = HashMap<String, Int>()
|
val proxy = HashMap<Any, Any>()
|
||||||
return obj.toMap(proxy)
|
return obj.toMap(proxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromProxy(proxy: HashMap<String, Int>): ImmutableMap<String, Int> {
|
override fun fromProxy(proxy: HashMap<Any, Any>): ImmutableMap<Any, Any> {
|
||||||
return proxy.toImmutableMap()
|
return proxy.toImmutableMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user