mirror of
https://github.com/corda/corda.git
synced 2025-03-13 07:54:32 +00:00
Move broken map into its own source file
This commit is contained in:
parent
576e563070
commit
fefa2bee5e
@ -22,7 +22,7 @@ class CustomCheckpointSerializerCorDapp {
|
||||
override fun call(): Int {
|
||||
|
||||
// This object is difficult to serialize with Kryo
|
||||
val difficultToSerialize: MockNetworkCustomCheckpointSerializerTest.BrokenMapAbstract<String, Int> = MockNetworkCustomCheckpointSerializerTest.BrokenMapAbstractImpl()
|
||||
val difficultToSerialize: DifficultToSerialize.BrokenMapAbstract<String, Int> = DifficultToSerialize.BrokenMapAbstractImpl()
|
||||
difficultToSerialize.putAll(mapOf("foo" to purchase))
|
||||
|
||||
// Force a checkpoint
|
||||
@ -40,7 +40,7 @@ class CustomCheckpointSerializerCorDapp {
|
||||
override fun call(): Int {
|
||||
|
||||
// This object is difficult to serialize with Kryo
|
||||
val difficultToSerialize: MockNetworkCustomCheckpointSerializerTest.BrokenMapInterface<String, Int> = MockNetworkCustomCheckpointSerializerTest.BrokenMapInterfaceImpl()
|
||||
val difficultToSerialize: DifficultToSerialize.BrokenMapInterface<String, Int> = DifficultToSerialize.BrokenMapInterfaceImpl()
|
||||
difficultToSerialize.putAll(mapOf("foo" to purchase))
|
||||
|
||||
// Force a checkpoint
|
||||
@ -57,7 +57,7 @@ class CustomCheckpointSerializerCorDapp {
|
||||
override fun call(): Int {
|
||||
|
||||
// This object is difficult to serialize with Kryo
|
||||
val difficultToSerialize: MockNetworkCustomCheckpointSerializerTest.BrokenMapClass<String, Int> = MockNetworkCustomCheckpointSerializerTest.BrokenMapClass()
|
||||
val difficultToSerialize: DifficultToSerialize.BrokenMapClass<String, Int> = DifficultToSerialize.BrokenMapClass()
|
||||
difficultToSerialize.putAll(mapOf("foo" to purchase))
|
||||
|
||||
// Force a checkpoint
|
||||
@ -70,11 +70,12 @@ class CustomCheckpointSerializerCorDapp {
|
||||
}
|
||||
|
||||
@StartableByRPC
|
||||
class TestFlowCheckingReferencesWork(private val reference: MockNetworkCustomCheckpointSerializerTest.BrokenMapClass<String, Int>) : FlowLogic<MockNetworkCustomCheckpointSerializerTest.BrokenMapClass<String, Int>>() {
|
||||
class TestFlowCheckingReferencesWork(private val reference: DifficultToSerialize.BrokenMapClass<String, Int>) :
|
||||
FlowLogic<DifficultToSerialize.BrokenMapClass<String, Int>>() {
|
||||
|
||||
private val referenceField = reference
|
||||
@Suspendable
|
||||
override fun call(): MockNetworkCustomCheckpointSerializerTest.BrokenMapClass<String, Int> {
|
||||
override fun call(): DifficultToSerialize.BrokenMapClass<String, Int> {
|
||||
|
||||
val ref = referenceField
|
||||
|
||||
@ -95,14 +96,14 @@ class CustomCheckpointSerializerCorDapp {
|
||||
|
||||
@Suppress("unused")
|
||||
class TestInterfaceSerializer :
|
||||
CheckpointCustomSerializer<MockNetworkCustomCheckpointSerializerTest.BrokenMapInterface<Any, Any>, HashMap<Any, Any>> {
|
||||
CheckpointCustomSerializer<DifficultToSerialize.BrokenMapInterface<Any, Any>, HashMap<Any, Any>> {
|
||||
|
||||
override fun toProxy(obj: MockNetworkCustomCheckpointSerializerTest.BrokenMapInterface<Any, Any>): HashMap<Any, Any> {
|
||||
override fun toProxy(obj: DifficultToSerialize.BrokenMapInterface<Any, Any>): HashMap<Any, Any> {
|
||||
val proxy = HashMap<Any, Any>()
|
||||
return obj.toMap(proxy)
|
||||
}
|
||||
override fun fromProxy(proxy: HashMap<Any, Any>): MockNetworkCustomCheckpointSerializerTest.BrokenMapInterface<Any, Any> {
|
||||
return MockNetworkCustomCheckpointSerializerTest.BrokenMapInterfaceImpl<Any, Any>()
|
||||
override fun fromProxy(proxy: HashMap<Any, Any>): DifficultToSerialize.BrokenMapInterface<Any, Any> {
|
||||
return DifficultToSerialize.BrokenMapInterfaceImpl<Any, Any>()
|
||||
.also { it.putAll(proxy) }
|
||||
}
|
||||
|
||||
@ -110,14 +111,14 @@ class CustomCheckpointSerializerCorDapp {
|
||||
|
||||
@Suppress("unused")
|
||||
class TestClassSerializer :
|
||||
CheckpointCustomSerializer<MockNetworkCustomCheckpointSerializerTest.BrokenMapClass<Any, Any>, HashMap<Any, Any>> {
|
||||
CheckpointCustomSerializer<DifficultToSerialize.BrokenMapClass<Any, Any>, HashMap<Any, Any>> {
|
||||
|
||||
override fun toProxy(obj: MockNetworkCustomCheckpointSerializerTest.BrokenMapClass<Any, Any>): HashMap<Any, Any> {
|
||||
override fun toProxy(obj: DifficultToSerialize.BrokenMapClass<Any, Any>): HashMap<Any, Any> {
|
||||
val proxy = HashMap<Any, Any>()
|
||||
return obj.toMap(proxy)
|
||||
}
|
||||
override fun fromProxy(proxy: HashMap<Any, Any>): MockNetworkCustomCheckpointSerializerTest.BrokenMapClass<Any, Any> {
|
||||
return MockNetworkCustomCheckpointSerializerTest.BrokenMapClass<Any, Any>()
|
||||
override fun fromProxy(proxy: HashMap<Any, Any>): DifficultToSerialize.BrokenMapClass<Any, Any> {
|
||||
return DifficultToSerialize.BrokenMapClass<Any, Any>()
|
||||
.also { it.putAll(proxy) }
|
||||
}
|
||||
|
||||
@ -125,16 +126,15 @@ class CustomCheckpointSerializerCorDapp {
|
||||
|
||||
@Suppress("unused")
|
||||
class TestAbstractClassSerializer :
|
||||
CheckpointCustomSerializer<MockNetworkCustomCheckpointSerializerTest.BrokenMapAbstract<Any, Any>, HashMap<Any, Any>> {
|
||||
CheckpointCustomSerializer<DifficultToSerialize.BrokenMapAbstract<Any, Any>, HashMap<Any, Any>> {
|
||||
|
||||
override fun toProxy(obj: MockNetworkCustomCheckpointSerializerTest.BrokenMapAbstract<Any, Any>): HashMap<Any, Any> {
|
||||
override fun toProxy(obj: DifficultToSerialize.BrokenMapAbstract<Any, Any>): HashMap<Any, Any> {
|
||||
val proxy = HashMap<Any, Any>()
|
||||
return obj.toMap(proxy)
|
||||
}
|
||||
override fun fromProxy(proxy: HashMap<Any, Any>): MockNetworkCustomCheckpointSerializerTest.BrokenMapAbstract<Any, Any> {
|
||||
return MockNetworkCustomCheckpointSerializerTest.BrokenMapAbstractImpl<Any, Any>()
|
||||
override fun fromProxy(proxy: HashMap<Any, Any>): DifficultToSerialize.BrokenMapAbstract<Any, Any> {
|
||||
return DifficultToSerialize.BrokenMapAbstractImpl<Any, Any>()
|
||||
.also { it.putAll(proxy) }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package net.corda.node.customcheckpointserializer
|
||||
|
||||
import net.corda.core.flows.FlowException
|
||||
|
||||
class DifficultToSerialize {
|
||||
|
||||
// Broken Map
|
||||
// This map breaks the rules for the put method. Making the normal map serializer fail.
|
||||
|
||||
open class BrokenMapBaseImpl<K,V> : MutableMap<K,V>{
|
||||
private val map = HashMap<K,V>()
|
||||
|
||||
override val size: Int
|
||||
get() = map.size
|
||||
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
|
||||
get() = map.entries
|
||||
override val keys: MutableSet<K>
|
||||
get() = map.keys
|
||||
override val values: MutableCollection<V>
|
||||
get() = map.values
|
||||
|
||||
override fun containsKey(key: K): Boolean = map.containsKey(key)
|
||||
override fun containsValue(value: V): Boolean = map.containsValue(value)
|
||||
override fun get(key: K): V? = map.get(key)
|
||||
override fun isEmpty(): Boolean = map.isEmpty()
|
||||
override fun clear() = map.clear()
|
||||
override fun put(key: K, value: V): V? = throw FlowException("Broken on purpose")
|
||||
override fun putAll(from: Map<out K, V>) = map.putAll(from)
|
||||
override fun remove(key: K): V? = map.remove(key)
|
||||
}
|
||||
|
||||
// A class to test custom serializers applied to implementations
|
||||
class BrokenMapClass<K,V> : BrokenMapBaseImpl<K, V>()
|
||||
|
||||
// An interface and implementation to test custom serializers applied to interface types
|
||||
interface BrokenMapInterface<K, V> : MutableMap<K, V>
|
||||
class BrokenMapInterfaceImpl<K,V> : BrokenMapBaseImpl<K, V>(), BrokenMapInterface<K, V>
|
||||
|
||||
// An abstract class and implementation to test custom serializers applied to interface types
|
||||
abstract class BrokenMapAbstract<K, V> : BrokenMapBaseImpl<K, V>(), MutableMap<K, V>
|
||||
class BrokenMapAbstractImpl<K,V> : BrokenMapAbstract<K, V>()
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package net.corda.node.customcheckpointserializer
|
||||
|
||||
import co.paralleluniverse.fibers.Suspendable
|
||||
import net.corda.core.flows.FlowException
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import net.corda.testing.node.MockNetworkParameters
|
||||
import org.assertj.core.api.Assertions
|
||||
@ -36,7 +35,7 @@ class MockNetworkCustomCheckpointSerializerTest {
|
||||
@Test(timeout = 300_000)
|
||||
fun `check references are restored correctly`() {
|
||||
val node = mockNetwork.createPartyNode()
|
||||
val expectedReference = BrokenMapClass<String, Int>()
|
||||
val expectedReference = DifficultToSerialize.BrokenMapClass<String, Int>()
|
||||
expectedReference.putAll(mapOf("one" to 1))
|
||||
val actualReference = node.startFlow(CustomCheckpointSerializerCorDapp.TestFlowCheckingReferencesWork(expectedReference)).get()
|
||||
|
||||
@ -59,42 +58,4 @@ class MockNetworkCustomCheckpointSerializerTest {
|
||||
val result = node.startFlow(CustomCheckpointSerializerCorDapp.TestFlowWithDifficultToSerializeLocalVariableAsAbstract(5)).get()
|
||||
Assertions.assertThat(result).isEqualTo(5)
|
||||
}
|
||||
|
||||
|
||||
// Broken Map
|
||||
// This map breaks the rules for the put method. Making the normal map serializer fail.
|
||||
|
||||
open class BrokenMapBaseImpl<K,V> : MutableMap<K,V>{
|
||||
private val map = HashMap<K,V>()
|
||||
|
||||
override val size: Int
|
||||
get() = map.size
|
||||
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
|
||||
get() = map.entries
|
||||
override val keys: MutableSet<K>
|
||||
get() = map.keys
|
||||
override val values: MutableCollection<V>
|
||||
get() = map.values
|
||||
|
||||
override fun containsKey(key: K): Boolean = map.containsKey(key)
|
||||
override fun containsValue(value: V): Boolean = map.containsValue(value)
|
||||
override fun get(key: K): V? = map.get(key)
|
||||
override fun isEmpty(): Boolean = map.isEmpty()
|
||||
override fun clear() = map.clear()
|
||||
override fun put(key: K, value: V): V? = throw FlowException("Broken on purpose")
|
||||
override fun putAll(from: Map<out K, V>) = map.putAll(from)
|
||||
override fun remove(key: K): V? = map.remove(key)
|
||||
}
|
||||
|
||||
// A class to test custom serializers applied to implementations
|
||||
class BrokenMapClass<K,V> : BrokenMapBaseImpl<K, V>()
|
||||
|
||||
// An interface and implementation to test custom serializers applied to interface types
|
||||
interface BrokenMapInterface<K, V> : MutableMap<K, V>
|
||||
class BrokenMapInterfaceImpl<K,V> : BrokenMapBaseImpl<K, V>(), BrokenMapInterface<K, V>
|
||||
|
||||
// An abstract class and implementation to test custom serializers applied to interface types
|
||||
abstract class BrokenMapAbstract<K, V> : BrokenMapBaseImpl<K, V>(), MutableMap<K, V>
|
||||
class BrokenMapAbstractImpl<K,V> : BrokenMapAbstract<K, V>()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user