mirror of
https://github.com/corda/corda.git
synced 2025-06-06 09:21:47 +00:00
Minor: add logging to the RecordingMap unit test utility
This commit is contained in:
parent
b2b51183b8
commit
55989a8e92
@ -23,6 +23,7 @@ import core.testutils.RecordingMap
|
|||||||
import core.testutils.TEST_KEYS_TO_CORP_MAP
|
import core.testutils.TEST_KEYS_TO_CORP_MAP
|
||||||
import core.testutils.TEST_PROGRAM_MAP
|
import core.testutils.TEST_PROGRAM_MAP
|
||||||
import core.testutils.TEST_TX_TIME
|
import core.testutils.TEST_TX_TIME
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
import java.security.KeyPair
|
import java.security.KeyPair
|
||||||
import java.security.PrivateKey
|
import java.security.PrivateKey
|
||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
@ -67,7 +68,7 @@ class MockWalletService(val states: List<StateAndRef<OwnableState>>) : WalletSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
class MockStorageService(val isRecording: Boolean = false) : StorageService {
|
class MockStorageService(val recordingAs: Map<String, String>? = null) : StorageService {
|
||||||
override val myLegalIdentityKey: KeyPair = generateKeyPair()
|
override val myLegalIdentityKey: KeyPair = generateKeyPair()
|
||||||
override val myLegalIdentity: Party = Party("Unit test party", myLegalIdentityKey.public)
|
override val myLegalIdentity: Party = Party("Unit test party", myLegalIdentityKey.public)
|
||||||
|
|
||||||
@ -83,8 +84,8 @@ class MockStorageService(val isRecording: Boolean = false) : StorageService {
|
|||||||
synchronized(tables) {
|
synchronized(tables) {
|
||||||
return tables.getOrPut(tableName) {
|
return tables.getOrPut(tableName) {
|
||||||
val map = Collections.synchronizedMap(HashMap<Any, Any>())
|
val map = Collections.synchronizedMap(HashMap<Any, Any>())
|
||||||
if (isRecording)
|
if (recordingAs != null && recordingAs[tableName] != null)
|
||||||
RecordingMap(map)
|
RecordingMap(map, LoggerFactory.getLogger("recordingmap.${recordingAs[tableName]}"))
|
||||||
else
|
else
|
||||||
map
|
map
|
||||||
} as MutableMap<K, V>
|
} as MutableMap<K, V>
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package core.testutils
|
package core.testutils
|
||||||
|
|
||||||
|
import core.utilities.loggerFor
|
||||||
|
import org.slf4j.Logger
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.annotation.concurrent.ThreadSafe
|
import javax.annotation.concurrent.ThreadSafe
|
||||||
|
|
||||||
@ -26,7 +28,8 @@ import javax.annotation.concurrent.ThreadSafe
|
|||||||
* Note: although this class itself thread safe, if the underlying map is not, then this class loses its thread safety.
|
* Note: although this class itself thread safe, if the underlying map is not, then this class loses its thread safety.
|
||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
class RecordingMap<K, V>(private val wrappedMap: MutableMap<K, V>) : MutableMap<K, V> by wrappedMap {
|
class RecordingMap<K, V>(private val wrappedMap: MutableMap<K, V>,
|
||||||
|
private val logger: Logger = loggerFor<RecordingMap<K, V>>()) : MutableMap<K, V> by wrappedMap {
|
||||||
// If/when Kotlin supports data classes inside sealed classes, that would be preferable to this.
|
// If/when Kotlin supports data classes inside sealed classes, that would be preferable to this.
|
||||||
interface Record
|
interface Record
|
||||||
data class Get<K>(val key: K) : Record
|
data class Get<K>(val key: K) : Record
|
||||||
@ -41,11 +44,13 @@ class RecordingMap<K, V>(private val wrappedMap: MutableMap<K, V>) : MutableMap<
|
|||||||
|
|
||||||
override fun get(key: K): V? {
|
override fun get(key: K): V? {
|
||||||
_records.add(Get(key))
|
_records.add(Get(key))
|
||||||
|
logger.trace("GET ${logger.name} : $key = ${wrappedMap[key]}")
|
||||||
return wrappedMap[key]
|
return wrappedMap[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun put(key: K, value: V): V? {
|
override fun put(key: K, value: V): V? {
|
||||||
_records.add(Put(key, value))
|
_records.add(Put(key, value))
|
||||||
|
logger.trace("PUT ${logger.name} : $key = $value")
|
||||||
return wrappedMap.put(key, value)
|
return wrappedMap.put(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user