mirror of
https://github.com/corda/corda.git
synced 2025-03-23 12:35:23 +00:00
Minor: rename NodeAttachmentStorage -> NodeAttachmentService
This commit is contained in:
parent
ffcc0507c4
commit
5aaa6bd204
@ -134,10 +134,10 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
|||||||
return constructStorageService(attachments, identity, keypair)
|
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)
|
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<String, MutableMap<Any, Any>>()
|
protected val tables = HashMap<String, MutableMap<Any, Any>>()
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@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")
|
val attachmentsDir = dir.resolve("attachments")
|
||||||
try {
|
try {
|
||||||
Files.createDirectory(attachmentsDir)
|
Files.createDirectory(attachmentsDir)
|
||||||
} catch (e: FileAlreadyExistsException) {
|
} catch (e: FileAlreadyExistsException) {
|
||||||
}
|
}
|
||||||
val attachments = NodeAttachmentStorage(attachmentsDir)
|
val attachments = NodeAttachmentService(attachmentsDir)
|
||||||
return attachments
|
return attachments
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ import core.crypto.generateKeyPair
|
|||||||
import core.messaging.LegallyIdentifiableNode
|
import core.messaging.LegallyIdentifiableNode
|
||||||
import core.messaging.SingleMessageRecipient
|
import core.messaging.SingleMessageRecipient
|
||||||
import core.node.services.ArtemisMessagingService
|
import core.node.services.ArtemisMessagingService
|
||||||
import core.node.services.NodeAttachmentStorage
|
import core.node.services.NodeAttachmentService
|
||||||
import core.node.services.NodeWalletService
|
import core.node.services.NodeWalletService
|
||||||
import protocols.TimestampingProtocol
|
import protocols.TimestampingProtocol
|
||||||
import core.protocols.ProtocolLogic
|
import core.protocols.ProtocolLogic
|
||||||
@ -101,7 +101,7 @@ fun main(args: Array<String>) {
|
|||||||
if (listening) {
|
if (listening) {
|
||||||
// For demo purposes just extract attachment jars when saved to disk, so the user can explore them.
|
// 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.
|
// 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.automaticallyExtractAttachments = true
|
||||||
it.storePath
|
it.storePath
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* Stores attachments in the specified local directory, which must exist. Doesn't allow new attachments to be uploaded.
|
||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
class NodeAttachmentStorage(val storePath: Path) : AttachmentStorage {
|
class NodeAttachmentService(val storePath: Path) : AttachmentStorage {
|
||||||
private val log = loggerFor<NodeAttachmentStorage>()
|
private val log = loggerFor<NodeAttachmentService>()
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
var checkAttachmentsOnLoad = true
|
var checkAttachmentsOnLoad = true
|
@ -14,7 +14,7 @@ import core.Attachment
|
|||||||
import core.crypto.SecureHash
|
import core.crypto.SecureHash
|
||||||
import core.crypto.sha256
|
import core.crypto.sha256
|
||||||
import core.node.MockNetwork
|
import core.node.MockNetwork
|
||||||
import core.node.services.NodeAttachmentStorage
|
import core.node.services.NodeAttachmentService
|
||||||
import core.serialization.OpaqueBytes
|
import core.serialization.OpaqueBytes
|
||||||
import core.testutils.rootCauseExceptions
|
import core.testutils.rootCauseExceptions
|
||||||
import core.utilities.BriefLogFormatter
|
import core.utilities.BriefLogFormatter
|
||||||
@ -94,7 +94,7 @@ class AttachmentTests {
|
|||||||
object : MockNetwork.MockNode(path, config, mock, ts) {
|
object : MockNetwork.MockNode(path, config, mock, ts) {
|
||||||
override fun start(): MockNetwork.MockNode {
|
override fun start(): MockNetwork.MockNode {
|
||||||
super.start()
|
super.start()
|
||||||
(storage.attachments as NodeAttachmentStorage).checkAttachmentsOnLoad = false
|
(storage.attachments as NodeAttachmentService).checkAttachmentsOnLoad = false
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ package core.messaging
|
|||||||
|
|
||||||
import contracts.Cash
|
import contracts.Cash
|
||||||
import contracts.CommercialPaper
|
import contracts.CommercialPaper
|
||||||
import protocols.TwoPartyTradeProtocol
|
|
||||||
import core.*
|
import core.*
|
||||||
import core.crypto.SecureHash
|
import core.crypto.SecureHash
|
||||||
import core.node.MockNetwork
|
import core.node.MockNetwork
|
||||||
@ -21,6 +20,7 @@ import org.junit.After
|
|||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import protocols.TwoPartyTradeProtocol
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
@ -195,7 +195,7 @@ class TwoPartyTradeProtocolTests : TestWithInMemoryNetwork() {
|
|||||||
return net.createNode(null) { path, config, net, tsNode ->
|
return net.createNode(null) { path, config, net, tsNode ->
|
||||||
object : MockNetwork.MockNode(path, config, net, tsNode) {
|
object : MockNetwork.MockNode(path, config, net, tsNode) {
|
||||||
// That constructs the storage service object in a customised way ...
|
// 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 ...
|
// By tweaking the standard StorageServiceImpl class ...
|
||||||
return object : StorageServiceImpl(attachments, identity, keypair) {
|
return object : StorageServiceImpl(attachments, identity, keypair) {
|
||||||
// To use RecordingMaps instead of ordinary HashMaps.
|
// To use RecordingMaps instead of ordinary HashMaps.
|
||||||
|
@ -11,7 +11,7 @@ package core.node
|
|||||||
import com.google.common.jimfs.Configuration
|
import com.google.common.jimfs.Configuration
|
||||||
import com.google.common.jimfs.Jimfs
|
import com.google.common.jimfs.Jimfs
|
||||||
import core.crypto.SecureHash
|
import core.crypto.SecureHash
|
||||||
import core.node.services.NodeAttachmentStorage
|
import core.node.services.NodeAttachmentService
|
||||||
import core.use
|
import core.use
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -40,7 +40,7 @@ class NodeAttachmentStorageTest {
|
|||||||
val testJar = makeTestJar()
|
val testJar = makeTestJar()
|
||||||
val expectedHash = SecureHash.sha256(Files.readAllBytes(testJar))
|
val expectedHash = SecureHash.sha256(Files.readAllBytes(testJar))
|
||||||
|
|
||||||
val storage = NodeAttachmentStorage(fs.getPath("/"))
|
val storage = NodeAttachmentService(fs.getPath("/"))
|
||||||
val id = testJar.use { storage.importAttachment(it) }
|
val id = testJar.use { storage.importAttachment(it) }
|
||||||
assertEquals(expectedHash, id)
|
assertEquals(expectedHash, id)
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class NodeAttachmentStorageTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `duplicates not allowed`() {
|
fun `duplicates not allowed`() {
|
||||||
val testJar = makeTestJar()
|
val testJar = makeTestJar()
|
||||||
val storage = NodeAttachmentStorage(fs.getPath("/"))
|
val storage = NodeAttachmentService(fs.getPath("/"))
|
||||||
testJar.use { storage.importAttachment(it) }
|
testJar.use { storage.importAttachment(it) }
|
||||||
assertFailsWith<java.nio.file.FileAlreadyExistsException> {
|
assertFailsWith<java.nio.file.FileAlreadyExistsException> {
|
||||||
testJar.use { storage.importAttachment(it) }
|
testJar.use { storage.importAttachment(it) }
|
||||||
@ -67,13 +67,13 @@ class NodeAttachmentStorageTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `corrupt entry throws exception`() {
|
fun `corrupt entry throws exception`() {
|
||||||
val testJar = makeTestJar()
|
val testJar = makeTestJar()
|
||||||
val storage = NodeAttachmentStorage(fs.getPath("/"))
|
val storage = NodeAttachmentService(fs.getPath("/"))
|
||||||
val id = testJar.use { storage.importAttachment(it) }
|
val id = testJar.use { storage.importAttachment(it) }
|
||||||
|
|
||||||
// Corrupt the file in the store.
|
// Corrupt the file in the store.
|
||||||
Files.write(fs.getPath("/", id.toString()), "arggghhhh".toByteArray(), StandardOpenOption.WRITE)
|
Files.write(fs.getPath("/", id.toString()), "arggghhhh".toByteArray(), StandardOpenOption.WRITE)
|
||||||
|
|
||||||
val e = assertFailsWith<NodeAttachmentStorage.OnDiskHashMismatch> {
|
val e = assertFailsWith<NodeAttachmentService.OnDiskHashMismatch> {
|
||||||
storage.openAttachment(id)!!.open().use { it.readBytes() }
|
storage.openAttachment(id)!!.open().use { it.readBytes() }
|
||||||
}
|
}
|
||||||
assertEquals(e.file, storage.storePath.resolve(id.toString()))
|
assertEquals(e.file, storage.storePath.resolve(id.toString()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user