Move MockNode/InMemoryNetwork to the main sourceset, as these are useful not only for unit testing, but also simulation tools.

This commit is contained in:
Mike Hearn 2016-03-21 19:01:19 +00:00
parent 621c88b93a
commit b1694e2d0d
8 changed files with 17 additions and 23 deletions

View File

@ -107,9 +107,11 @@ dependencies {
// Coda Hale's Metrics: for monitoring of key statistics
compile "io.dropwizard.metrics:metrics-core:3.1.2"
// JimFS: in memory java.nio filesystem. Used for test and simulation utilities.
compile 'com.google.jimfs:jimfs:1.1'
// Unit testing helpers.
testCompile 'junit:junit:4.12'
testCompile 'com.google.jimfs:jimfs:1.1' // in memory java.nio filesystem.
}
// These lines tell Gradle to add a couple of JVM command line arguments to unit test and program runs, which set up

View File

@ -6,7 +6,7 @@
* All other rights reserved.
*/
package core.messaging
package core.testing
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
@ -14,6 +14,7 @@ import com.google.common.util.concurrent.MoreExecutors
import core.node.services.DummyTimestampingAuthority
import core.ThreadBox
import core.crypto.sha256
import core.messaging.*
import core.node.services.NodeTimestamperService
import core.utilities.loggerFor
import java.time.Instant

View File

@ -6,25 +6,16 @@
* All other rights reserved.
*/
/*
* Copyright 2015 Distributed Ledger Group LLC. Distributed as Licensed Company IP to DLG Group Members
* pursuant to the August 7, 2015 Advisory Services Agreement and subject to the Company IP License terms
* set forth therein.
*
* All other rights reserved.
*/
package core.testing
package core.node
import com.google.common.jimfs.Configuration
import com.google.common.jimfs.Jimfs
import com.google.common.util.concurrent.MoreExecutors
import core.Party
import core.messaging.InMemoryMessagingNetwork
import core.messaging.LegallyIdentifiableNode
import core.messaging.MessagingService
import core.node.AbstractNode
import core.node.NodeConfiguration
import core.node.services.FixedIdentityService
import core.testutils.TEST_KEYS_TO_CORP_MAP
import core.utilities.loggerFor
import org.slf4j.Logger
import java.nio.file.Files
@ -43,10 +34,10 @@ import java.util.concurrent.Executors
*/
class MockNetwork(private val threadPerNode: Boolean = false) {
private var counter = 0
val filesystem = Jimfs.newFileSystem(Configuration.unix())
val filesystem = Jimfs.newFileSystem(com.google.common.jimfs.Configuration.unix())
val messagingNetwork = InMemoryMessagingNetwork()
val identities = ArrayList<Party>(TEST_KEYS_TO_CORP_MAP.values)
val identities = ArrayList<Party>()
private val _nodes = ArrayList<MockNode>()
/** A read only view of the current set of executing nodes. */

View File

@ -13,7 +13,7 @@ import protocols.FetchDataProtocol
import core.Attachment
import core.crypto.SecureHash
import core.crypto.sha256
import core.node.MockNetwork
import core.testing.MockNetwork
import core.node.services.NodeAttachmentService
import core.serialization.OpaqueBytes
import core.testutils.rootCauseExceptions

View File

@ -11,6 +11,7 @@
package core.messaging
import core.serialization.deserialize
import core.testing.InMemoryMessagingNetwork
import org.junit.After
import org.junit.Before
import org.junit.Test

View File

@ -12,16 +12,15 @@ import contracts.Cash
import contracts.CommercialPaper
import core.*
import core.crypto.SecureHash
import core.node.MockNetwork
import core.node.services.*
import core.node.services.StorageServiceImpl
import core.testing.InMemoryMessagingNetwork
import core.testing.MockNetwork
import core.testutils.*
import core.utilities.BriefLogFormatter
import core.utilities.RecordingMap
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.slf4j.LoggerFactory
import protocols.TwoPartyTradeProtocol
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
@ -36,8 +35,6 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
// TODO: Refactor this test to use the MockNode class, which will clean this file up significantly.
/**
* In this example, Alice wishes to sell her commercial paper to Bob in return for $1,000,000 and they wish to do
* it on the ledger atomically. Therefore they must work together to build a transaction.
@ -50,6 +47,7 @@ class TwoPartyTradeProtocolTests : TestWithInMemoryNetwork() {
@Before
fun before() {
net = MockNetwork(false)
net.identities += TEST_KEYS_TO_CORP_MAP.values
BriefLogFormatter.loggingOn("platform.trade", "core.TransactionGroup", "recordingmap")
}

View File

@ -17,6 +17,7 @@ import core.node.services.ServiceHub
import core.node.services.TimestampingError
import core.protocols.ProtocolLogic
import core.serialization.serialize
import core.testing.InMemoryMessagingNetwork
import core.testutils.ALICE
import core.testutils.ALICE_KEY
import core.testutils.CASH

View File

@ -10,7 +10,7 @@ package core.node.services
import contracts.Cash
import core.*
import core.node.MockNetwork
import core.testing.MockNetwork
import core.testutils.*
import core.utilities.BriefLogFormatter
import org.junit.Test