From d811f6f4565de4b5d485374398280e18c7301f62 Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Mon, 8 Jan 2024 11:00:50 +0000 Subject: [PATCH] Investigating DuplicateSerializerLogTest --- build.gradle | 1 + .../kryo/KryoCheckpointSerializer.kt | 38 ++++++++++++++++++- .../src/main/resources/node-jvm-args.txt | 6 +++ .../DifficultToSerialize.kt | 2 +- .../DuplicateSerializerLogTest.kt | 4 +- .../customcheckpointserializer/TestCorDapp.kt | 8 ++-- .../flows/FlowReloadAfterCheckpointTest.kt | 2 +- 7 files changed, 53 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 652f501416..dd810fa774 100644 --- a/build.gradle +++ b/build.gradle @@ -311,6 +311,7 @@ allprojects { } tasks.withType(Test).configureEach { + jvmArgs += project(":node:capsule").file("src/main/resources/node-jvm-args.txt").readLines() jvmArgs += "--add-modules=jdk.incubator.foreign" // For the SharedMemoryIncremental forkEvery = 20 ignoreFailures = project.hasProperty('tests.ignoreFailures') ? project.property('tests.ignoreFailures').toBoolean() : false diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoCheckpointSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoCheckpointSerializer.kt index a61bc7c8ee..df4c383d43 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoCheckpointSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoCheckpointSerializer.kt @@ -6,6 +6,7 @@ import co.paralleluniverse.io.serialization.kryo.ExternalizableKryoSerializer import co.paralleluniverse.io.serialization.kryo.JdkProxySerializer import co.paralleluniverse.io.serialization.kryo.KryoSerializer import co.paralleluniverse.io.serialization.kryo.ReferenceSerializer +import com.esotericsoftware.kryo.ClassResolver import com.esotericsoftware.kryo.Kryo import com.esotericsoftware.kryo.KryoException import com.esotericsoftware.kryo.Serializer @@ -24,6 +25,7 @@ import net.corda.core.serialization.SerializedBytes import net.corda.core.serialization.internal.CheckpointSerializationContext import net.corda.core.serialization.internal.CheckpointSerializer import net.corda.core.utilities.ByteSequence +import net.corda.core.utilities.contextLogger import net.corda.core.utilities.loggerFor import net.corda.serialization.internal.AlwaysAcceptEncodingWhitelist import net.corda.serialization.internal.ByteBufferInputStream @@ -103,7 +105,7 @@ object KryoCheckpointSerializer : CheckpointSerializer { fun createFiberSerializer(context: CheckpointSerializationContext): KryoSerializer { // val serializer = Fiber.getFiberSerializer(classResolver, false) as KryoSerializer // (this as ReplaceableObjectKryo).isIgnoreInaccessibleClasses = true - val kryo = Kryo(CordaClassResolver(context), MapReferenceResolver()) + val kryo = LoggingKryo(CordaClassResolver(context), MapReferenceResolver()) kryo.isRegistrationRequired = false // Needed because of https://github.com/EsotericSoftware/kryo/issues/864 kryo.setOptimizedGenerics(false) @@ -111,6 +113,40 @@ object KryoCheckpointSerializer : CheckpointSerializer { return Fiber.getFiberSerializer(kryo, false) as KryoSerializer } + private class LoggingKryo(classResolver: ClassResolver, referenceResolver: MapReferenceResolver) : Kryo(classResolver, referenceResolver) { + private companion object { + private val log = contextLogger() + } + override fun writeObject(output: Output?, `object`: Any?, serializer: Serializer<*>?) { + log.info("writeObject ${`object`} serializer = $serializer") + super.writeObject(output, `object`, serializer) + } + + override fun writeClassAndObject(output: Output?, `object`: Any?) { + log.info("writeClassAndObject ${`object`}") + + super.writeClassAndObject(output, `object`) + } + + override fun writeObject(output: Output?, `object`: Any?) { + log.info("writeObject ${`object`}") + + super.writeObject(output, `object`) + } + + override fun writeObjectOrNull(output: Output?, `object`: Any?, serializer: Serializer<*>?) { + log.info("writeObjectOrNull ${`object`} serializer = $serializer") + + super.writeObjectOrNull(output, `object`, serializer) + } + + override fun writeObjectOrNull(output: Output?, `object`: Any?, type: Class<*>?) { + log.info("writeObjectOrNull ${`object`}") + + super.writeObjectOrNull(output, `object`, type) + } + } + /** * Copy of [co.paralleluniverse.io.serialization.kryo.KryoUtil.registerCommonClasses] ... */ diff --git a/node/capsule/src/main/resources/node-jvm-args.txt b/node/capsule/src/main/resources/node-jvm-args.txt index 549e0b3d6f..21d6d9f829 100644 --- a/node/capsule/src/main/resources/node-jvm-args.txt +++ b/node/capsule/src/main/resources/node-jvm-args.txt @@ -1,3 +1,9 @@ --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED +--add-opens=java.base/java.nio=ALL-UNNAMED +--add-opens=java.base/java.security=ALL-UNNAMED +--add-opens=java.base/java.security.cert=ALL-UNNAMED +--add-opens=java.base/java.time=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED +--add-opens=java.base/java.util.concurrent=ALL-UNNAMED +--add-opens=java.sql/java.sql=ALL-UNNAMED diff --git a/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/DifficultToSerialize.kt b/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/DifficultToSerialize.kt index f272e71ebf..04dc5cd524 100644 --- a/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/DifficultToSerialize.kt +++ b/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/DifficultToSerialize.kt @@ -8,7 +8,7 @@ class DifficultToSerialize { // This map breaks the rules for the put method. Making the normal map serializer fail. open class BrokenMapBaseImpl(delegate: MutableMap = mutableMapOf()) : MutableMap by delegate { - override fun put(key: K, value: V): V? = throw FlowException("Broken on purpose") + override fun put(key: K, value: V): V? = throw FlowException("Broken on purpose BrokenMapBaseImpl") } // A class to test custom serializers applied to implementations diff --git a/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/DuplicateSerializerLogTest.kt b/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/DuplicateSerializerLogTest.kt index 0e96e84d3c..e9b1b43dce 100644 --- a/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/DuplicateSerializerLogTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/DuplicateSerializerLogTest.kt @@ -8,6 +8,8 @@ import net.corda.core.serialization.CheckpointCustomSerializer import net.corda.core.utilities.getOrThrow import net.corda.testing.driver.driver import net.corda.testing.driver.logFile +import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.internalDriver import org.assertj.core.api.Assertions import org.junit.Test import java.time.Duration @@ -15,7 +17,7 @@ import java.time.Duration class DuplicateSerializerLogTest{ @Test(timeout=300_000) fun `check duplicate serialisers are logged`() { - driver { + internalDriver(cordappsForAllNodes = cordappsForPackages(javaClass.packageName)) { val node = startNode(startInSameProcess = false).getOrThrow() node.rpc.startFlow(::TestFlow).returnValue.get() diff --git a/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/TestCorDapp.kt b/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/TestCorDapp.kt index 1d3e929dde..ba3efdc3c5 100644 --- a/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/TestCorDapp.kt +++ b/node/src/integration-test/kotlin/net/corda/node/customcheckpointserializer/TestCorDapp.kt @@ -191,11 +191,11 @@ class TestCorDapp { class BrokenPublicKeySerializer : CheckpointCustomSerializer { override fun toProxy(obj: PublicKey): String { - throw FlowException("Broken on purpose") + throw FlowException("Broken on purpose BrokenPublicKeySerializer.toProxy") } override fun fromProxy(proxy: String): PublicKey { - throw FlowException("Broken on purpose") + throw FlowException("Broken on purpose BrokenPublicKeySerializer.fromProxy") } } @@ -203,11 +203,11 @@ class TestCorDapp { class BrokenEdDSAPublicKeySerializer : CheckpointCustomSerializer { override fun toProxy(obj: EdDSAPublicKey): String { - throw FlowException("Broken on purpose") + throw FlowException("Broken on purpose BrokenEdDSAPublicKeySerializer.toProxy") } override fun fromProxy(proxy: String): EdDSAPublicKey { - throw FlowException("Broken on purpose") + throw FlowException("Broken on purpose BrokenEdDSAPublicKeySerializer.fromProxy") } } diff --git a/node/src/integration-test/kotlin/net/corda/node/flows/FlowReloadAfterCheckpointTest.kt b/node/src/integration-test/kotlin/net/corda/node/flows/FlowReloadAfterCheckpointTest.kt index 9f4095615a..9c337d05d1 100644 --- a/node/src/integration-test/kotlin/net/corda/node/flows/FlowReloadAfterCheckpointTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/flows/FlowReloadAfterCheckpointTest.kt @@ -522,6 +522,6 @@ class FlowReloadAfterCheckpointTest { } internal class BrokenMap(delegate: MutableMap = mutableMapOf()) : MutableMap by delegate { - override fun put(key: K, value: V): V = throw IllegalStateException("Broken on purpose") + override fun put(key: K, value: V): V = throw IllegalStateException("Broken on purpose BrokenMap") }