mirror of
https://github.com/corda/corda.git
synced 2025-06-23 01:19:00 +00:00
CORDA-1498: serialization multiple transform bug (#3216)
* Fix issue when evolving enums with transformation chains * Regenerate test data for deserializeWithRename test and unignore * Further tweaks / remove debugging * Formatting tweaks * Address review comments * Remove debug * Add classname to serialization tranform exceptions * Use direct node links instead of indexes to improve readability * More readability tweaks * More readability improvements * rename require to requireThat to resolve conflict with kotlin libraries * Add logging of error message * Change requireThat helper to inline function * remove unneeded toString * Further tweaks * Change NotSerializableException to more generic IOException * Make exception context clearer
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
package net.corda.serialization.internal.amqp
|
||||
|
||||
import net.corda.core.serialization.*
|
||||
import net.corda.serialization.internal.NotSerializableDetailedException
|
||||
import net.corda.serialization.internal.amqp.testutils.*
|
||||
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.assertj.core.api.Condition
|
||||
import org.junit.Test
|
||||
import java.io.NotSerializableException
|
||||
import java.net.URI
|
||||
@ -442,6 +445,68 @@ class EnumEvolvabilityTests {
|
||||
assertTrue(envelope.transformsSchema.types[WithUnknownTest::class.java.name]!!.containsKey(TransformTypes.Unknown))
|
||||
}
|
||||
|
||||
//
|
||||
// In this test we check that multiple transforms of a property are accepted
|
||||
//
|
||||
@CordaSerializationTransformRenames(
|
||||
CordaSerializationTransformRename(from = "A", to = "B"),
|
||||
CordaSerializationTransformRename(from = "B", to = "C")
|
||||
)
|
||||
enum class AcceptMultipleRename { C }
|
||||
|
||||
@Test
|
||||
fun acceptMultipleRename() {
|
||||
data class C(val e: AcceptMultipleRename)
|
||||
|
||||
val sf = testDefaultFactory()
|
||||
SerializationOutput(sf).serialize(C(AcceptMultipleRename.C))
|
||||
}
|
||||
|
||||
//
|
||||
// In this example we will try to rename two different things to the same thing,
|
||||
// which is not allowed
|
||||
//
|
||||
@CordaSerializationTransformRenames(
|
||||
CordaSerializationTransformRename(from = "D", to = "C"),
|
||||
CordaSerializationTransformRename(from = "E", to = "C")
|
||||
)
|
||||
enum class RejectMultipleRenameTo { A, B, C }
|
||||
|
||||
@Test
|
||||
fun rejectMultipleRenameTo() {
|
||||
data class C(val e: RejectMultipleRenameTo)
|
||||
|
||||
val sf = testDefaultFactory()
|
||||
assertThatThrownBy {
|
||||
SerializationOutput(sf).serialize(C(RejectMultipleRenameTo.A))
|
||||
}.isInstanceOfSatisfying(NotSerializableDetailedException::class.java) { ex ->
|
||||
assertThat(ex.reason).isEqualToIgnoringCase("There are multiple transformations to C, which is not allowed")
|
||||
assertThat(ex.message).endsWith(RejectMultipleRenameTo::class.simpleName)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// In this example we will try to rename two different things from the same thing,
|
||||
// which is not allowed
|
||||
//
|
||||
@CordaSerializationTransformRenames(
|
||||
CordaSerializationTransformRename(from = "D", to = "C"),
|
||||
CordaSerializationTransformRename(from = "D", to = "B")
|
||||
)
|
||||
enum class RejectMultipleRenameFrom { A, B, C }
|
||||
|
||||
@Test
|
||||
fun rejectMultipleRenameFrom() {
|
||||
data class C(val e: RejectMultipleRenameFrom)
|
||||
|
||||
val sf = testDefaultFactory()
|
||||
assertThatThrownBy {
|
||||
SerializationOutput(sf).serialize(C(RejectMultipleRenameFrom.A))
|
||||
}.isInstanceOf(NotSerializableException::class.java)
|
||||
.hasToString("Unable to serialize/deserialize net.corda.serialization.internal.amqp.EnumEvolvabilityTests\$RejectMultipleRenameFrom: " +
|
||||
"There are multiple transformations from D, which is not allowed")
|
||||
}
|
||||
|
||||
//
|
||||
// In this example we will have attempted to rename D back to C
|
||||
//
|
||||
@ -534,5 +599,4 @@ class EnumEvolvabilityTests {
|
||||
SerializationOutput(sf).serialize(C(RejectBadDefaultToSelf.D))
|
||||
}.isInstanceOf(NotSerializableException::class.java)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -150,7 +150,6 @@ class EnumEvolveTests {
|
||||
// Finally, the version we're using to test with
|
||||
enum class DeserializeWithRename { A, B, C }
|
||||
|
||||
@Ignore("https://r3-cev.atlassian.net/browse/CORDA-1498")
|
||||
@Test
|
||||
fun deserializeWithRename() {
|
||||
val resource = "${javaClass.simpleName}.${testName()}"
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user