From 07f44e9e2a2b16e9bd66bc470ddca816f1eafa1a Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Wed, 31 Aug 2016 14:13:28 +0100 Subject: [PATCH 1/2] Move test code from node to test-utils --- build.gradle | 2 + .../ResolveTransactionsProtocolTest.kt | 2 +- node/build.gradle | 2 +- .../r3corda/node/messaging/AttachmentTests.kt | 2 +- .../node/messaging/InMemoryMessagingTests.kt | 2 +- .../messaging/TwoPartyTradeProtocolTests.kt | 4 +- .../services/InMemoryNetworkMapCacheTest.kt | 2 +- .../services/InMemoryNetworkMapServiceTest.kt | 2 +- .../node/services/MockServiceHubInternal.kt | 2 +- .../node/services/NodeInterestRatesTest.kt | 2 +- .../node/services/NodeSchedulerServiceTest.kt | 4 +- .../node/services/NotaryChangeTests.kt | 2 +- .../node/services/NotaryServiceTests.kt | 2 +- .../services/ValidatingNotaryServiceTests.kt | 2 +- .../services/WalletMonitorServiceTests.kt | 2 +- .../persistence/DataVendingServiceTests.kt | 2 +- .../statemachine/StateMachineManagerTests.kt | 2 +- .../r3corda/node/utilities/ClockUtilsTest.kt | 2 +- .../r3corda/node/utilities/FiberBoxTest.kt | 2 +- src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 2 +- .../demos/protocols/ExitServerProtocol.kt | 2 +- .../protocols/UpdateBusinessDayProtocol.kt | 2 +- .../r3corda/core/testing/IRSSimulationTest.kt | 2 +- test-utils/build.gradle | 5 +++ .../r3corda/testing/node}/IRSSimulation.kt | 11 ++--- .../testing/node}/InMemoryMessagingNetwork.kt | 12 +++--- .../testing/node}/MockNetworkMapCache.kt | 4 +- .../com/r3corda/testing/node}/MockNode.kt | 40 +++++++---------- .../com/r3corda/testing/node}/Simulation.kt | 43 +++++++++---------- .../com/r3corda/testing/node}/TestClock.kt | 4 +- .../r3corda/testing/node}/TradeSimulation.kt | 15 +++---- 31 files changed, 87 insertions(+), 97 deletions(-) rename {node/src/main/kotlin/com/r3corda/node/internal/testing => test-utils/src/main/kotlin/com/r3corda/testing/node}/IRSSimulation.kt (92%) rename {node/src/main/kotlin/com/r3corda/node/services/network => test-utils/src/main/kotlin/com/r3corda/testing/node}/InMemoryMessagingNetwork.kt (97%) rename {node/src/main/kotlin/com/r3corda/node/services/network => test-utils/src/main/kotlin/com/r3corda/testing/node}/MockNetworkMapCache.kt (92%) rename {node/src/main/kotlin/com/r3corda/node/internal/testing => test-utils/src/main/kotlin/com/r3corda/testing/node}/MockNode.kt (83%) rename {node/src/main/kotlin/com/r3corda/node/internal/testing => test-utils/src/main/kotlin/com/r3corda/testing/node}/Simulation.kt (83%) rename {node/src/main/kotlin/com/r3corda/node/internal/testing => test-utils/src/main/kotlin/com/r3corda/testing/node}/TestClock.kt (95%) rename {node/src/main/kotlin/com/r3corda/node/internal/testing => test-utils/src/main/kotlin/com/r3corda/testing/node}/TradeSimulation.kt (80%) diff --git a/build.gradle b/build.gradle index bac83cfec4..752a4988d7 100644 --- a/build.gradle +++ b/build.gradle @@ -102,6 +102,8 @@ mainClassName = 'com.r3corda.demos.TraderDemoKt' dependencies { compile project(':node') + // TODO: Demos should not depend on test code, but only use production APIs + compile project(':test-utils') compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" diff --git a/core/src/test/kotlin/com/r3corda/core/protocols/ResolveTransactionsProtocolTest.kt b/core/src/test/kotlin/com/r3corda/core/protocols/ResolveTransactionsProtocolTest.kt index 0a29b85733..f77955bd8d 100644 --- a/core/src/test/kotlin/com/r3corda/core/protocols/ResolveTransactionsProtocolTest.kt +++ b/core/src/test/kotlin/com/r3corda/core/protocols/ResolveTransactionsProtocolTest.kt @@ -7,7 +7,7 @@ import com.r3corda.core.crypto.Party import com.r3corda.core.crypto.SecureHash import com.r3corda.core.serialization.opaque import com.r3corda.core.utilities.DUMMY_NOTARY_KEY -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.protocols.ResolveTransactionsProtocol import com.r3corda.testing.* import org.junit.After diff --git a/node/build.gradle b/node/build.gradle index e2d8528f9f..cf9c285d26 100644 --- a/node/build.gradle +++ b/node/build.gradle @@ -34,7 +34,7 @@ sourceSets { dependencies { compile project(':contracts') - compile project(':test-utils') + testCompile project(':test-utils') compile "com.google.code.findbugs:jsr305:3.0.1" diff --git a/node/src/test/kotlin/com/r3corda/node/messaging/AttachmentTests.kt b/node/src/test/kotlin/com/r3corda/node/messaging/AttachmentTests.kt index ee19616e4a..4ff60c09b5 100644 --- a/node/src/test/kotlin/com/r3corda/node/messaging/AttachmentTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/messaging/AttachmentTests.kt @@ -6,7 +6,7 @@ import com.r3corda.core.crypto.sha256 import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.services.ServiceType import com.r3corda.core.serialization.OpaqueBytes -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.config.NodeConfiguration import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.persistence.NodeAttachmentService diff --git a/node/src/test/kotlin/com/r3corda/node/messaging/InMemoryMessagingTests.kt b/node/src/test/kotlin/com/r3corda/node/messaging/InMemoryMessagingTests.kt index 0f3433d6f9..2bdc1439a6 100644 --- a/node/src/test/kotlin/com/r3corda/node/messaging/InMemoryMessagingTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/messaging/InMemoryMessagingTests.kt @@ -5,7 +5,7 @@ package com.r3corda.node.messaging import com.r3corda.core.messaging.Message import com.r3corda.core.messaging.TopicStringValidator import com.r3corda.core.node.services.DEFAULT_SESSION_ID -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import org.junit.Before import org.junit.Test import java.util.* diff --git a/node/src/test/kotlin/com/r3corda/node/messaging/TwoPartyTradeProtocolTests.kt b/node/src/test/kotlin/com/r3corda/node/messaging/TwoPartyTradeProtocolTests.kt index 6b028b50b6..f7f0fbb996 100644 --- a/node/src/test/kotlin/com/r3corda/node/messaging/TwoPartyTradeProtocolTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/messaging/TwoPartyTradeProtocolTests.kt @@ -18,9 +18,9 @@ import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.DUMMY_NOTARY_KEY import com.r3corda.core.utilities.LogHelper import com.r3corda.core.utilities.TEST_TX_TIME -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.config.NodeConfiguration -import com.r3corda.node.services.network.InMemoryMessagingNetwork +import com.r3corda.testing.node.InMemoryMessagingNetwork import com.r3corda.node.services.persistence.NodeAttachmentService import com.r3corda.node.services.persistence.PerFileTransactionStorage import com.r3corda.node.services.persistence.StorageServiceImpl diff --git a/node/src/test/kotlin/com/r3corda/node/services/InMemoryNetworkMapCacheTest.kt b/node/src/test/kotlin/com/r3corda/node/services/InMemoryNetworkMapCacheTest.kt index f1f5d9f238..c4c74a3cac 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/InMemoryNetworkMapCacheTest.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/InMemoryNetworkMapCacheTest.kt @@ -1,6 +1,6 @@ package com.r3corda.node.services -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import org.junit.Before import org.junit.Test diff --git a/node/src/test/kotlin/com/r3corda/node/services/InMemoryNetworkMapServiceTest.kt b/node/src/test/kotlin/com/r3corda/node/services/InMemoryNetworkMapServiceTest.kt index 33a3e29fc8..a5601f54ee 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/InMemoryNetworkMapServiceTest.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/InMemoryNetworkMapServiceTest.kt @@ -5,7 +5,7 @@ import com.r3corda.core.crypto.SecureHash import com.r3corda.core.node.NodeInfo import com.r3corda.core.protocols.ProtocolLogic import com.r3corda.core.random63BitValue -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.network.InMemoryNetworkMapService import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.network.NodeRegistration diff --git a/node/src/test/kotlin/com/r3corda/node/services/MockServiceHubInternal.kt b/node/src/test/kotlin/com/r3corda/node/services/MockServiceHubInternal.kt index 62aa61630b..696a3644f3 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/MockServiceHubInternal.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/MockServiceHubInternal.kt @@ -10,7 +10,7 @@ import com.r3corda.node.serialization.NodeClock import com.r3corda.node.services.api.MessagingServiceInternal import com.r3corda.node.services.api.MonitoringService import com.r3corda.node.services.api.ServiceHubInternal -import com.r3corda.node.services.network.MockNetworkMapCache +import com.r3corda.testing.node.MockNetworkMapCache import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.persistence.DataVending import com.r3corda.node.services.statemachine.StateMachineManager diff --git a/node/src/test/kotlin/com/r3corda/node/services/NodeInterestRatesTest.kt b/node/src/test/kotlin/com/r3corda/node/services/NodeInterestRatesTest.kt index 28ea6d5453..cab98cf3c6 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/NodeInterestRatesTest.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/NodeInterestRatesTest.kt @@ -13,7 +13,7 @@ import com.r3corda.core.crypto.Party import com.r3corda.core.crypto.generateKeyPair import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.LogHelper -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.clientapi.NodeInterestRates import com.r3corda.protocols.RatesFixProtocol import com.r3corda.testing.ALICE_PUBKEY diff --git a/node/src/test/kotlin/com/r3corda/node/services/NodeSchedulerServiceTest.kt b/node/src/test/kotlin/com/r3corda/node/services/NodeSchedulerServiceTest.kt index ae451f54b8..902f108ba9 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/NodeSchedulerServiceTest.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/NodeSchedulerServiceTest.kt @@ -11,9 +11,9 @@ import com.r3corda.core.protocols.ProtocolLogicRef import com.r3corda.core.protocols.ProtocolLogicRefFactory import com.r3corda.core.serialization.SingletonSerializeAsToken import com.r3corda.core.utilities.DUMMY_NOTARY -import com.r3corda.node.internal.testing.TestClock +import com.r3corda.testing.node.TestClock import com.r3corda.node.services.events.NodeSchedulerService -import com.r3corda.node.services.network.InMemoryMessagingNetwork +import com.r3corda.testing.node.InMemoryMessagingNetwork import com.r3corda.node.services.persistence.PerFileCheckpointStorage import com.r3corda.node.services.statemachine.StateMachineManager import com.r3corda.node.utilities.AffinityExecutor diff --git a/node/src/test/kotlin/com/r3corda/node/services/NotaryChangeTests.kt b/node/src/test/kotlin/com/r3corda/node/services/NotaryChangeTests.kt index 9ccbb2c008..037e059002 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/NotaryChangeTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/NotaryChangeTests.kt @@ -7,7 +7,7 @@ import com.r3corda.core.seconds import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.DUMMY_NOTARY_KEY import com.r3corda.node.internal.AbstractNode -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.transactions.SimpleNotaryService import com.r3corda.protocols.NotaryChangeProtocol diff --git a/node/src/test/kotlin/com/r3corda/node/services/NotaryServiceTests.kt b/node/src/test/kotlin/com/r3corda/node/services/NotaryServiceTests.kt index d60deb82b5..05a612ef03 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/NotaryServiceTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/NotaryServiceTests.kt @@ -5,7 +5,7 @@ import com.r3corda.core.contracts.TransactionType import com.r3corda.core.seconds import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.DUMMY_NOTARY_KEY -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.transactions.SimpleNotaryService import com.r3corda.protocols.NotaryError diff --git a/node/src/test/kotlin/com/r3corda/node/services/ValidatingNotaryServiceTests.kt b/node/src/test/kotlin/com/r3corda/node/services/ValidatingNotaryServiceTests.kt index adf7e4b920..42c701632c 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/ValidatingNotaryServiceTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/ValidatingNotaryServiceTests.kt @@ -5,7 +5,7 @@ import com.r3corda.core.contracts.DummyContract import com.r3corda.core.contracts.TransactionType import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.DUMMY_NOTARY_KEY -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.transactions.ValidatingNotaryService import com.r3corda.protocols.NotaryError diff --git a/node/src/test/kotlin/com/r3corda/node/services/WalletMonitorServiceTests.kt b/node/src/test/kotlin/com/r3corda/node/services/WalletMonitorServiceTests.kt index 41e2cb4cf7..c8317435ab 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/WalletMonitorServiceTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/WalletMonitorServiceTests.kt @@ -16,7 +16,7 @@ import com.r3corda.core.serialization.deserialize import com.r3corda.core.serialization.serialize import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.DUMMY_PUBKEY_1 -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.monitor.* import org.junit.Before import org.junit.Test diff --git a/node/src/test/kotlin/com/r3corda/node/services/persistence/DataVendingServiceTests.kt b/node/src/test/kotlin/com/r3corda/node/services/persistence/DataVendingServiceTests.kt index 821a88593f..bb19fe2c02 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/persistence/DataVendingServiceTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/persistence/DataVendingServiceTests.kt @@ -6,7 +6,7 @@ import com.r3corda.core.contracts.Issued import com.r3corda.core.contracts.TransactionType import com.r3corda.core.contracts.USD import com.r3corda.core.utilities.DUMMY_NOTARY -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.testing.MEGA_CORP import org.junit.Before import org.junit.Test diff --git a/node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt b/node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt index 3f65e77526..8151c016c8 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt @@ -7,7 +7,7 @@ import com.r3corda.node.services.MockServiceHubInternal import com.r3corda.node.services.api.Checkpoint import com.r3corda.node.services.api.CheckpointStorage import com.r3corda.node.services.api.MessagingServiceInternal -import com.r3corda.node.services.network.InMemoryMessagingNetwork +import com.r3corda.testing.node.InMemoryMessagingNetwork import com.r3corda.node.utilities.AffinityExecutor import org.assertj.core.api.Assertions.assertThat import org.junit.After diff --git a/node/src/test/kotlin/com/r3corda/node/utilities/ClockUtilsTest.kt b/node/src/test/kotlin/com/r3corda/node/utilities/ClockUtilsTest.kt index faf7b1a7ee..be64fb16ca 100644 --- a/node/src/test/kotlin/com/r3corda/node/utilities/ClockUtilsTest.kt +++ b/node/src/test/kotlin/com/r3corda/node/utilities/ClockUtilsTest.kt @@ -5,7 +5,7 @@ import co.paralleluniverse.fibers.FiberExecutorScheduler import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.strands.Strand import com.google.common.util.concurrent.SettableFuture -import com.r3corda.node.internal.testing.TestClock +import com.r3corda.testing.node.TestClock import org.junit.After import org.junit.Before import org.junit.Test diff --git a/node/src/test/kotlin/com/r3corda/node/utilities/FiberBoxTest.kt b/node/src/test/kotlin/com/r3corda/node/utilities/FiberBoxTest.kt index 1702422398..69c9316c1a 100644 --- a/node/src/test/kotlin/com/r3corda/node/utilities/FiberBoxTest.kt +++ b/node/src/test/kotlin/com/r3corda/node/utilities/FiberBoxTest.kt @@ -5,7 +5,7 @@ import co.paralleluniverse.fibers.FiberExecutorScheduler import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.strands.Strand import com.r3corda.core.RetryableException -import com.r3corda.node.internal.testing.TestClock +import com.r3corda.testing.node.TestClock import org.junit.After import org.junit.Before import org.junit.Test diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index 3138b98073..0e5d161949 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -19,7 +19,7 @@ import com.r3corda.demos.utilities.putJson import com.r3corda.demos.utilities.uploadFile import com.r3corda.node.internal.AbstractNode import com.r3corda.node.internal.Node -import com.r3corda.node.internal.testing.MockNetwork +import com.r3corda.testing.node.MockNetwork import com.r3corda.node.services.clientapi.NodeInterestRates import com.r3corda.node.services.config.NodeConfiguration import com.r3corda.node.services.config.NodeConfigurationFromConfig diff --git a/src/main/kotlin/com/r3corda/demos/protocols/ExitServerProtocol.kt b/src/main/kotlin/com/r3corda/demos/protocols/ExitServerProtocol.kt index d28b9a2910..7789e157fd 100644 --- a/src/main/kotlin/com/r3corda/demos/protocols/ExitServerProtocol.kt +++ b/src/main/kotlin/com/r3corda/demos/protocols/ExitServerProtocol.kt @@ -8,7 +8,7 @@ import com.r3corda.core.node.services.DEFAULT_SESSION_ID import com.r3corda.core.protocols.ProtocolLogic import com.r3corda.core.serialization.deserialize import com.r3corda.node.services.api.ServiceHubInternal -import com.r3corda.node.services.network.MockNetworkMapCache +import com.r3corda.testing.node.MockNetworkMapCache import java.util.concurrent.TimeUnit diff --git a/src/main/kotlin/com/r3corda/demos/protocols/UpdateBusinessDayProtocol.kt b/src/main/kotlin/com/r3corda/demos/protocols/UpdateBusinessDayProtocol.kt index 4edad7436e..4e72a060bf 100644 --- a/src/main/kotlin/com/r3corda/demos/protocols/UpdateBusinessDayProtocol.kt +++ b/src/main/kotlin/com/r3corda/demos/protocols/UpdateBusinessDayProtocol.kt @@ -10,7 +10,7 @@ import com.r3corda.core.utilities.ProgressTracker import com.r3corda.demos.DemoClock import com.r3corda.node.internal.Node import com.r3corda.node.services.api.ServiceHubInternal -import com.r3corda.node.services.network.MockNetworkMapCache +import com.r3corda.testing.node.MockNetworkMapCache import java.time.LocalDate /** diff --git a/src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt b/src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt index 62bd0ac797..1889536cad 100644 --- a/src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt +++ b/src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt @@ -2,7 +2,7 @@ package com.r3corda.core.testing import com.google.common.base.Throwables import com.r3corda.core.utilities.LogHelper -import com.r3corda.node.internal.testing.IRSSimulation +import com.r3corda.testing.node.IRSSimulation import org.junit.Test class IRSSimulationTest { diff --git a/test-utils/build.gradle b/test-utils/build.gradle index 01edd0a091..d22df345a1 100644 --- a/test-utils/build.gradle +++ b/test-utils/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'kotlin' +apply plugin: QuasarPlugin repositories { mavenLocal() @@ -20,7 +21,9 @@ configurations { } dependencies { + compile project(':contracts') compile project(':core') + compile project(':node') // Log4J: logging framework (with SLF4J bindings) compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}" @@ -38,3 +41,5 @@ dependencies { // Unit testing helpers. compile 'junit:junit:4.12' } + +quasarScan.dependsOn('classes', ':core:classes', ':contracts:classes') diff --git a/node/src/main/kotlin/com/r3corda/node/internal/testing/IRSSimulation.kt b/test-utils/src/main/kotlin/com/r3corda/testing/node/IRSSimulation.kt similarity index 92% rename from node/src/main/kotlin/com/r3corda/node/internal/testing/IRSSimulation.kt rename to test-utils/src/main/kotlin/com/r3corda/testing/node/IRSSimulation.kt index df9682cd8f..a1d71a3263 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/testing/IRSSimulation.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/node/IRSSimulation.kt @@ -1,4 +1,4 @@ -package com.r3corda.node.internal.testing +package com.r3corda.testing.node import com.fasterxml.jackson.module.kotlin.readValue import com.google.common.util.concurrent.FutureCallback @@ -12,11 +12,8 @@ import com.r3corda.core.contracts.StateAndRef import com.r3corda.core.contracts.UniqueIdentifier import com.r3corda.core.failure import com.r3corda.core.node.services.linearHeadsOfType -import com.r3corda.testing.node.MockIdentityService import com.r3corda.core.random63BitValue import com.r3corda.core.success -import com.r3corda.node.services.network.InMemoryMessagingNetwork -import com.r3corda.node.utilities.JsonSupport import com.r3corda.protocols.TwoPartyDealProtocol import java.security.KeyPair import java.time.LocalDate @@ -27,7 +24,7 @@ import java.util.* * A simulation in which banks execute interest rate swaps with each other, including the fixing events. */ class IRSSimulation(networkSendManuallyPumped: Boolean, runAsync: Boolean, latencyInjector: InMemoryMessagingNetwork.LatencyCalculator?) : Simulation(networkSendManuallyPumped, runAsync, latencyInjector) { - val om = JsonSupport.createDefaultMapper(MockIdentityService(network.identities)) + val om = com.r3corda.node.utilities.JsonSupport.createDefaultMapper(MockIdentityService(network.identities)) init { currentDateAndTime = LocalDate.of(2016, 3, 8).atStartOfDay() @@ -80,7 +77,7 @@ class IRSSimulation(networkSendManuallyPumped: Boolean, runAsync: Boolean, laten val node1: SimulatedNode = banks[i] val node2: SimulatedNode = banks[j] - val swaps: Map> = node1.services.walletService.linearHeadsOfType() + val swaps: Map> = node1.services.walletService.linearHeadsOfType() val theDealRef: StateAndRef = swaps.values.single() // Do we have any more days left in this deal's lifetime? If not, return. @@ -118,7 +115,7 @@ class IRSSimulation(networkSendManuallyPumped: Boolean, runAsync: Boolean, laten // We load the IRS afresh each time because the leg parts of the structure aren't data classes so they don't // have the convenient copy() method that'd let us make small adjustments. Instead they're partly mutable. // TODO: We should revisit this in post-Excalibur cleanup and fix, e.g. by introducing an interface. - val irs = om.readValue(javaClass.getResource("trade.json")) + val irs = om.readValue(javaClass.getResource("trade.json")) irs.fixedLeg.fixedRatePayer = node1.info.identity irs.floatingLeg.floatingRatePayer = node2.info.identity diff --git a/node/src/main/kotlin/com/r3corda/node/services/network/InMemoryMessagingNetwork.kt b/test-utils/src/main/kotlin/com/r3corda/testing/node/InMemoryMessagingNetwork.kt similarity index 97% rename from node/src/main/kotlin/com/r3corda/node/services/network/InMemoryMessagingNetwork.kt rename to test-utils/src/main/kotlin/com/r3corda/testing/node/InMemoryMessagingNetwork.kt index 7bc0cd20ca..5e38895a9d 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/network/InMemoryMessagingNetwork.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/node/InMemoryMessagingNetwork.kt @@ -1,4 +1,4 @@ -package com.r3corda.node.services.network +package com.r3corda.testing.node import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture @@ -12,7 +12,7 @@ import com.r3corda.core.utilities.loggerFor import com.r3corda.core.utilities.trace import com.r3corda.node.services.api.MessagingServiceBuilder import com.r3corda.node.services.api.MessagingServiceInternal -import com.r3corda.node.services.network.InMemoryMessagingNetwork.InMemoryMessaging +import com.r3corda.testing.node.InMemoryMessagingNetwork.InMemoryMessaging import org.slf4j.LoggerFactory import rx.Observable import rx.subjects.PublishSubject @@ -80,7 +80,7 @@ class InMemoryMessagingNetwork(val sendManuallyPumped: Boolean) : SingletonSeria * executor. */ @Synchronized - fun createNode(manuallyPumped: Boolean): Pair> { + fun createNode(manuallyPumped: Boolean): Pair> { check(counter >= 0) { "In memory network stopped: please recreate." } val builder = createNodeWithID(manuallyPumped, counter) as Builder counter++ @@ -95,7 +95,7 @@ class InMemoryMessagingNetwork(val sendManuallyPumped: Boolean) : SingletonSeria * @param id the numeric ID to use, e.g. set to whatever ID the node used last time. * @param description text string that identifies this node for message logging (if is enabled) or null to autogenerate. */ - fun createNodeWithID(manuallyPumped: Boolean, id: Int, description: String? = null): MessagingServiceBuilder { + fun createNodeWithID(manuallyPumped: Boolean, id: Int, description: String? = null): com.r3corda.node.services.api.MessagingServiceBuilder { return Builder(manuallyPumped, Handle(id, description ?: "In memory node $id")) } @@ -136,7 +136,7 @@ class InMemoryMessagingNetwork(val sendManuallyPumped: Boolean) : SingletonSeria messageReceiveQueues.clear() } - inner class Builder(val manuallyPumped: Boolean, val id: Handle) : MessagingServiceBuilder { + inner class Builder(val manuallyPumped: Boolean, val id: Handle) : com.r3corda.node.services.api.MessagingServiceBuilder { override fun start(): ListenableFuture { synchronized(this@InMemoryMessagingNetwork) { val node = InMemoryMessaging(manuallyPumped, id) @@ -200,7 +200,7 @@ class InMemoryMessagingNetwork(val sendManuallyPumped: Boolean) : SingletonSeria * An instance can be obtained by creating a builder and then using the start method. */ @ThreadSafe - inner class InMemoryMessaging(private val manuallyPumped: Boolean, private val handle: Handle) : SingletonSerializeAsToken(), MessagingServiceInternal { + inner class InMemoryMessaging(private val manuallyPumped: Boolean, private val handle: Handle) : SingletonSerializeAsToken(), com.r3corda.node.services.api.MessagingServiceInternal { inner class Handler(val executor: Executor?, val topicSession: TopicSession, val callback: (Message, MessageHandlerRegistration) -> Unit) : MessageHandlerRegistration diff --git a/node/src/main/kotlin/com/r3corda/node/services/network/MockNetworkMapCache.kt b/test-utils/src/main/kotlin/com/r3corda/testing/node/MockNetworkMapCache.kt similarity index 92% rename from node/src/main/kotlin/com/r3corda/node/services/network/MockNetworkMapCache.kt rename to test-utils/src/main/kotlin/com/r3corda/testing/node/MockNetworkMapCache.kt index bc37111f63..8bcfe7694e 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/network/MockNetworkMapCache.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/node/MockNetworkMapCache.kt @@ -1,4 +1,4 @@ -package com.r3corda.node.services.network +package com.r3corda.testing.node import co.paralleluniverse.common.util.VisibleForTesting import com.r3corda.core.crypto.DummyPublicKey @@ -12,7 +12,7 @@ import rx.subjects.PublishSubject /** * Network map cache with no backing map service. */ -class MockNetworkMapCache() : InMemoryNetworkMapCache() { +class MockNetworkMapCache() : com.r3corda.node.services.network.InMemoryNetworkMapCache() { override val changed: Observable = PublishSubject.create() data class MockAddress(val id: String): SingleMessageRecipient diff --git a/node/src/main/kotlin/com/r3corda/node/internal/testing/MockNode.kt b/test-utils/src/main/kotlin/com/r3corda/testing/node/MockNode.kt similarity index 83% rename from node/src/main/kotlin/com/r3corda/node/internal/testing/MockNode.kt rename to test-utils/src/main/kotlin/com/r3corda/testing/node/MockNode.kt index 6896a31466..342395ceb8 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/testing/MockNode.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/node/MockNode.kt @@ -1,6 +1,5 @@ -package com.r3corda.node.internal.testing +package com.r3corda.testing.node -import com.google.common.jimfs.Configuration import com.google.common.jimfs.Jimfs import com.google.common.util.concurrent.Futures import com.r3corda.core.crypto.Party @@ -9,18 +8,9 @@ import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.PhysicalLocation import com.r3corda.core.node.services.ServiceType import com.r3corda.core.node.services.WalletService -import com.r3corda.testing.node.MockIdentityService -import com.r3corda.testing.node.makeTestDataSourceProperties import com.r3corda.core.testing.InMemoryWalletService import com.r3corda.core.utilities.DUMMY_NOTARY_KEY import com.r3corda.core.utilities.loggerFor -import com.r3corda.node.internal.AbstractNode -import com.r3corda.node.services.api.MessagingServiceInternal -import com.r3corda.node.services.config.NodeConfiguration -import com.r3corda.node.services.network.InMemoryMessagingNetwork -import com.r3corda.node.services.network.NetworkMapService -import com.r3corda.node.services.transactions.SimpleNotaryService -import com.r3corda.node.utilities.AffinityExecutor import org.slf4j.Logger import java.nio.file.Files import java.nio.file.Path @@ -43,7 +33,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, private val threadPerNode: Boolean = false, private val defaultFactory: Factory = MockNetwork.DefaultFactory) { private var counter = 0 - val filesystem = Jimfs.newFileSystem(Configuration.unix()) + val filesystem = com.google.common.jimfs.Jimfs.newFileSystem(com.google.common.jimfs.Configuration.unix()) val messagingNetwork = InMemoryMessagingNetwork(networkSendManuallyPumped) val identities = ArrayList() @@ -58,30 +48,30 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, /** Allows customisation of how nodes are created. */ interface Factory { - fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNode } object DefaultFactory : Factory { - override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNode { return MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair) } } - open class MockNode(dir: Path, config: NodeConfiguration, val mockNet: MockNetwork, networkMapAddr: NodeInfo?, - advertisedServices: Set, val id: Int, val keyPair: KeyPair?) : AbstractNode(dir, config, networkMapAddr, advertisedServices, TestClock()) { + open class MockNode(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, val mockNet: MockNetwork, networkMapAddr: NodeInfo?, + advertisedServices: Set, val id: Int, val keyPair: KeyPair?) : com.r3corda.node.internal.AbstractNode(dir, config, networkMapAddr, advertisedServices, TestClock()) { override val log: Logger = loggerFor() - override val serverThread: AffinityExecutor = + override val serverThread: com.r3corda.node.utilities.AffinityExecutor = if (mockNet.threadPerNode) - AffinityExecutor.ServiceAffinityExecutor("Mock node thread", 1) + com.r3corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor("Mock node thread", 1) else - AffinityExecutor.SAME_THREAD + com.r3corda.node.utilities.AffinityExecutor.Companion.SAME_THREAD // We only need to override the messaging service here, as currently everything that hits disk does so // through the java.nio API which we are already mocking via Jimfs. - override fun makeMessagingService(): MessagingServiceInternal { + override fun makeMessagingService(): com.r3corda.node.services.api.MessagingServiceInternal { require(id >= 0) { "Node ID must be zero or positive, was passed: " + id } return mockNet.messagingNetwork.createNodeWithID(!mockNet.threadPerNode, id, configuration.myLegalName).start().get() } @@ -123,7 +113,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, val path = filesystem.getPath("/nodes/$id") if (newNode) Files.createDirectories(path.resolve("attachments")) - val config = object : NodeConfiguration { + val config = object : com.r3corda.node.services.config.NodeConfiguration { override val myLegalName: String = legalName ?: "Mock Company $id" override val exportJMXto: String = "" override val nearestCity: String = "Atlantis" @@ -169,7 +159,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, fun createTwoNodes(nodeFactory: Factory = defaultFactory, notaryKeyPair: KeyPair? = null): Pair { require(nodes.isEmpty()) return Pair( - createNode(null, -1, nodeFactory, true, null, notaryKeyPair, false, NetworkMapService.Type, SimpleNotaryService.Type), + createNode(null, -1, nodeFactory, true, null, notaryKeyPair, false, com.r3corda.node.services.network.NetworkMapService.Type, com.r3corda.node.services.transactions.SimpleNotaryService.Type), createNode(nodes[0].info, -1, nodeFactory, true, null) ) } @@ -186,9 +176,9 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, */ fun createSomeNodes(numPartyNodes: Int = 2, nodeFactory: Factory = defaultFactory, notaryKeyPair: KeyPair? = DUMMY_NOTARY_KEY): BasketOfNodes { require(nodes.isEmpty()) - val mapNode = createNode(null, nodeFactory = nodeFactory, advertisedServices = NetworkMapService.Type) + val mapNode = createNode(null, nodeFactory = nodeFactory, advertisedServices = com.r3corda.node.services.network.NetworkMapService.Type) val notaryNode = createNode(mapNode.info, nodeFactory = nodeFactory, keyPair = notaryKeyPair, - advertisedServices = SimpleNotaryService.Type) + advertisedServices = com.r3corda.node.services.transactions.SimpleNotaryService.Type) val nodes = ArrayList() repeat(numPartyNodes) { nodes += createPartyNode(mapNode.info) @@ -197,7 +187,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, } fun createNotaryNode(legalName: String? = null, keyPair: KeyPair? = null): MockNode { - return createNode(null, -1, defaultFactory, true, legalName, keyPair, false, NetworkMapService.Type, SimpleNotaryService.Type) + return createNode(null, -1, defaultFactory, true, legalName, keyPair, false, com.r3corda.node.services.network.NetworkMapService.Type, com.r3corda.node.services.transactions.SimpleNotaryService.Type) } fun createPartyNode(networkMapAddr: NodeInfo, legalName: String? = null, keyPair: KeyPair? = null): MockNode { diff --git a/node/src/main/kotlin/com/r3corda/node/internal/testing/Simulation.kt b/test-utils/src/main/kotlin/com/r3corda/testing/node/Simulation.kt similarity index 83% rename from node/src/main/kotlin/com/r3corda/node/internal/testing/Simulation.kt rename to test-utils/src/main/kotlin/com/r3corda/testing/node/Simulation.kt index c236896752..81fd482f56 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/testing/Simulation.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/node/Simulation.kt @@ -1,4 +1,4 @@ -package com.r3corda.node.internal.testing +package com.r3corda.testing.node import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture @@ -11,7 +11,6 @@ import com.r3corda.core.then import com.r3corda.core.utilities.ProgressTracker import com.r3corda.node.services.clientapi.NodeInterestRates import com.r3corda.node.services.config.NodeConfiguration -import com.r3corda.node.services.network.InMemoryMessagingNetwork import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.transactions.SimpleNotaryService import com.r3corda.node.utilities.AddOrRemove @@ -42,7 +41,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, // This puts together a mock network of SimulatedNodes. - open class SimulatedNode(dir: Path, config: NodeConfiguration, mockNet: MockNetwork, networkMapAddress: NodeInfo?, + open class SimulatedNode(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, mockNet: MockNetwork, networkMapAddress: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?) : MockNetwork.MockNode(dir, config, mockNet, networkMapAddress, advertisedServices, id, keyPair) { override fun findMyLocation(): PhysicalLocation? = CityDatabase[configuration.nearestCity] } @@ -50,11 +49,11 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, inner class BankFactory : MockNetwork.Factory { var counter = 0 - override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { val letter = 'A' + counter val city = bankLocations[counter++ % bankLocations.size] - val cfg = object : NodeConfiguration { + val cfg = object : com.r3corda.node.services.config.NodeConfiguration { // TODO: Set this back to "Bank of $city" after video day. override val myLegalName: String = "Bank $letter" override val exportJMXto: String = "" @@ -72,10 +71,10 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, val bankFactory = BankFactory() object NetworkMapNodeFactory : MockNetwork.Factory { - override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, + override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { - require(advertisedServices.contains(NetworkMapService.Type)) - val cfg = object : NodeConfiguration { + require(advertisedServices.contains(com.r3corda.node.services.network.NetworkMapService.Type)) + val cfg = object : com.r3corda.node.services.config.NodeConfiguration { override val myLegalName: String = "Network coordination center" override val exportJMXto: String = "" override val nearestCity: String = "Amsterdam" @@ -88,10 +87,10 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, } object NotaryNodeFactory : MockNetwork.Factory { - override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { - require(advertisedServices.contains(SimpleNotaryService.Type)) - val cfg = object : NodeConfiguration { + require(advertisedServices.contains(com.r3corda.node.services.transactions.SimpleNotaryService.Type)) + val cfg = object : com.r3corda.node.services.config.NodeConfiguration { override val myLegalName: String = "Notary Service" override val exportJMXto: String = "" override val nearestCity: String = "Zurich" @@ -103,10 +102,10 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, } object RatesOracleFactory : MockNetwork.Factory { - override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { - require(advertisedServices.contains(NodeInterestRates.Type)) - val cfg = object : NodeConfiguration { + require(advertisedServices.contains(com.r3corda.node.services.clientapi.NodeInterestRates.Type)) + val cfg = object : com.r3corda.node.services.config.NodeConfiguration { override val myLegalName: String = "Rates Service Provider" override val exportJMXto: String = "" override val nearestCity: String = "Madrid" @@ -117,7 +116,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, return object : SimulatedNode(dir, cfg, network, networkMapAddr, advertisedServices, id, keyPair) { override fun start(): MockNetwork.MockNode { super.start() - findService().upload(javaClass.getResourceAsStream("example.rates.txt")) + findService().upload(javaClass.getResourceAsStream("example.rates.txt")) return this } } @@ -125,9 +124,9 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, } object RegulatorFactory : MockNetwork.Factory { - override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { - val cfg = object : NodeConfiguration { + val cfg = object : com.r3corda.node.services.config.NodeConfiguration { override val myLegalName: String = "Regulator A" override val exportJMXto: String = "" override val nearestCity: String = "Paris" @@ -147,12 +146,12 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, val network = MockNetwork(networkSendManuallyPumped, runAsync) // This one must come first. val networkMap: SimulatedNode - = network.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = NetworkMapService.Type) as SimulatedNode + = network.createNode(null, nodeFactory = NetworkMapNodeFactory, advertisedServices = com.r3corda.node.services.network.NetworkMapService.Type) as SimulatedNode val notary: SimulatedNode - = network.createNode(networkMap.info, nodeFactory = NotaryNodeFactory, advertisedServices = SimpleNotaryService.Type) as SimulatedNode + = network.createNode(networkMap.info, nodeFactory = NotaryNodeFactory, advertisedServices = com.r3corda.node.services.transactions.SimpleNotaryService.Type) as SimulatedNode val regulators: List = listOf(network.createNode(networkMap.info, start = false, nodeFactory = RegulatorFactory) as SimulatedNode) val ratesOracle: SimulatedNode - = network.createNode(networkMap.info, start = false, nodeFactory = RatesOracleFactory, advertisedServices = NodeInterestRates.Type) as SimulatedNode + = network.createNode(networkMap.info, start = false, nodeFactory = RatesOracleFactory, advertisedServices = com.r3corda.node.services.clientapi.NodeInterestRates.Type) as SimulatedNode // All nodes must be in one of these two lists for the purposes of the visualiser tool. val serviceProviders: List = listOf(notary, ratesOracle, networkMap) @@ -226,7 +225,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, protected fun showProgressFor(nodes: List) { nodes.forEach { node -> - node.smm.changes.filter { it.second == AddOrRemove.ADD }.first().subscribe { + node.smm.changes.filter { it.second == com.r3corda.node.utilities.AddOrRemove.ADD }.first().subscribe { linkProtocolProgress(node, it.first) } } @@ -245,7 +244,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, protected fun showConsensusFor(nodes: List) { val node = nodes.first() - node.smm.changes.filter { it.second == AddOrRemove.ADD }.first().subscribe { + node.smm.changes.filter { it.second == com.r3corda.node.utilities.AddOrRemove.ADD }.first().subscribe { linkConsensus(nodes, it.first) } } diff --git a/node/src/main/kotlin/com/r3corda/node/internal/testing/TestClock.kt b/test-utils/src/main/kotlin/com/r3corda/testing/node/TestClock.kt similarity index 95% rename from node/src/main/kotlin/com/r3corda/node/internal/testing/TestClock.kt rename to test-utils/src/main/kotlin/com/r3corda/testing/node/TestClock.kt index fdfa24ca60..8acc0cbb87 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/testing/TestClock.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/node/TestClock.kt @@ -1,4 +1,4 @@ -package com.r3corda.node.internal.testing +package com.r3corda.testing.node import com.r3corda.core.serialization.SerializeAsToken import com.r3corda.core.serialization.SerializeAsTokenContext @@ -15,7 +15,7 @@ import javax.annotation.concurrent.ThreadSafe * A [Clock] that can have the time advanced for use in testing. */ @ThreadSafe -class TestClock(private var delegateClock: Clock = Clock.systemUTC()) : MutableClock(), SerializeAsToken { +class TestClock(private var delegateClock: Clock = Clock.systemUTC()) : com.r3corda.node.utilities.MutableClock(), SerializeAsToken { private val token = SingletonSerializationToken(this) diff --git a/node/src/main/kotlin/com/r3corda/node/internal/testing/TradeSimulation.kt b/test-utils/src/main/kotlin/com/r3corda/testing/node/TradeSimulation.kt similarity index 80% rename from node/src/main/kotlin/com/r3corda/node/internal/testing/TradeSimulation.kt rename to test-utils/src/main/kotlin/com/r3corda/testing/node/TradeSimulation.kt index ba175ff811..0a9b3d69bf 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/testing/TradeSimulation.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/node/TradeSimulation.kt @@ -1,9 +1,8 @@ -package com.r3corda.node.internal.testing +package com.r3corda.testing.node import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture import com.r3corda.contracts.CommercialPaper -import com.r3corda.contracts.asset.DUMMY_CASH_ISSUER import com.r3corda.contracts.testing.fillWithSomeTestCash import com.r3corda.core.contracts.DOLLARS import com.r3corda.core.contracts.OwnableState @@ -12,8 +11,6 @@ import com.r3corda.core.contracts.`issued by` import com.r3corda.core.days import com.r3corda.core.random63BitValue import com.r3corda.core.seconds -import com.r3corda.node.services.network.InMemoryMessagingNetwork -import com.r3corda.protocols.TwoPartyTradeProtocol import java.time.Instant /** @@ -33,7 +30,7 @@ class TradeSimulation(runAsync: Boolean, latencyInjector: InMemoryMessagingNetwo buyer.services.fillWithSomeTestCash(1500.DOLLARS, notary.info.identity) val issuance = run { - val tx = CommercialPaper().generateIssue(seller.info.identity.ref(1, 2, 3), 1100.DOLLARS `issued by` DUMMY_CASH_ISSUER, + val tx = com.r3corda.contracts.CommercialPaper().generateIssue(seller.info.identity.ref(1, 2, 3), 1100.DOLLARS `issued by` com.r3corda.contracts.asset.DUMMY_CASH_ISSUER, Instant.now() + 10.days, notary.info.identity) tx.setTime(Instant.now(), 30.seconds) tx.signWith(notary.storage.myLegalIdentityKey) @@ -44,13 +41,13 @@ class TradeSimulation(runAsync: Boolean, latencyInjector: InMemoryMessagingNetwo val amount = 1000.DOLLARS val sessionID = random63BitValue() - val buyerProtocol = TwoPartyTradeProtocol.Buyer( + val buyerProtocol = com.r3corda.protocols.TwoPartyTradeProtocol.Buyer( seller.info.identity, notary.info.identity, amount, CommercialPaper.State::class.java, sessionID) - val sellerProtocol = TwoPartyTradeProtocol.Seller( + val sellerProtocol = com.r3corda.protocols.TwoPartyTradeProtocol.Seller( buyer.info.identity, notary.info, issuance.tx.outRef(0), @@ -61,8 +58,8 @@ class TradeSimulation(runAsync: Boolean, latencyInjector: InMemoryMessagingNetwo showConsensusFor(listOf(buyer, seller, notary)) showProgressFor(listOf(buyer, seller)) - val buyerFuture = buyer.services.startProtocol("bank.$buyerBankIndex.${TwoPartyTradeProtocol.TOPIC}.buyer", buyerProtocol) - val sellerFuture = seller.services.startProtocol("bank.$sellerBankIndex.${TwoPartyTradeProtocol.TOPIC}.seller", sellerProtocol) + val buyerFuture = buyer.services.startProtocol("bank.$buyerBankIndex.${com.r3corda.protocols.TwoPartyTradeProtocol.TOPIC}.buyer", buyerProtocol) + val sellerFuture = seller.services.startProtocol("bank.$sellerBankIndex.${com.r3corda.protocols.TwoPartyTradeProtocol.TOPIC}.seller", sellerProtocol) return Futures.successfulAsList(buyerFuture, sellerFuture) } From 868b23a9233ff4c25a22b254a834d99287c71d4e Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Wed, 31 Aug 2016 15:20:44 +0100 Subject: [PATCH 2/2] Move simulations to top level --- contracts/build.gradle | 6 ++++-- experimental/build.gradle | 8 ++++++++ .../com/r3corda/simulation}/IRSSimulation.kt | 4 +++- .../kotlin/com/r3corda/simulation}/Simulation.kt | 10 +++++++--- .../com/r3corda/simulation}/TradeSimulation.kt | 15 +++++++++------ .../com/r3corda/simulation}/example.rates.txt | 0 .../resources/com/r3corda/simulation}/trade.json | 0 .../com/r3corda/core/testing/IRSSimulationTest.kt | 2 +- .../kotlin/com/r3corda/testing/node/MockNode.kt | 9 +++++---- 9 files changed, 37 insertions(+), 17 deletions(-) rename {test-utils/src/main/kotlin/com/r3corda/testing/node => src/main/kotlin/com/r3corda/simulation}/IRSSimulation.kt (97%) rename {test-utils/src/main/kotlin/com/r3corda/testing/node => src/main/kotlin/com/r3corda/simulation}/Simulation.kt (97%) rename {test-utils/src/main/kotlin/com/r3corda/testing/node => src/main/kotlin/com/r3corda/simulation}/TradeSimulation.kt (81%) rename {node/src/main/resources/com/r3corda/node/internal/testing => src/main/resources/com/r3corda/simulation}/example.rates.txt (100%) rename {node/src/main/resources/com/r3corda/node/internal/testing => src/main/resources/com/r3corda/simulation}/trade.json (100%) diff --git a/contracts/build.gradle b/contracts/build.gradle index 7faee58d2d..9b506ea682 100644 --- a/contracts/build.gradle +++ b/contracts/build.gradle @@ -2,13 +2,15 @@ apply plugin: 'kotlin' apply plugin: CanonicalizerPlugin repositories { - mavenCentral() mavenLocal() mavenCentral() - jcenter() maven { url 'http://oss.sonatype.org/content/repositories/snapshots' } + jcenter() + maven { + url 'https://dl.bintray.com/kotlin/exposed' + } } dependencies { diff --git a/experimental/build.gradle b/experimental/build.gradle index d8ca4c18d7..fa5287a577 100644 --- a/experimental/build.gradle +++ b/experimental/build.gradle @@ -6,7 +6,15 @@ apply plugin: 'kotlin' sourceCompatibility = 1.5 repositories { + mavenLocal() mavenCentral() + maven { + url 'http://oss.sonatype.org/content/repositories/snapshots' + } + jcenter() + maven { + url 'https://dl.bintray.com/kotlin/exposed' + } } compileKotlin { diff --git a/test-utils/src/main/kotlin/com/r3corda/testing/node/IRSSimulation.kt b/src/main/kotlin/com/r3corda/simulation/IRSSimulation.kt similarity index 97% rename from test-utils/src/main/kotlin/com/r3corda/testing/node/IRSSimulation.kt rename to src/main/kotlin/com/r3corda/simulation/IRSSimulation.kt index a1d71a3263..fa3252b79c 100644 --- a/test-utils/src/main/kotlin/com/r3corda/testing/node/IRSSimulation.kt +++ b/src/main/kotlin/com/r3corda/simulation/IRSSimulation.kt @@ -1,4 +1,4 @@ -package com.r3corda.testing.node +package com.r3corda.simulation import com.fasterxml.jackson.module.kotlin.readValue import com.google.common.util.concurrent.FutureCallback @@ -15,6 +15,8 @@ import com.r3corda.core.node.services.linearHeadsOfType import com.r3corda.core.random63BitValue import com.r3corda.core.success import com.r3corda.protocols.TwoPartyDealProtocol +import com.r3corda.testing.node.InMemoryMessagingNetwork +import com.r3corda.testing.node.MockIdentityService import java.security.KeyPair import java.time.LocalDate import java.util.* diff --git a/test-utils/src/main/kotlin/com/r3corda/testing/node/Simulation.kt b/src/main/kotlin/com/r3corda/simulation/Simulation.kt similarity index 97% rename from test-utils/src/main/kotlin/com/r3corda/testing/node/Simulation.kt rename to src/main/kotlin/com/r3corda/simulation/Simulation.kt index 81fd482f56..4fc070e98a 100644 --- a/test-utils/src/main/kotlin/com/r3corda/testing/node/Simulation.kt +++ b/src/main/kotlin/com/r3corda/simulation/Simulation.kt @@ -1,4 +1,4 @@ -package com.r3corda.testing.node +package com.r3corda.simulation import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture @@ -14,6 +14,10 @@ import com.r3corda.node.services.config.NodeConfiguration import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.transactions.SimpleNotaryService import com.r3corda.node.utilities.AddOrRemove +import com.r3corda.testing.node.InMemoryMessagingNetwork +import com.r3corda.testing.node.MockNetwork +import com.r3corda.testing.node.TestClock +import com.r3corda.testing.node.setTo import rx.Observable import rx.subjects.PublishSubject import java.nio.file.Path @@ -41,7 +45,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, // This puts together a mock network of SimulatedNodes. - open class SimulatedNode(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, mockNet: MockNetwork, networkMapAddress: NodeInfo?, + open class SimulatedNode(dir: Path, config: NodeConfiguration, mockNet: MockNetwork, networkMapAddress: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?) : MockNetwork.MockNode(dir, config, mockNet, networkMapAddress, advertisedServices, id, keyPair) { override fun findMyLocation(): PhysicalLocation? = CityDatabase[configuration.nearestCity] } @@ -49,7 +53,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, inner class BankFactory : MockNetwork.Factory { var counter = 0 - override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { val letter = 'A' + counter val city = bankLocations[counter++ % bankLocations.size] diff --git a/test-utils/src/main/kotlin/com/r3corda/testing/node/TradeSimulation.kt b/src/main/kotlin/com/r3corda/simulation/TradeSimulation.kt similarity index 81% rename from test-utils/src/main/kotlin/com/r3corda/testing/node/TradeSimulation.kt rename to src/main/kotlin/com/r3corda/simulation/TradeSimulation.kt index 0a9b3d69bf..8624747ba5 100644 --- a/test-utils/src/main/kotlin/com/r3corda/testing/node/TradeSimulation.kt +++ b/src/main/kotlin/com/r3corda/simulation/TradeSimulation.kt @@ -1,8 +1,9 @@ -package com.r3corda.testing.node +package com.r3corda.simulation import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture import com.r3corda.contracts.CommercialPaper +import com.r3corda.contracts.asset.DUMMY_CASH_ISSUER import com.r3corda.contracts.testing.fillWithSomeTestCash import com.r3corda.core.contracts.DOLLARS import com.r3corda.core.contracts.OwnableState @@ -11,6 +12,8 @@ import com.r3corda.core.contracts.`issued by` import com.r3corda.core.days import com.r3corda.core.random63BitValue import com.r3corda.core.seconds +import com.r3corda.protocols.TwoPartyTradeProtocol +import com.r3corda.testing.node.InMemoryMessagingNetwork import java.time.Instant /** @@ -30,7 +33,7 @@ class TradeSimulation(runAsync: Boolean, latencyInjector: InMemoryMessagingNetwo buyer.services.fillWithSomeTestCash(1500.DOLLARS, notary.info.identity) val issuance = run { - val tx = com.r3corda.contracts.CommercialPaper().generateIssue(seller.info.identity.ref(1, 2, 3), 1100.DOLLARS `issued by` com.r3corda.contracts.asset.DUMMY_CASH_ISSUER, + val tx = CommercialPaper().generateIssue(seller.info.identity.ref(1, 2, 3), 1100.DOLLARS `issued by` DUMMY_CASH_ISSUER, Instant.now() + 10.days, notary.info.identity) tx.setTime(Instant.now(), 30.seconds) tx.signWith(notary.storage.myLegalIdentityKey) @@ -41,13 +44,13 @@ class TradeSimulation(runAsync: Boolean, latencyInjector: InMemoryMessagingNetwo val amount = 1000.DOLLARS val sessionID = random63BitValue() - val buyerProtocol = com.r3corda.protocols.TwoPartyTradeProtocol.Buyer( + val buyerProtocol = TwoPartyTradeProtocol.Buyer( seller.info.identity, notary.info.identity, amount, CommercialPaper.State::class.java, sessionID) - val sellerProtocol = com.r3corda.protocols.TwoPartyTradeProtocol.Seller( + val sellerProtocol = TwoPartyTradeProtocol.Seller( buyer.info.identity, notary.info, issuance.tx.outRef(0), @@ -58,8 +61,8 @@ class TradeSimulation(runAsync: Boolean, latencyInjector: InMemoryMessagingNetwo showConsensusFor(listOf(buyer, seller, notary)) showProgressFor(listOf(buyer, seller)) - val buyerFuture = buyer.services.startProtocol("bank.$buyerBankIndex.${com.r3corda.protocols.TwoPartyTradeProtocol.TOPIC}.buyer", buyerProtocol) - val sellerFuture = seller.services.startProtocol("bank.$sellerBankIndex.${com.r3corda.protocols.TwoPartyTradeProtocol.TOPIC}.seller", sellerProtocol) + val buyerFuture = buyer.services.startProtocol("bank.$buyerBankIndex.${TwoPartyTradeProtocol.TOPIC}.buyer", buyerProtocol) + val sellerFuture = seller.services.startProtocol("bank.$sellerBankIndex.${TwoPartyTradeProtocol.TOPIC}.seller", sellerProtocol) return Futures.successfulAsList(buyerFuture, sellerFuture) } diff --git a/node/src/main/resources/com/r3corda/node/internal/testing/example.rates.txt b/src/main/resources/com/r3corda/simulation/example.rates.txt similarity index 100% rename from node/src/main/resources/com/r3corda/node/internal/testing/example.rates.txt rename to src/main/resources/com/r3corda/simulation/example.rates.txt diff --git a/node/src/main/resources/com/r3corda/node/internal/testing/trade.json b/src/main/resources/com/r3corda/simulation/trade.json similarity index 100% rename from node/src/main/resources/com/r3corda/node/internal/testing/trade.json rename to src/main/resources/com/r3corda/simulation/trade.json diff --git a/src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt b/src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt index 1889536cad..928f454aa9 100644 --- a/src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt +++ b/src/test/kotlin/com/r3corda/core/testing/IRSSimulationTest.kt @@ -2,7 +2,7 @@ package com.r3corda.core.testing import com.google.common.base.Throwables import com.r3corda.core.utilities.LogHelper -import com.r3corda.testing.node.IRSSimulation +import com.r3corda.simulation.IRSSimulation import org.junit.Test class IRSSimulationTest { diff --git a/test-utils/src/main/kotlin/com/r3corda/testing/node/MockNode.kt b/test-utils/src/main/kotlin/com/r3corda/testing/node/MockNode.kt index 342395ceb8..1819622050 100644 --- a/test-utils/src/main/kotlin/com/r3corda/testing/node/MockNode.kt +++ b/test-utils/src/main/kotlin/com/r3corda/testing/node/MockNode.kt @@ -11,6 +11,7 @@ import com.r3corda.core.node.services.WalletService import com.r3corda.core.testing.InMemoryWalletService import com.r3corda.core.utilities.DUMMY_NOTARY_KEY import com.r3corda.core.utilities.loggerFor +import com.r3corda.node.services.config.NodeConfiguration import org.slf4j.Logger import java.nio.file.Files import java.nio.file.Path @@ -48,18 +49,18 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, /** Allows customisation of how nodes are created. */ interface Factory { - fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNode } object DefaultFactory : Factory { - override fun create(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, + override fun create(dir: Path, config: NodeConfiguration, network: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNode { return MockNode(dir, config, network, networkMapAddr, advertisedServices, id, keyPair) } } - open class MockNode(dir: Path, config: com.r3corda.node.services.config.NodeConfiguration, val mockNet: MockNetwork, networkMapAddr: NodeInfo?, + open class MockNode(dir: Path, config: NodeConfiguration, val mockNet: MockNetwork, networkMapAddr: NodeInfo?, advertisedServices: Set, val id: Int, val keyPair: KeyPair?) : com.r3corda.node.internal.AbstractNode(dir, config, networkMapAddr, advertisedServices, TestClock()) { override val log: Logger = loggerFor() override val serverThread: com.r3corda.node.utilities.AffinityExecutor = @@ -113,7 +114,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, val path = filesystem.getPath("/nodes/$id") if (newNode) Files.createDirectories(path.resolve("attachments")) - val config = object : com.r3corda.node.services.config.NodeConfiguration { + val config = object : NodeConfiguration { override val myLegalName: String = legalName ?: "Mock Company $id" override val exportJMXto: String = "" override val nearestCity: String = "Atlantis"