mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
Refactoring related to obsolete attachments directory (#1150)
* No longer create obsolete "attachments" directory * Remove redundant NodeAttachmentService param * Add type param to MockNetwork.Factory to eliminate casts * Use null not -1 for unforced node ID * Remove redundant createNode args
This commit is contained in:
@ -413,7 +413,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
||||
private fun makeServices(): MutableList<Any> {
|
||||
checkpointStorage = DBCheckpointStorage()
|
||||
_services = ServiceHubInternalImpl()
|
||||
attachments = createAttachmentStorage()
|
||||
attachments = NodeAttachmentService(configuration.dataSourceProperties, services.monitoringService.metrics, configuration.database)
|
||||
network = makeMessagingService()
|
||||
info = makeInfo()
|
||||
|
||||
@ -762,11 +762,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
||||
|
||||
protected open fun generateKeyPair() = cryptoGenerateKeyPair()
|
||||
|
||||
private fun createAttachmentStorage(): NodeAttachmentService {
|
||||
val attachmentsDir = (configuration.baseDirectory / "attachments").createDirectories()
|
||||
return NodeAttachmentService(attachmentsDir, configuration.dataSourceProperties, services.monitoringService.metrics, configuration.database)
|
||||
}
|
||||
|
||||
private inner class ServiceHubInternalImpl : ServiceHubInternal, SingletonSerializeAsToken() {
|
||||
override val rpcFlows = ArrayList<Class<out FlowLogic<*>>>()
|
||||
override val uploaders = ArrayList<FileUploader>()
|
||||
|
@ -9,7 +9,6 @@ import com.google.common.io.CountingInputStream
|
||||
import net.corda.core.contracts.AbstractAttachment
|
||||
import net.corda.core.contracts.Attachment
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.internal.isDirectory
|
||||
import net.corda.core.node.services.AttachmentStorage
|
||||
import net.corda.core.serialization.*
|
||||
import net.corda.core.utilities.loggerFor
|
||||
@ -22,7 +21,6 @@ import java.io.FilterInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.nio.file.FileAlreadyExistsException
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import java.util.jar.JarInputStream
|
||||
@ -32,7 +30,7 @@ import javax.annotation.concurrent.ThreadSafe
|
||||
* Stores attachments in H2 database.
|
||||
*/
|
||||
@ThreadSafe
|
||||
class NodeAttachmentService(val storePath: Path, dataSourceProperties: Properties, metrics: MetricRegistry, databaseProperties: Properties?)
|
||||
class NodeAttachmentService(dataSourceProperties: Properties, metrics: MetricRegistry, databaseProperties: Properties?)
|
||||
: AttachmentStorage, AcceptsFileUpload, SingletonSerializeAsToken() {
|
||||
companion object {
|
||||
private val log = loggerFor<NodeAttachmentService>()
|
||||
@ -47,8 +45,6 @@ class NodeAttachmentService(val storePath: Path, dataSourceProperties: Propertie
|
||||
private val attachmentCount = metrics.counter("Attachments")
|
||||
|
||||
init {
|
||||
require(storePath.isDirectory()) { "$storePath must be a directory" }
|
||||
|
||||
session.withTransaction {
|
||||
attachmentCount.inc(session.count(AttachmentEntity::class).get().value().toLong())
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ class AttachmentTests {
|
||||
@Test
|
||||
fun `malicious response`() {
|
||||
// Make a node that doesn't do sanity checking at load time.
|
||||
val n0 = mockNet.createNode(null, -1, object : MockNetwork.Factory {
|
||||
val n0 = mockNet.createNode(nodeFactory = object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int,
|
||||
overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
@ -115,7 +115,7 @@ class AttachmentTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
}, true, null, null, ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type))
|
||||
}, advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
|
||||
val n1 = mockNet.createNode(n0.network.myAddress)
|
||||
|
||||
val attachment = fakeAttachment()
|
||||
|
@ -249,7 +249,7 @@ class TwoPartyTradeFlowTests {
|
||||
|
||||
// ... bring the node back up ... the act of constructing the SMM will re-register the message handlers
|
||||
// that Bob was waiting on before the reboot occurred.
|
||||
bobNode = mockNet.createNode(networkMapAddress, bobAddr.id, object : MockNetwork.Factory {
|
||||
bobNode = mockNet.createNode(networkMapAddress, bobAddr.id, object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?,
|
||||
advertisedServices: Set<ServiceInfo>, id: Int, overrideServices: Map<ServiceInfo, KeyPair>?,
|
||||
entropyRoot: BigInteger): MockNetwork.MockNode {
|
||||
@ -290,10 +290,9 @@ class TwoPartyTradeFlowTests {
|
||||
// of gets and puts.
|
||||
private fun makeNodeWithTracking(
|
||||
networkMapAddress: SingleMessageRecipient?,
|
||||
name: X500Name,
|
||||
overridenServices: Map<ServiceInfo, KeyPair>? = null): MockNetwork.MockNode {
|
||||
name: X500Name): MockNetwork.MockNode {
|
||||
// Create a node in the mock network ...
|
||||
return mockNet.createNode(networkMapAddress, -1, object : MockNetwork.Factory {
|
||||
return mockNet.createNode(networkMapAddress, nodeFactory = object : MockNetwork.Factory<MockNetwork.MockNode> {
|
||||
override fun create(config: NodeConfiguration,
|
||||
network: MockNetwork,
|
||||
networkMapAddr: SingleMessageRecipient?,
|
||||
@ -307,7 +306,7 @@ class TwoPartyTradeFlowTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
}, true, name, overridenServices)
|
||||
}, legalName = name)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.corda.node.services.network
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import net.corda.core.crypto.random63BitValue
|
||||
import net.corda.core.getOrThrow
|
||||
import net.corda.core.messaging.SingleMessageRecipient
|
||||
import net.corda.core.node.NodeInfo
|
||||
@ -53,8 +52,11 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
@Before
|
||||
fun setup() {
|
||||
mockNet = MockNetwork(defaultFactory = nodeFactory)
|
||||
mapServiceNode = mockNet.createNode(null, -1, nodeFactory, true, DUMMY_MAP.name, null, BigInteger.valueOf(random63BitValue()), ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type))
|
||||
alice = mockNet.createNode(mapServiceNode.network.myAddress, -1, nodeFactory, true, ALICE.name)
|
||||
mapServiceNode = mockNet.createNode(
|
||||
nodeFactory = nodeFactory,
|
||||
legalName = DUMMY_MAP.name,
|
||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
|
||||
alice = mockNet.createNode(mapServiceNode.network.myAddress, nodeFactory = nodeFactory, legalName = ALICE.name)
|
||||
mockNet.runNetwork()
|
||||
lastSerial = System.currentTimeMillis()
|
||||
}
|
||||
@ -64,7 +66,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
mockNet.stopNodes()
|
||||
}
|
||||
|
||||
protected abstract val nodeFactory: MockNetwork.Factory
|
||||
protected abstract val nodeFactory: MockNetwork.Factory<*>
|
||||
|
||||
protected abstract val networkMapService: S
|
||||
|
||||
@ -249,7 +251,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
}
|
||||
|
||||
private fun addNewNodeToNetworkMap(legalName: X500Name): MockNode {
|
||||
val node = mockNet.createNode(networkMapAddress = mapServiceNode.network.myAddress, legalName = legalName)
|
||||
val node = mockNet.createNode(mapServiceNode.network.myAddress, legalName = legalName)
|
||||
mockNet.runNetwork()
|
||||
lastSerial = System.currentTimeMillis()
|
||||
return node
|
||||
@ -269,7 +271,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
}
|
||||
}
|
||||
|
||||
private object NoNMSNodeFactory : MockNetwork.Factory {
|
||||
private object NoNMSNodeFactory : MockNetwork.Factory<MockNode> {
|
||||
override fun create(config: NodeConfiguration,
|
||||
network: MockNetwork,
|
||||
networkMapAddr: SingleMessageRecipient?,
|
||||
|
@ -38,8 +38,8 @@ class InMemoryNetworkMapCacheTest {
|
||||
@Test
|
||||
fun `key collision`() {
|
||||
val entropy = BigInteger.valueOf(24012017L)
|
||||
val nodeA = mockNet.createNode(null, -1, MockNetwork.DefaultFactory, true, ALICE.name, null, entropy, ServiceInfo(NetworkMapService.type))
|
||||
val nodeB = mockNet.createNode(null, -1, MockNetwork.DefaultFactory, true, BOB.name, null, entropy, ServiceInfo(NetworkMapService.type))
|
||||
val nodeA = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = ALICE.name, entropyRoot = entropy, advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||
val nodeB = mockNet.createNode(nodeFactory = MockNetwork.DefaultFactory, legalName = BOB.name, entropyRoot = entropy, advertisedServices = ServiceInfo(NetworkMapService.type))
|
||||
assertEquals(nodeA.info.legalIdentity, nodeB.info.legalIdentity)
|
||||
|
||||
mockNet.runNetwork()
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.corda.node.services.network
|
||||
|
||||
import net.corda.node.services.network.InMemoryNetworkMapService
|
||||
import net.corda.testing.node.MockNetwork
|
||||
|
||||
class InMemoryNetworkMapServiceTest : AbstractNetworkMapServiceTest<InMemoryNetworkMapService>() {
|
||||
override val nodeFactory: MockNetwork.Factory get() = MockNetwork.DefaultFactory
|
||||
override val nodeFactory get() = MockNetwork.DefaultFactory
|
||||
override val networkMapService: InMemoryNetworkMapService get() = mapServiceNode.inNodeNetworkMapService as InMemoryNetworkMapService
|
||||
override fun swizzle() = Unit
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import java.security.KeyPair
|
||||
*/
|
||||
class PersistentNetworkMapServiceTest : AbstractNetworkMapServiceTest<PersistentNetworkMapService>() {
|
||||
|
||||
override val nodeFactory: MockNetwork.Factory get() = NodeFactory
|
||||
override val nodeFactory: MockNetwork.Factory<*> get() = NodeFactory
|
||||
|
||||
override val networkMapService: PersistentNetworkMapService
|
||||
get() = (mapServiceNode.inNodeNetworkMapService as SwizzleNetworkMapService).delegate
|
||||
@ -26,7 +26,7 @@ class PersistentNetworkMapServiceTest : AbstractNetworkMapServiceTest<Persistent
|
||||
}
|
||||
}
|
||||
|
||||
private object NodeFactory : MockNetwork.Factory {
|
||||
private object NodeFactory : MockNetwork.Factory<MockNode> {
|
||||
override fun create(config: NodeConfiguration,
|
||||
network: MockNetwork,
|
||||
networkMapAddr: SingleMessageRecipient?,
|
||||
|
@ -60,7 +60,7 @@ class NodeAttachmentStorageTest {
|
||||
val expectedHash = testJar.readAll().sha256()
|
||||
|
||||
database.transaction {
|
||||
val storage = NodeAttachmentService(fs.getPath("/"), dataSourceProperties, MetricRegistry(), makeTestDatabaseProperties())
|
||||
val storage = NodeAttachmentService(dataSourceProperties, MetricRegistry(), makeTestDatabaseProperties())
|
||||
val id = testJar.read { storage.importAttachment(it) }
|
||||
assertEquals(expectedHash, id)
|
||||
|
||||
@ -86,7 +86,7 @@ class NodeAttachmentStorageTest {
|
||||
fun `duplicates not allowed`() {
|
||||
val testJar = makeTestJar()
|
||||
database.transaction {
|
||||
val storage = NodeAttachmentService(fs.getPath("/"), dataSourceProperties, MetricRegistry(), makeTestDatabaseProperties())
|
||||
val storage = NodeAttachmentService(dataSourceProperties, MetricRegistry(), makeTestDatabaseProperties())
|
||||
testJar.read {
|
||||
storage.importAttachment(it)
|
||||
}
|
||||
@ -102,7 +102,7 @@ class NodeAttachmentStorageTest {
|
||||
fun `corrupt entry throws exception`() {
|
||||
val testJar = makeTestJar()
|
||||
database.transaction {
|
||||
val storage = NodeAttachmentService(fs.getPath("/"), dataSourceProperties, MetricRegistry(), makeTestDatabaseProperties())
|
||||
val storage = NodeAttachmentService(dataSourceProperties, MetricRegistry(), makeTestDatabaseProperties())
|
||||
val id = testJar.read { storage.importAttachment(it) }
|
||||
|
||||
// Corrupt the file in the store.
|
||||
@ -130,7 +130,7 @@ class NodeAttachmentStorageTest {
|
||||
@Test
|
||||
fun `non jar rejected`() {
|
||||
database.transaction {
|
||||
val storage = NodeAttachmentService(fs.getPath("/"), dataSourceProperties, MetricRegistry(), makeTestDatabaseProperties())
|
||||
val storage = NodeAttachmentService(dataSourceProperties, MetricRegistry(), makeTestDatabaseProperties())
|
||||
val path = fs.getPath("notajar")
|
||||
path.writeLines(listOf("Hey", "there!"))
|
||||
path.read {
|
||||
|
@ -170,7 +170,7 @@ class FlowFrameworkTests {
|
||||
node3.disableDBCloseOnStop()
|
||||
node3.stop()
|
||||
|
||||
node3 = mockNet.createNode(node1.network.myAddress, forcedID = node3.id)
|
||||
node3 = mockNet.createNode(node1.network.myAddress, node3.id)
|
||||
val restoredFlow = node3.getSingleFlow<NoOpFlow>().first
|
||||
assertEquals(false, restoredFlow.flowStarted) // Not started yet as no network activity has been allowed yet
|
||||
mockNet.runNetwork() // Allow network map messages to flow
|
||||
@ -180,7 +180,7 @@ class FlowFrameworkTests {
|
||||
node3.stop()
|
||||
|
||||
// Now it is completed the flow should leave no Checkpoint.
|
||||
node3 = mockNet.createNode(node1.network.myAddress, forcedID = node3.id)
|
||||
node3 = mockNet.createNode(node1.network.myAddress, node3.id)
|
||||
mockNet.runNetwork() // Allow network map messages to flow
|
||||
node3.smm.executor.flush()
|
||||
assertTrue(node3.smm.findStateMachines(NoOpFlow::class.java).isEmpty())
|
||||
|
@ -37,7 +37,7 @@ class NotaryServiceTests {
|
||||
notaryNode = mockNet.createNode(
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(SimpleNotaryService.type)))
|
||||
clientNode = mockNet.createNode(networkMapAddress = notaryNode.network.myAddress)
|
||||
clientNode = mockNet.createNode(notaryNode.network.myAddress)
|
||||
mockNet.runNetwork() // Clear network map registration messages
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ class ValidatingNotaryServiceTests {
|
||||
legalName = DUMMY_NOTARY.name,
|
||||
advertisedServices = *arrayOf(ServiceInfo(NetworkMapService.type), ServiceInfo(ValidatingNotaryService.type))
|
||||
)
|
||||
clientNode = mockNet.createNode(networkMapAddress = notaryNode.network.myAddress)
|
||||
clientNode = mockNet.createNode(notaryNode.network.myAddress)
|
||||
mockNet.runNetwork() // Clear network map registration messages
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user