Add test to check references are restored correctly

This commit is contained in:
Joseph Zuniga-Daly 2020-06-25 11:40:47 +01:00
parent 296202d541
commit 050a36a677

View File

@ -29,17 +29,30 @@ class MockNetworkCustomSerializerCheckpointTest{
mockNetwork.stopNodes()
}
// Tests
@Test(timeout = 300_000)
fun `flow suspend with custom kryo serializer`() {
val node = mockNetwork.createPartyNode()
val expected = 5
val actual = node.startFlow(TestFlow(5)).get()
val actual = node.startFlow(TestFlowWithDifficultToSerializeLocalVariable(5)).get()
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
class TestFlow(private val purchase: Int) : FlowLogic<Int>() {
class TestFlowWithDifficultToSerializeLocalVariable(private val purchase: Int) : FlowLogic<Int>() {
@Suspendable
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")
class TestSerializer : SerializationCustomSerializer<ImmutableMap<String, Int>, HashMap<String, Int>> {
override fun toProxy(obj: ImmutableMap<String, Int>): HashMap<String, Int> {
val proxy = HashMap<String, Int>()
class TestSerializer : SerializationCustomSerializer<ImmutableMap<Any, Any>, HashMap<Any, Any>> {
override fun toProxy(obj: ImmutableMap<Any, Any>): HashMap<Any, Any> {
val proxy = HashMap<Any, Any>()
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()
}
}