diff --git a/node/src/integration-test/kotlin/net/corda/node/MockNetworkCustomSerializerCheckpointTest.kt b/node/src/integration-test/kotlin/net/corda/node/MockNetworkCustomSerializerCheckpointTest.kt index 19bf41bb65..6ce4018c8b 100644 --- a/node/src/integration-test/kotlin/net/corda/node/MockNetworkCustomSerializerCheckpointTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/MockNetworkCustomSerializerCheckpointTest.kt @@ -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() { + class TestFlowWithDifficultToSerializeLocalVariable(private val purchase: Int) : FlowLogic() { @Suspendable override fun call(): Int { @@ -54,14 +67,38 @@ class MockNetworkCustomSerializerCheckpointTest{ } } + @StartableByRPC + class TestFlowCheckingReferencesWork(private val reference: T) : FlowLogic() { + + 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, HashMap> { - override fun toProxy(obj: ImmutableMap): HashMap { - val proxy = HashMap() + class TestSerializer : SerializationCustomSerializer, HashMap> { + override fun toProxy(obj: ImmutableMap): HashMap { + val proxy = HashMap() return obj.toMap(proxy) } - override fun fromProxy(proxy: HashMap): ImmutableMap { + override fun fromProxy(proxy: HashMap): ImmutableMap { return proxy.toImmutableMap() } }