Skip to content

Commit

Permalink
Merge pull request corda#6678 from corda/jzd/merge-os4.6-to-os4.7-202…
Browse files Browse the repository at this point in the history
…0-09-01

NOTICK: Merge OS 4.6 into OS 4.7
  • Loading branch information
rick-r3 authored Sep 4, 2020
2 parents 02b2b35 + eecc294 commit e937889
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,24 +408,24 @@ class CordaRPCClientReconnectionTest {

val completedCounter = AtomicInteger(0)
flowHandle0.returnValue.doOnComplete {
completedCounter.incrementAndGet()
completedCounter.getAndIncrement()
}
flowHandle1!!.returnValue.doOnComplete {
completedCounter.incrementAndGet()
completedCounter.getAndIncrement()
}

flowHandle0.returnValue.thenMatch({
completedCounter.incrementAndGet()
completedCounter.getAndIncrement()
}, {})
flowHandle1.returnValue.thenMatch({
completedCounter.incrementAndGet()
completedCounter.getAndIncrement()
}, {})

flowHandle0.returnValue.toCompletableFuture().thenApply {
completedCounter.incrementAndGet()
completedCounter.getAndIncrement()
}
flowHandle1.returnValue.toCompletableFuture().thenApply {
completedCounter.incrementAndGet()
completedCounter.getAndIncrement()
}

node.stop()
Expand Down Expand Up @@ -469,13 +469,13 @@ class CordaRPCClientReconnectionTest {
val clientId = UUID.randomUUID().toString()
val flowHandle = rpcOps.startFlowWithClientId(clientId, ::ThrowingFlow)

var erroredCounter = 0
val erroredCounter = AtomicInteger(0)
flowHandle.returnValue.doOnError {
erroredCounter++
erroredCounter.getAndIncrement()
}

flowHandle.returnValue.toCompletableFuture().exceptionally {
erroredCounter++
erroredCounter.getAndIncrement()
}

node.stop()
Expand All @@ -489,7 +489,7 @@ class CordaRPCClientReconnectionTest {
}

sleep(1000)
assertEquals(2, erroredCounter)
assertEquals(2, erroredCounter.get())
assertThat(rpcOps.reconnectingRPCConnection.isClosed())
}
}
Expand Down
5 changes: 3 additions & 2 deletions node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ open class SharedNodeCmdLineOptions {
return """
Unable to load the node config file from '$configFile'.
${cause?.message?.let { "Cause: $it" } ?: ""}
Try setting the --base-directory flag to change which directory the node
Ensure that the [COMMAND] precedes all options. Alternatively, try
setting the --base-directory flag to change which directory the node
is looking in, or use the --config-file flag to specify it explicitly.
""".trimIndent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ class NodeInfoWatcher(private val nodePath: Path,
private val logger = contextLogger()

// TODO This method doesn't belong in this class
fun saveToFile(path: Path, nodeInfoAndSigned: NodeInfoAndSigned) {
fun saveToFile(path: Path, nodeInfoAndSigned: NodeInfoAndSigned): Path {
// By using the hash of the node's first name we ensure:
// 1) node info files for the same node map to the same filename and thus avoid having duplicate files for
// the same node
// 2) avoid having to deal with characters in the X.500 name which are incompatible with the local filesystem
val fileNameHash = nodeInfoAndSigned.nodeInfo.legalIdentities[0].name.serialize().hash
val target = path / "${NodeInfoFilesCopier.NODE_INFO_FILE_NAME_PREFIX}$fileNameHash"
nodeInfoAndSigned
.signed
.serialize()
.open()
.copyTo(path / "${NodeInfoFilesCopier.NODE_INFO_FILE_NAME_PREFIX}$fileNameHash", REPLACE_EXISTING)
.copyTo(target, REPLACE_EXISTING)

return target
}
}

Expand Down Expand Up @@ -85,6 +88,7 @@ class NodeInfoWatcher(private val nodePath: Path,
logger.debug { "Examining $it" }
true
}
.filter { !it.toString().endsWith(".tmp") }
.filter { it.isRegularFile() }
.filter { file ->
val lastModifiedTime = file.lastModifiedTime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import net.corda.core.internal.createDirectories
import net.corda.core.internal.div
import net.corda.core.internal.size
import net.corda.core.node.services.KeyManagementService
import net.corda.coretesting.internal.createNodeInfoAndSigned
import net.corda.nodeapi.internal.NodeInfoAndSigned
import net.corda.nodeapi.internal.network.NodeInfoFilesCopier
import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.SerializationEnvironmentRule
import net.corda.coretesting.internal.createNodeInfoAndSigned
import net.corda.testing.node.internal.MockKeyManagementService
import net.corda.testing.node.makeTestIdentityService
import org.assertj.core.api.Assertions.assertThat
Expand All @@ -21,7 +21,9 @@ import org.junit.Test
import org.junit.rules.TemporaryFolder
import rx.observers.TestSubscriber
import rx.schedulers.TestScheduler
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.concurrent.TimeUnit
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand Down Expand Up @@ -132,6 +134,31 @@ class NodeInfoWatcherTest {
}
}

@Test(timeout=300_000)
fun `ignore tmp files`() {
nodeInfoPath.createDirectories()

// Start polling with an empty folder.
val subscription = nodeInfoWatcher.nodeInfoUpdates().subscribe(testSubscriber)
try {
// Ensure the watch service is started.
advanceTime()


// create file
// boohoo, we shouldn't create real files, instead mock Path
val file = NodeInfoWatcher.saveToFile(nodeInfoPath, nodeInfoAndSigned)
Files.move(file, Paths.get("$file.tmp"))

advanceTime()

// Check no nodeInfos are read.
assertEquals(0, testSubscriber.onNextEvents.distinct().flatten().size)
} finally {
subscription.unsubscribe()
}
}

private fun advanceTime() {
scheduler.advanceTimeBy(1, TimeUnit.MINUTES)
}
Expand Down

0 comments on commit e937889

Please sign in to comment.