forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENT-2489: Fix serialization for some of the CordaExceptions. (corda#3925
) Also add a unit test that exposes the problem. Without these changes AMQP serialization fails with the following: ``` net.corda.serialization.internal.amqp.AMQPNotSerializableException: Constructor parameter - "reason" - doesn't refer to a property of "class net.corda.node.services.statemachine.SessionRejectException" at net.corda.serialization.internal.amqp.SerializationHelperKt.toPropertyAccessorConstructor(SerializationHelper.kt:120) ~[corda-serialization-4.0-SNAPSHOT.jar:?] at net.corda.serialization.internal.amqp.SerializationHelperKt.propertiesForSerializationFromConstructor(SerializationHelper.kt:107) ~[corda-serialization-4.0-SNAPSHOT.jar:?] at net.corda.serialization.internal.amqp.custom.ThrowableSerializer.toProxy(ThrowableSerializer.kt:28) [corda-serialization-4.0-SNAPSHOT.jar:?] at net.corda.serialization.internal.amqp.custom.ThrowableSerializer.toProxy(ThrowableSerializer.kt:12) [corda-serialization-4.0-SNAPSHOT.jar:?] at net.corda.serialization.internal.amqp.CustomSerializer$Proxy.writeDescribedObject(CustomSerializer.kt:159) [corda-serialization-4.0-SNAPSHOT.jar:?] ```
- Loading branch information
1 parent
ca5d88e
commit 90a7dd2
Showing
4 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
node/src/test/kotlin/net/corda/node/services/statemachine/ExceptionsSerializationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package net.corda.node.services.statemachine | ||
|
||
import net.corda.core.CordaException | ||
import net.corda.core.node.services.UnknownAnonymousPartyException | ||
import net.corda.core.serialization.SerializedBytes | ||
import net.corda.core.serialization.deserialize | ||
import net.corda.core.serialization.serialize | ||
import net.corda.node.internal.AbstractNode | ||
import net.corda.node.utilities.registration.CertificateRequestException | ||
import net.corda.testing.core.SerializationEnvironmentRule | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import kotlin.test.assertEquals | ||
|
||
@RunWith(Parameterized::class) | ||
class ExceptionsSerializationTest(private val initialException: CordaException, @Suppress("UNUSED_PARAMETER") description: String) { | ||
|
||
companion object { | ||
@JvmStatic | ||
@Parameterized.Parameters(name = "{1}") | ||
fun data(): Collection<Array<Any>> = listOf( | ||
arrayOf<Any>(SessionRejectException("test"), "SessionRejectException"), | ||
arrayOf<Any>(CertificateRequestException("test"), "CertificateRequestException"), | ||
arrayOf<Any>(UnknownAnonymousPartyException("test"), "UnknownAnonymousPartyException"), | ||
arrayOf<Any>(AbstractNode.DatabaseConfigurationException("test"), "DatabaseConfigurationException") | ||
) | ||
} | ||
|
||
@Rule | ||
@JvmField | ||
val testSerialization = SerializationEnvironmentRule() | ||
|
||
@Test | ||
fun testMarshal() { | ||
val fromSerialized = performRoundTripSerialization(initialException) | ||
assertEquals(initialException.message, fromSerialized.message) | ||
} | ||
|
||
private inline fun <reified T : Any> performRoundTripSerialization(obj: T): T { | ||
val serializedForm: SerializedBytes<T> = obj.serialize() | ||
return serializedForm.deserialize() | ||
} | ||
} |