From 5aaa6bd2044b1b3cb04bd64ac47ee0ea7d486c81 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 8 Mar 2016 15:49:16 +0100 Subject: [PATCH] Minor: rename NodeAttachmentStorage -> NodeAttachmentService --- src/main/kotlin/core/node/AbstractNode.kt | 8 ++++---- src/main/kotlin/core/node/TraderDemo.kt | 4 ++-- ...deAttachmentStorage.kt => NodeAttachmentService.kt} | 4 ++-- src/test/kotlin/core/messaging/AttachmentTests.kt | 4 ++-- .../core/messaging/TwoPartyTradeProtocolTests.kt | 4 ++-- src/test/kotlin/core/node/NodeAttachmentStorageTest.kt | 10 +++++----- 6 files changed, 17 insertions(+), 17 deletions(-) rename src/main/kotlin/core/node/services/{NodeAttachmentStorage.kt => NodeAttachmentService.kt} (98%) diff --git a/src/main/kotlin/core/node/AbstractNode.kt b/src/main/kotlin/core/node/AbstractNode.kt index cba8cf19f3..0e02c858e7 100644 --- a/src/main/kotlin/core/node/AbstractNode.kt +++ b/src/main/kotlin/core/node/AbstractNode.kt @@ -134,10 +134,10 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, return constructStorageService(attachments, identity, keypair) } - protected open fun constructStorageService(attachments: NodeAttachmentStorage, identity: Party, keypair: KeyPair) = + protected open fun constructStorageService(attachments: NodeAttachmentService, identity: Party, keypair: KeyPair) = StorageServiceImpl(attachments, identity, keypair) - open inner class StorageServiceImpl(attachments: NodeAttachmentStorage, identity: Party, keypair: KeyPair) : StorageService { + open inner class StorageServiceImpl(attachments: NodeAttachmentService, identity: Party, keypair: KeyPair) : StorageService { protected val tables = HashMap>() @Suppress("UNCHECKED_CAST") @@ -189,13 +189,13 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, } } - private fun makeAttachmentStorage(dir: Path): NodeAttachmentStorage { + private fun makeAttachmentStorage(dir: Path): NodeAttachmentService { val attachmentsDir = dir.resolve("attachments") try { Files.createDirectory(attachmentsDir) } catch (e: FileAlreadyExistsException) { } - val attachments = NodeAttachmentStorage(attachmentsDir) + val attachments = NodeAttachmentService(attachmentsDir) return attachments } } \ No newline at end of file diff --git a/src/main/kotlin/core/node/TraderDemo.kt b/src/main/kotlin/core/node/TraderDemo.kt index bdede36081..bb4c6bb71e 100644 --- a/src/main/kotlin/core/node/TraderDemo.kt +++ b/src/main/kotlin/core/node/TraderDemo.kt @@ -19,7 +19,7 @@ import core.crypto.generateKeyPair import core.messaging.LegallyIdentifiableNode import core.messaging.SingleMessageRecipient import core.node.services.ArtemisMessagingService -import core.node.services.NodeAttachmentStorage +import core.node.services.NodeAttachmentService import core.node.services.NodeWalletService import protocols.TimestampingProtocol import core.protocols.ProtocolLogic @@ -101,7 +101,7 @@ fun main(args: Array) { if (listening) { // For demo purposes just extract attachment jars when saved to disk, so the user can explore them. // Buyer will fetch the attachment from the seller. - val attachmentsPath = (node.storage.attachments as NodeAttachmentStorage).let { + val attachmentsPath = (node.storage.attachments as NodeAttachmentService).let { it.automaticallyExtractAttachments = true it.storePath } diff --git a/src/main/kotlin/core/node/services/NodeAttachmentStorage.kt b/src/main/kotlin/core/node/services/NodeAttachmentService.kt similarity index 98% rename from src/main/kotlin/core/node/services/NodeAttachmentStorage.kt rename to src/main/kotlin/core/node/services/NodeAttachmentService.kt index ccb4ad5f8e..8e973ec7bb 100644 --- a/src/main/kotlin/core/node/services/NodeAttachmentStorage.kt +++ b/src/main/kotlin/core/node/services/NodeAttachmentService.kt @@ -30,8 +30,8 @@ import javax.annotation.concurrent.ThreadSafe * Stores attachments in the specified local directory, which must exist. Doesn't allow new attachments to be uploaded. */ @ThreadSafe -class NodeAttachmentStorage(val storePath: Path) : AttachmentStorage { - private val log = loggerFor() +class NodeAttachmentService(val storePath: Path) : AttachmentStorage { + private val log = loggerFor() @VisibleForTesting var checkAttachmentsOnLoad = true diff --git a/src/test/kotlin/core/messaging/AttachmentTests.kt b/src/test/kotlin/core/messaging/AttachmentTests.kt index 6f24cf4441..60be7c0730 100644 --- a/src/test/kotlin/core/messaging/AttachmentTests.kt +++ b/src/test/kotlin/core/messaging/AttachmentTests.kt @@ -14,7 +14,7 @@ import core.Attachment import core.crypto.SecureHash import core.crypto.sha256 import core.node.MockNetwork -import core.node.services.NodeAttachmentStorage +import core.node.services.NodeAttachmentService import core.serialization.OpaqueBytes import core.testutils.rootCauseExceptions import core.utilities.BriefLogFormatter @@ -94,7 +94,7 @@ class AttachmentTests { object : MockNetwork.MockNode(path, config, mock, ts) { override fun start(): MockNetwork.MockNode { super.start() - (storage.attachments as NodeAttachmentStorage).checkAttachmentsOnLoad = false + (storage.attachments as NodeAttachmentService).checkAttachmentsOnLoad = false return this } } diff --git a/src/test/kotlin/core/messaging/TwoPartyTradeProtocolTests.kt b/src/test/kotlin/core/messaging/TwoPartyTradeProtocolTests.kt index e9ee89ec7a..6ce6107398 100644 --- a/src/test/kotlin/core/messaging/TwoPartyTradeProtocolTests.kt +++ b/src/test/kotlin/core/messaging/TwoPartyTradeProtocolTests.kt @@ -10,7 +10,6 @@ package core.messaging import contracts.Cash import contracts.CommercialPaper -import protocols.TwoPartyTradeProtocol import core.* import core.crypto.SecureHash import core.node.MockNetwork @@ -21,6 +20,7 @@ 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 import java.nio.file.Path @@ -195,7 +195,7 @@ class TwoPartyTradeProtocolTests : TestWithInMemoryNetwork() { return net.createNode(null) { path, config, net, tsNode -> object : MockNetwork.MockNode(path, config, net, tsNode) { // That constructs the storage service object in a customised way ... - override fun constructStorageService(attachments: NodeAttachmentStorage, identity: Party, keypair: KeyPair): StorageServiceImpl { + override fun constructStorageService(attachments: NodeAttachmentService, identity: Party, keypair: KeyPair): StorageServiceImpl { // By tweaking the standard StorageServiceImpl class ... return object : StorageServiceImpl(attachments, identity, keypair) { // To use RecordingMaps instead of ordinary HashMaps. diff --git a/src/test/kotlin/core/node/NodeAttachmentStorageTest.kt b/src/test/kotlin/core/node/NodeAttachmentStorageTest.kt index 0533de45d1..16dc8ef4c8 100644 --- a/src/test/kotlin/core/node/NodeAttachmentStorageTest.kt +++ b/src/test/kotlin/core/node/NodeAttachmentStorageTest.kt @@ -11,7 +11,7 @@ package core.node import com.google.common.jimfs.Configuration import com.google.common.jimfs.Jimfs import core.crypto.SecureHash -import core.node.services.NodeAttachmentStorage +import core.node.services.NodeAttachmentService import core.use import org.junit.Before import org.junit.Test @@ -40,7 +40,7 @@ class NodeAttachmentStorageTest { val testJar = makeTestJar() val expectedHash = SecureHash.sha256(Files.readAllBytes(testJar)) - val storage = NodeAttachmentStorage(fs.getPath("/")) + val storage = NodeAttachmentService(fs.getPath("/")) val id = testJar.use { storage.importAttachment(it) } assertEquals(expectedHash, id) @@ -57,7 +57,7 @@ class NodeAttachmentStorageTest { @Test fun `duplicates not allowed`() { val testJar = makeTestJar() - val storage = NodeAttachmentStorage(fs.getPath("/")) + val storage = NodeAttachmentService(fs.getPath("/")) testJar.use { storage.importAttachment(it) } assertFailsWith { testJar.use { storage.importAttachment(it) } @@ -67,13 +67,13 @@ class NodeAttachmentStorageTest { @Test fun `corrupt entry throws exception`() { val testJar = makeTestJar() - val storage = NodeAttachmentStorage(fs.getPath("/")) + val storage = NodeAttachmentService(fs.getPath("/")) val id = testJar.use { storage.importAttachment(it) } // Corrupt the file in the store. Files.write(fs.getPath("/", id.toString()), "arggghhhh".toByteArray(), StandardOpenOption.WRITE) - val e = assertFailsWith { + val e = assertFailsWith { storage.openAttachment(id)!!.open().use { it.readBytes() } } assertEquals(e.file, storage.storePath.resolve(id.toString()))