Clean up BFTNotaryServiceTests

BFTNotaryServiceTests generates a master node independently of the cluster nodes, so it can put it
at the end of the list of nodes. The calling function however treats the first node in the list as
the master, not the last node. This simplifies the code while maintaining the same behaviour.
This commit is contained in:
Ross Nicoll
2017-04-25 14:29:39 +01:00
parent f92949d3b5
commit c8af48ebd9

View File

@ -26,7 +26,9 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
class BFTNotaryServiceTests : NodeBasedTest() { class BFTNotaryServiceTests : NodeBasedTest() {
private val notaryName = "BFT Notary Server" private companion object {
val notaryName = "BFT Notary Server"
}
@Test @Test
fun `detect double spend`() { fun `detect double spend`() {
@ -74,6 +76,7 @@ class BFTNotaryServiceTests : NodeBasedTest() {
private fun startBFTNotaryCluster(notaryName: String, private fun startBFTNotaryCluster(notaryName: String,
clusterSize: Int, clusterSize: Int,
serviceType: ServiceType): List<Node> { serviceType: ServiceType): List<Node> {
require(clusterSize > 0)
val quorum = (2 * clusterSize + 1) / 3 val quorum = (2 * clusterSize + 1) / 3
ServiceIdentityGenerator.generateToDisk( ServiceIdentityGenerator.generateToDisk(
(0 until clusterSize).map { tempFolder.root.toPath() / "$notaryName-$it" }, (0 until clusterSize).map { tempFolder.root.toPath() / "$notaryName-$it" },
@ -82,13 +85,7 @@ class BFTNotaryServiceTests : NodeBasedTest() {
quorum) quorum)
val serviceInfo = ServiceInfo(serviceType, notaryName) val serviceInfo = ServiceInfo(serviceType, notaryName)
val masterNode = startNode( val nodes = (0 until clusterSize).map {
"$notaryName-0",
advertisedServices = setOf(serviceInfo),
configOverrides = mapOf("notaryNodeId" to 0)
).getOrThrow()
val remainingNodes = (1 until clusterSize).map {
startNode( startNode(
"$notaryName-$it", "$notaryName-$it",
advertisedServices = setOf(serviceInfo), advertisedServices = setOf(serviceInfo),
@ -96,6 +93,6 @@ class BFTNotaryServiceTests : NodeBasedTest() {
).getOrThrow() ).getOrThrow()
} }
return remainingNodes + masterNode return nodes
} }
} }