mirror of
https://github.com/corda/corda.git
synced 2025-01-18 10:46:38 +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_PROGRAM_MAP
|
||||
import core.testutils.TEST_TX_TIME
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.security.KeyPair
|
||||
import java.security.PrivateKey
|
||||
import java.security.PublicKey
|
||||
@ -67,7 +68,7 @@ class MockWalletService(val states: List<StateAndRef<OwnableState>>) : WalletSer
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
class MockStorageService(val isRecording: Boolean = false) : StorageService {
|
||||
class MockStorageService(val recordingAs: Map<String, String>? = null) : StorageService {
|
||||
override val myLegalIdentityKey: KeyPair = generateKeyPair()
|
||||
override val myLegalIdentity: Party = Party("Unit test party", myLegalIdentityKey.public)
|
||||
|
||||
@ -83,8 +84,8 @@ class MockStorageService(val isRecording: Boolean = false) : StorageService {
|
||||
synchronized(tables) {
|
||||
return tables.getOrPut(tableName) {
|
||||
val map = Collections.synchronizedMap(HashMap<Any, Any>())
|
||||
if (isRecording)
|
||||
RecordingMap(map)
|
||||
if (recordingAs != null && recordingAs[tableName] != null)
|
||||
RecordingMap(map, LoggerFactory.getLogger("recordingmap.${recordingAs[tableName]}"))
|
||||
else
|
||||
map
|
||||
} as MutableMap<K, V>
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package core.testutils
|
||||
|
||||
import core.utilities.loggerFor
|
||||
import org.slf4j.Logger
|
||||
import java.util.*
|
||||
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.
|
||||
*/
|
||||
@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.
|
||||
interface 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? {
|
||||
_records.add(Get(key))
|
||||
logger.trace("GET ${logger.name} : $key = ${wrappedMap[key]}")
|
||||
return wrappedMap[key]
|
||||
}
|
||||
|
||||
override fun put(key: K, value: V): V? {
|
||||
_records.add(Put(key, value))
|
||||
logger.trace("PUT ${logger.name} : $key = $value")
|
||||
return wrappedMap.put(key, value)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user