From 4dd37f009e76da204bcfc3f3aef07d20a2ee2b9f Mon Sep 17 00:00:00 2001 From: Katelyn Baker Date: Mon, 3 Jul 2017 16:33:20 +0100 Subject: [PATCH] Integrate with the carpenter now it's in core --- .../corda/core/serialization/amqp/Schema.kt | 10 +-- .../serialization/carpenter/MetaCarpenter.kt | 59 ++++++++++++++++- .../core/serialization/carpenter/Schema.kt | 10 +++ .../carpenter/ClassCarpenterTestUtils.kt | 2 +- ...berCompositeSchemaToClassCarpenterTests.kt | 58 ++++++++--------- .../InheritanceSchemaToClassCarpenterTests.kt | 65 ++++++++++--------- ...berCompositeSchemaToClassCarpenterTests.kt | 31 ++++----- ...berCompositeSchemaToClassCarpenterTests.kt | 21 +++--- .../net/corda/carpenter/MetaCapenter.kt | 61 ----------------- 9 files changed, 163 insertions(+), 154 deletions(-) rename {experimental/src/test/kotlin/net/corda => core/src/test/kotlin/net/corda/core/serialization}/carpenter/ClassCarpenterTestUtils.kt (97%) rename {experimental/src/test/kotlin/net/corda => core/src/test/kotlin/net/corda/core/serialization}/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt (82%) rename {experimental/src/test/kotlin/net/corda => core/src/test/kotlin/net/corda/core/serialization}/carpenter/InheritanceSchemaToClassCarpenterTests.kt (88%) rename {experimental/src/test/kotlin/net/corda => core/src/test/kotlin/net/corda/core/serialization}/carpenter/MultiMemberCompositeSchemaToClassCarpenterTests.kt (76%) rename {experimental/src/test/kotlin/net/corda => core/src/test/kotlin/net/corda/core/serialization}/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt (94%) delete mode 100644 experimental/src/main/kotlin/net/corda/carpenter/MetaCapenter.kt diff --git a/core/src/main/kotlin/net/corda/core/serialization/amqp/Schema.kt b/core/src/main/kotlin/net/corda/core/serialization/amqp/Schema.kt index c1ba797610..f0f0f80647 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/amqp/Schema.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/amqp/Schema.kt @@ -113,7 +113,7 @@ data class Schema(val types: List) : DescribedType { fun carpenterSchema(loaders : List = listOf(ClassLoader.getSystemClassLoader())) : CarpenterSchemas { - var rtn = CarpenterSchemas.newInstance() + val rtn = CarpenterSchemas.newInstance() types.filterIsInstance().forEach { it.carpenterSchema(classLoaders = loaders, carpenterSchemas = rtn) @@ -250,7 +250,7 @@ sealed class TypeNotation : DescribedType { } } - abstract var name: String + abstract val name: String abstract val label: String? abstract val provides: List abstract val descriptor: Descriptor @@ -328,7 +328,7 @@ data class CompositeType(override var name: String, override val label: String?, var isCreatable = true provides.forEach { - if (name.equals(it)) { + if (name == it) { isInterface = true return@forEach } @@ -366,7 +366,7 @@ data class CompositeType(override var name: String, override val label: String?, } } -data class RestrictedType(override var name: String, override val label: String?, override val provides: List, val source: String, override val descriptor: Descriptor, val choices: List) : TypeNotation() { +data class RestrictedType(override val name: String, override val label: String?, override val provides: List, val source: String, override val descriptor: Descriptor, val choices: List) : TypeNotation() { companion object : DescribedTypeConstructor { val DESCRIPTOR = UnsignedLong(6L or DESCRIPTOR_TOP_32BITS) @@ -409,7 +409,7 @@ data class RestrictedType(override var name: String, override val label: String? } } -data class Choice(var name: String, val value: String) : DescribedType { +data class Choice(val name: String, val value: String) : DescribedType { companion object : DescribedTypeConstructor { val DESCRIPTOR = UnsignedLong(7L or DESCRIPTOR_TOP_32BITS) diff --git a/core/src/main/kotlin/net/corda/core/serialization/carpenter/MetaCarpenter.kt b/core/src/main/kotlin/net/corda/core/serialization/carpenter/MetaCarpenter.kt index 821308658c..3f0414c1ad 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/carpenter/MetaCarpenter.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/carpenter/MetaCarpenter.kt @@ -1,7 +1,10 @@ package net.corda.core.serialization.carpenter +import net.corda.core.serialization.amqp.CompositeType import net.corda.core.serialization.amqp.TypeNotation +/**********************************************************************************************************************/ + data class CarpenterSchemas ( val carpenterSchemas : MutableList, val dependencies : MutableMap>>, @@ -22,7 +25,61 @@ data class CarpenterSchemas ( dependencies.computeIfAbsent(dependant, { Pair(type, mutableListOf()) }).second.add(dependee) } - val size get() = carpenterSchemas.size } + +/**********************************************************************************************************************/ + +abstract class MetaCarpenterBase (val schemas : CarpenterSchemas) { + + private val cc = ClassCarpenter() + val objects = mutableMapOf>() + + fun step (newObject : Schema) { + objects[newObject.name] = cc.build (newObject) + + /* go over the list of everything that had a dependency on the newly + carpented class existing and remove it from their dependency list, If that + list is now empty we have no impediment to carpenting that class up */ + schemas.dependsOn.remove(newObject.name)?.forEach { dependent -> + assert (newObject.name in schemas.dependencies[dependent]!!.second) + + schemas.dependencies[dependent]?.second?.remove(newObject.name) + + /* we're out of blockers so we can now create the type */ + if (schemas.dependencies[dependent]?.second?.isEmpty() ?: false) { + (schemas.dependencies.remove (dependent)?.first as CompositeType).carpenterSchema ( + classLoaders = listOf ( + ClassLoader.getSystemClassLoader(), + cc.classloader), + carpenterSchemas = schemas) + } + } + } + + abstract fun build() +} + +/**********************************************************************************************************************/ + +class MetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) { + override fun build() { + while (schemas.carpenterSchemas.isNotEmpty()) { + val newObject = schemas.carpenterSchemas.removeAt(0) + step (newObject) + } + } +} + +/**********************************************************************************************************************/ + +class TestMetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) { + override fun build() { + println ("TestMetaCarpenter::build") + if (schemas.carpenterSchemas.isEmpty()) return + step (schemas.carpenterSchemas.removeAt(0)) + } +} + +/**********************************************************************************************************************/ diff --git a/core/src/main/kotlin/net/corda/core/serialization/carpenter/Schema.kt b/core/src/main/kotlin/net/corda/core/serialization/carpenter/Schema.kt index 7bca4512b0..dfc37fc471 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/carpenter/Schema.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/carpenter/Schema.kt @@ -3,6 +3,8 @@ package net.corda.core.serialization.carpenter import org.objectweb.asm.Type import java.util.LinkedHashMap +/**********************************************************************************************************************/ + /** * A Schema represents a desired class. */ @@ -29,6 +31,8 @@ abstract class Schema( get() = name.replace(".", "/") } +/**********************************************************************************************************************/ + class ClassSchema( name: String, fields: Map>, @@ -36,6 +40,8 @@ class ClassSchema( interfaces: List> = emptyList() ) : Schema (name, fields, superclass, interfaces) +/**********************************************************************************************************************/ + class InterfaceSchema( name: String, fields: Map>, @@ -43,6 +49,8 @@ class InterfaceSchema( interfaces: List> = emptyList() ) : Schema (name, fields, superclass, interfaces) +/**********************************************************************************************************************/ + object CarpenterSchemaFactory { fun newInstance ( name: String, @@ -54,3 +62,5 @@ object CarpenterSchemaFactory { if (isInterface) InterfaceSchema (name, fields, superclass, interfaces) else ClassSchema (name, fields, superclass, interfaces) } + +/**********************************************************************************************************************/ diff --git a/experimental/src/test/kotlin/net/corda/carpenter/ClassCarpenterTestUtils.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/ClassCarpenterTestUtils.kt similarity index 97% rename from experimental/src/test/kotlin/net/corda/carpenter/ClassCarpenterTestUtils.kt rename to core/src/test/kotlin/net/corda/core/serialization/carpenter/ClassCarpenterTestUtils.kt index 8b2c97cf07..5ec3dbc61d 100644 --- a/experimental/src/test/kotlin/net/corda/carpenter/ClassCarpenterTestUtils.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/ClassCarpenterTestUtils.kt @@ -1,4 +1,4 @@ -package net.corda.carpenter.test +package net.corda.core.serialization.carpenter.test import net.corda.core.serialization.amqp.CompositeType import net.corda.core.serialization.amqp.Field diff --git a/experimental/src/test/kotlin/net/corda/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt similarity index 82% rename from experimental/src/test/kotlin/net/corda/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt rename to core/src/test/kotlin/net/corda/core/serialization/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt index 07c0898f13..cc196cd5f3 100644 --- a/experimental/src/test/kotlin/net/corda/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/CompositeMemberCompositeSchemaToClassCarpenterTests.kt @@ -1,11 +1,11 @@ -package net.corda.carpenter +package net.corda.core.serialization.carpenter +import net.corda.core.serialization.carpenter.test.* import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.amqp.* import org.junit.Test import kotlin.test.assertEquals -import net.corda.carpenter.test.* import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -32,22 +32,22 @@ class CompositeMembers : AmqpCarpenterBase() { val b = B(A(testA), testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - assert(obj.first is B) + assert(obj.obj is B) - val amqpObj = obj.first as B + val amqpObj = obj.obj as B assertEquals(testB, amqpObj.b) assertEquals(testA, amqpObj.a.a) - assertEquals(2, obj.second.schema.types.size) - assert(obj.second.schema.types[0] is CompositeType) - assert(obj.second.schema.types[1] is CompositeType) + assertEquals(2, obj.envelope.schema.types.size) + assert(obj.envelope.schema.types[0] is CompositeType) + assert(obj.envelope.schema.types[1] is CompositeType) var amqpSchemaA: CompositeType? = null var amqpSchemaB: CompositeType? = null - for (type in obj.second.schema.types) { + for (type in obj.envelope.schema.types) { when (type.name.split ("$").last()) { "A" -> amqpSchemaA = type as CompositeType "B" -> amqpSchemaB = type as CompositeType @@ -71,7 +71,7 @@ class CompositeMembers : AmqpCarpenterBase() { assertEquals("b", amqpSchemaB.fields[1].name) assertEquals("int", amqpSchemaB.fields[1].type) - val metaSchema = obj.second.schema.carpenterSchema() + val metaSchema = obj.envelope.schema.carpenterSchema() /* if we know all the classes there is nothing to really achieve here */ assert(metaSchema.carpenterSchemas.isEmpty()) @@ -95,10 +95,10 @@ class CompositeMembers : AmqpCarpenterBase() { val b = B(A(testA), testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) - val amqpSchema = obj.second.schema.curruptName(listOf (classTestName ("A"))) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) + val amqpSchema = obj.envelope.schema.curruptName(listOf (classTestName ("A"))) - assert(obj.first is B) + assert(obj.obj is B) amqpSchema.carpenterSchema() } @@ -116,9 +116,9 @@ class CompositeMembers : AmqpCarpenterBase() { val b = B(A(testA), testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - assert(obj.first is B) + assert(obj.obj is B) val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("B"))) @@ -146,9 +146,9 @@ class CompositeMembers : AmqpCarpenterBase() { val b = B(A(testA), testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - assert(obj.first is B) + assert(obj.obj is B) val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B"))) @@ -207,9 +207,9 @@ class CompositeMembers : AmqpCarpenterBase() { val c = C(B(testA, testB), testC) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(c)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(c)) - assert(obj.first is C) + assert(obj.obj is C) val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B"))) @@ -233,9 +233,9 @@ class CompositeMembers : AmqpCarpenterBase() { val c = C(B(testA, testB), testC) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(c)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(c)) - assert(obj.first is C) + assert(obj.obj is C) val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B"))) @@ -259,9 +259,9 @@ class CompositeMembers : AmqpCarpenterBase() { val c = C(B(testA, testB), testC) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(c)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(c)) - assert(obj.first is C) + assert(obj.obj is C) val amqpSchema = obj.envelope.schema.curruptName(listOf(classTestName("A"), classTestName("B"))) } @@ -284,9 +284,9 @@ class CompositeMembers : AmqpCarpenterBase() { val b = B(A(testA), testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - assert(obj.first is B) + assert(obj.obj is B) } @Test @@ -302,9 +302,9 @@ class CompositeMembers : AmqpCarpenterBase() { val b = B(A(testA), testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - assert(obj.first is B) + assert(obj.obj is B) } @Test @@ -320,9 +320,9 @@ class CompositeMembers : AmqpCarpenterBase() { val b = B(A(testA), testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - assert(obj.first is B) + assert(obj.obj is B) } } diff --git a/experimental/src/test/kotlin/net/corda/carpenter/InheritanceSchemaToClassCarpenterTests.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/InheritanceSchemaToClassCarpenterTests.kt similarity index 88% rename from experimental/src/test/kotlin/net/corda/carpenter/InheritanceSchemaToClassCarpenterTests.kt rename to core/src/test/kotlin/net/corda/core/serialization/carpenter/InheritanceSchemaToClassCarpenterTests.kt index a7d25841be..7516b4228e 100644 --- a/experimental/src/test/kotlin/net/corda/carpenter/InheritanceSchemaToClassCarpenterTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/InheritanceSchemaToClassCarpenterTests.kt @@ -1,10 +1,11 @@ -package net.corda.carpenter +package net.corda.core.serialization.carpenter import net.corda.core.serialization.CordaSerializable +import net.corda.core.serialization.carpenter.MetaCarpenter +import net.corda.core.serialization.carpenter.test.* import net.corda.core.serialization.amqp.* + import org.junit.Test -import net.corda.carpenter.test.* -import net.corda.carpenter.MetaCarpenter import kotlin.test.* /*******************************************************************************************************/ @@ -52,11 +53,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(testJ, a.j) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - assert(obj.first is A) + assert(obj.obj is A) - val serSchema = obj.second.schema + val serSchema = obj.envelope.schema assertEquals(2, serSchema.types.size) @@ -77,7 +78,7 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(curruptName(classTestName("A")), aSchema!!.name) assertEquals(1, aSchema.interfaces.size) - assertEquals(net.corda.carpenter.J::class.java, aSchema.interfaces[0]) + assertEquals(net.corda.core.serialization.carpenter.J::class.java, aSchema.interfaces[0]) val aBuilder = ClassCarpenter().build(aSchema) @@ -101,11 +102,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(testJ, a.j) assertEquals(testJJ, a.jj) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - assert(obj.first is A) + assert(obj.obj is A) - val serSchema = obj.second.schema + val serSchema = obj.envelope.schema assertEquals(2, serSchema.types.size) @@ -128,7 +129,7 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(aName, aSchema!!.name) assertEquals(1, aSchema.interfaces.size) - assertEquals(net.corda.carpenter.J::class.java, aSchema.interfaces[0]) + assertEquals(net.corda.core.serialization.carpenter.J::class.java, aSchema.interfaces[0]) val aBuilder = ClassCarpenter().build(aSchema) @@ -151,9 +152,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val a = A(testI, testII) val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - assert(obj.first is A) + assert(obj.obj is A) - val serSchema = obj.second.schema + val serSchema = obj.envelope.schema assertEquals(3, serSchema.types.size) @@ -178,8 +179,8 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(aName, aSchema!!.name) assertEquals(2, aSchema.interfaces.size) - assert(net.corda.carpenter.I::class.java in aSchema.interfaces) - assert(net.corda.carpenter.II::class.java in aSchema.interfaces) + assert(net.corda.core.serialization.carpenter.I::class.java in aSchema.interfaces) + assert(net.corda.core.serialization.carpenter.II::class.java in aSchema.interfaces) val aBuilder = ClassCarpenter().build(aSchema) @@ -204,9 +205,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val a = A(testI, testIII) val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - assert(obj.first is A) + assert(obj.obj is A) - val serSchema = obj.second.schema + val serSchema = obj.envelope.schema assertEquals(3, serSchema.types.size) @@ -228,8 +229,8 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(aName, aSchema!!.name) assertEquals(2, aSchema.interfaces.size) - assert(net.corda.carpenter.I::class.java in aSchema.interfaces) - assert(net.corda.carpenter.III::class.java in aSchema.interfaces) + assert(net.corda.core.serialization.carpenter.I::class.java in aSchema.interfaces) + assert(net.corda.core.serialization.carpenter.III::class.java in aSchema.interfaces) val aBuilder = ClassCarpenter().build(aSchema) @@ -256,11 +257,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val a = A(testI) val b = B(a, testIIII) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - assert(obj.first is B) + assert(obj.obj is B) - val serSchema = obj.second.schema + val serSchema = obj.envelope.schema /* * class A @@ -316,11 +317,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val a = A(testI) val b = B(a, testIIII) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(b)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(b)) - assert(obj.first is B) + assert(obj.obj is B) - val serSchema = obj.second.schema + val serSchema = obj.envelope.schema /* * The classes we're expecting to find: @@ -344,11 +345,11 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val a = A(testI) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - assert(obj.first is A) + assert(obj.obj is A) - val serSchema = obj.second.schema + val serSchema = obj.envelope.schema /* * The classes we're expecting to find: @@ -402,9 +403,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val a = A(testI, testII) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - val amqpSchema = obj.second.schema.curruptName(listOf( + val amqpSchema = obj.envelope.schema.curruptName(listOf( classTestName("A"), "${this.javaClass.`package`.name}.I", "${this.javaClass.`package`.name}.II")) @@ -457,9 +458,9 @@ class InheritanceSchemaToClassCarpenterTests : AmqpCarpenterBase() { val a = A(testI, testIII) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - val amqpSchema = obj.second.schema.curruptName(listOf( + val amqpSchema = obj.envelope.schema.curruptName(listOf( classTestName("A"), "${this.javaClass.`package`.name}.I", "${this.javaClass.`package`.name}.III")) diff --git a/experimental/src/test/kotlin/net/corda/carpenter/MultiMemberCompositeSchemaToClassCarpenterTests.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/MultiMemberCompositeSchemaToClassCarpenterTests.kt similarity index 76% rename from experimental/src/test/kotlin/net/corda/carpenter/MultiMemberCompositeSchemaToClassCarpenterTests.kt rename to core/src/test/kotlin/net/corda/core/serialization/carpenter/MultiMemberCompositeSchemaToClassCarpenterTests.kt index 0e53d438f9..71b96e1c8b 100644 --- a/experimental/src/test/kotlin/net/corda/carpenter/MultiMemberCompositeSchemaToClassCarpenterTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/MultiMemberCompositeSchemaToClassCarpenterTests.kt @@ -1,9 +1,10 @@ -package net.corda.carpenter +package net.corda.core.serialization.carpenter -import net.corda.carpenter.test.AmqpCarpenterBase +import net.corda.core.serialization.carpenter.test.AmqpCarpenterBase +import net.corda.core.serialization.carpenter.CarpenterSchemas import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.amqp.* -import net.corda.core.serialization.carpenter.CarpenterSchemas + import org.junit.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals @@ -20,17 +21,17 @@ class MultiMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { var a = A(testA, testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - assert(obj.first is A) - val amqpObj = obj.first as A + assert(obj.obj is A) + val amqpObj = obj.obj as A assertEquals(testA, amqpObj.a) assertEquals(testB, amqpObj.b) - assertEquals(1, obj.second.schema.types.size) - assert(obj.second.schema.types[0] is CompositeType) + assertEquals(1, obj.envelope.schema.types.size) + assert(obj.envelope.schema.types[0] is CompositeType) - var amqpSchema = obj.second.schema.types[0] as CompositeType + var amqpSchema = obj.envelope.schema.types[0] as CompositeType assertEquals(2, amqpSchema.fields.size) assertEquals("a", amqpSchema.fields[0].name) @@ -64,17 +65,17 @@ class MultiMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { val a = A(testA, testB) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) - assert(obj.first is A) - val amqpObj = obj.first as A + assert(obj.obj is A) + val amqpObj = obj.obj as A assertEquals(testA, amqpObj.a) assertEquals(testB, amqpObj.b) - assertEquals(1, obj.second.schema.types.size) - assert(obj.second.schema.types[0] is CompositeType) + assertEquals(1, obj.envelope.schema.types.size) + assert(obj.envelope.schema.types[0] is CompositeType) - val amqpSchema = obj.second.schema.types[0] as CompositeType + val amqpSchema = obj.envelope.schema.types[0] as CompositeType assertEquals(2, amqpSchema.fields.size) assertEquals("a", amqpSchema.fields[0].name) diff --git a/experimental/src/test/kotlin/net/corda/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt b/core/src/test/kotlin/net/corda/core/serialization/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt similarity index 94% rename from experimental/src/test/kotlin/net/corda/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt rename to core/src/test/kotlin/net/corda/core/serialization/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt index 0150e34a76..304d7185c4 100644 --- a/experimental/src/test/kotlin/net/corda/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/carpenter/SingleMemberCompositeSchemaToClassCarpenterTests.kt @@ -1,9 +1,10 @@ -package net.corda.carpenter +package net.corda.core.serialization.carpenter -import net.corda.carpenter.test.AmqpCarpenterBase +import net.corda.core.serialization.carpenter.test.AmqpCarpenterBase +import net.corda.core.serialization.carpenter.CarpenterSchemas import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.amqp.* -import net.corda.core.serialization.carpenter.CarpenterSchemas + import org.junit.Test import kotlin.test.assertEquals @@ -84,7 +85,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { data class A(val a : Char) val a = A(test) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise(a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) assert (obj.obj is A) val amqpObj = obj.obj as A @@ -121,7 +122,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { @CordaSerializable data class A(val a: Long) - var a = A(test) + val a = A(test) val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) @@ -132,7 +133,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(1, obj.envelope.schema.types.size) assert(obj.envelope.schema.types[0] is CompositeType) - var amqpSchema = obj.envelope.schema.types[0] as CompositeType + val amqpSchema = obj.envelope.schema.types[0] as CompositeType assertEquals(1, amqpSchema.fields.size) assertEquals("a", amqpSchema.fields[0].name) @@ -155,7 +156,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { @CordaSerializable data class A(val a: Short) - var a = A(test) + val a = A(test) val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise(a)) @@ -166,7 +167,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(1, obj.envelope.schema.types.size) assert(obj.envelope.schema.types[0] is CompositeType) - var amqpSchema = obj.envelope.schema.types[0] as CompositeType + val amqpSchema = obj.envelope.schema.types[0] as CompositeType assertEquals(1, amqpSchema.fields.size) assertEquals("a", amqpSchema.fields[0].name) @@ -192,7 +193,7 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { var a = A (test) - val obj = DeserializationInput(factory).deserializeRtnEnvelope(serialise (a)) + val obj = DeserializationInput(factory).deserializeAndReturnEnvelope(serialise (a)) assert (obj.obj is A) val amqpObj = obj.obj as A @@ -282,4 +283,4 @@ class SingleMemberCompositeSchemaToClassCarpenterTests : AmqpCarpenterBase() { assertEquals(pinochio.getMethod("getA").invoke(p), amqpObj.a) } -} \ No newline at end of file +} diff --git a/experimental/src/main/kotlin/net/corda/carpenter/MetaCapenter.kt b/experimental/src/main/kotlin/net/corda/carpenter/MetaCapenter.kt deleted file mode 100644 index cdbdcadf58..0000000000 --- a/experimental/src/main/kotlin/net/corda/carpenter/MetaCapenter.kt +++ /dev/null @@ -1,61 +0,0 @@ -package net.corda.carpenter - -import net.corda.core.serialization.carpenter.CarpenterSchemas -import net.corda.core.serialization.carpenter.Schema - -import net.corda.core.serialization.amqp.CompositeType - -/**********************************************************************************************************************/ - -abstract class MetaCarpenterBase (val schemas : CarpenterSchemas) { - - private val cc = ClassCarpenter() - val objects = mutableMapOf>() - - fun step (newObject : Schema) { - objects[newObject.name] = cc.build (newObject) - - /* go over the list of everything that had a dependency on the newly - carpented class existing and remove it from their dependency list, If that - list is now empty we have no impediment to carpenting that class up */ - schemas.dependsOn.remove(newObject.name)?.forEach { dependent -> - assert (newObject.name in schemas.dependencies[dependent]!!.second) - - schemas.dependencies[dependent]?.second?.remove(newObject.name) - - /* we're out of blockers so we can now create the type */ - if (schemas.dependencies[dependent]?.second?.isEmpty() ?: false) { - (schemas.dependencies.remove (dependent)?.first as CompositeType).carpenterSchema ( - classLoaders = listOf ( - ClassLoader.getSystemClassLoader(), - cc.classloader), - carpenterSchemas = schemas) - } - } - } - - abstract fun build() -} - -/**********************************************************************************************************************/ - -class MetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) { - override fun build() { - while (schemas.carpenterSchemas.isNotEmpty()) { - val newObject = schemas.carpenterSchemas.removeAt(0) - step (newObject) - } - } -} - -/**********************************************************************************************************************/ - -class TestMetaCarpenter (schemas : CarpenterSchemas) : MetaCarpenterBase (schemas) { - override fun build() { - println ("TestMetaCarpenter::build") - if (schemas.carpenterSchemas.isEmpty()) return - step (schemas.carpenterSchemas.removeAt(0)) - } -} - -/**********************************************************************************************************************/