diff --git a/data/avro-schema/src/main/resources/avro/net/corda/data/membership/state/CommandMetadata.avsc b/data/avro-schema/src/main/resources/avro/net/corda/data/membership/state/CommandMetadata.avsc new file mode 100644 index 0000000000..9fc8ef3b96 --- /dev/null +++ b/data/avro-schema/src/main/resources/avro/net/corda/data/membership/state/CommandMetadata.avsc @@ -0,0 +1,18 @@ +{ + "type": "record", + "name": "CommandMetadata", + "namespace": "net.corda.data.membership.state", + "doc": "Metadata about a complete registration command.", + "fields": [ + { + "name": "index", + "doc": "An index which can be used to determine the order of complete registration commands.", + "type": "int" + }, + { + "name": "command", + "doc": "The name of the command which was completed.", + "type": "string" + } + ] +} \ No newline at end of file diff --git a/data/avro-schema/src/main/resources/avro/net/corda/data/membership/state/RegistrationState.avsc b/data/avro-schema/src/main/resources/avro/net/corda/data/membership/state/RegistrationState.avsc index 28a5d16297..e5979c988f 100644 --- a/data/avro-schema/src/main/resources/avro/net/corda/data/membership/state/RegistrationState.avsc +++ b/data/avro-schema/src/main/resources/avro/net/corda/data/membership/state/RegistrationState.avsc @@ -21,6 +21,15 @@ "name": "mgm", "doc": "Holding identity of the MGM.", "type": "net.corda.data.identity.HoldingIdentity" + }, + { + "name": "commands", + "doc": "A list of all the complete commands during registration. Can be used for idempotency in the case of message replays.", + "type": { + "type": "array", + "items": "net.corda.data.membership.state.CommandMetadata" + }, + "default": [] } ] } \ No newline at end of file diff --git a/data/avro-schema/src/test/kotlin/net/corda/data/command/registration/mgm/DeclineRegistrationCompatibilityTest.kt b/data/avro-schema/src/test/kotlin/net/corda/data/membership/command/registration/mgm/DeclineRegistrationCompatibilityTest.kt similarity index 91% rename from data/avro-schema/src/test/kotlin/net/corda/data/command/registration/mgm/DeclineRegistrationCompatibilityTest.kt rename to data/avro-schema/src/test/kotlin/net/corda/data/membership/command/registration/mgm/DeclineRegistrationCompatibilityTest.kt index fea285f523..130d61db8d 100644 --- a/data/avro-schema/src/test/kotlin/net/corda/data/command/registration/mgm/DeclineRegistrationCompatibilityTest.kt +++ b/data/avro-schema/src/test/kotlin/net/corda/data/membership/command/registration/mgm/DeclineRegistrationCompatibilityTest.kt @@ -1,6 +1,5 @@ -package net.corda.data.command.registration.mgm +package net.corda.data.membership.command.registration.mgm -import net.corda.data.membership.command.registration.mgm.DeclineRegistration import org.apache.avro.Schema import org.apache.avro.SchemaCompatibility import org.junit.jupiter.api.Assertions diff --git a/data/avro-schema/src/test/kotlin/net/corda/data/membership/state/RegistrationStateTest.kt b/data/avro-schema/src/test/kotlin/net/corda/data/membership/state/RegistrationStateTest.kt new file mode 100644 index 0000000000..3032520184 --- /dev/null +++ b/data/avro-schema/src/test/kotlin/net/corda/data/membership/state/RegistrationStateTest.kt @@ -0,0 +1,56 @@ +package net.corda.data.membership.state + +import net.corda.data.identity.HoldingIdentity +import org.apache.avro.Schema +import org.apache.avro.SchemaCompatibility +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +class RegistrationStateTest { + + @Test + fun `Changes in RegistrationState between Corda 5_0 and 5_1 are compatible`() { + val oldSchemaJson = """ + { + "type": "record", + "name": "RegistrationState", + "namespace": "net.corda.data.membership.state", + "doc": "State for a registration.", + "fields": [ + { + "name": "registrationId", + "doc": "UUID identifying this registration request", + "type": { + "type": "string", + "logicalType": "uuid" + } + }, + { + "name": "registeringMember", + "doc": "Holding identity of the registering member as provided during P2P communication. Used to verify the registration request.", + "type": "net.corda.data.identity.HoldingIdentity" + }, + { + "name": "mgm", + "doc": "Holding identity of the MGM.", + "type": "net.corda.data.identity.HoldingIdentity" + } + ] + } + """.trimIndent() + + val oldSchema = Schema.Parser() + .addTypes(mapOf(HoldingIdentity::class.java.name to HoldingIdentity.`SCHEMA$`)) + .parse(oldSchemaJson) + val newSchema = RegistrationState.`SCHEMA$` + + val compatibility = SchemaCompatibility.checkReaderWriterCompatibility(newSchema, oldSchema) + + Assertions.assertEquals( + compatibility.type, + SchemaCompatibility.SchemaCompatibilityType.COMPATIBLE, + "Failed due to incompatible change. ${compatibility.description}" + ) + } + +} \ No newline at end of file