Merged in andrius-driver-fix (pull request #280)

DriverTest fix: get quasar.jar location from the classpath
This commit is contained in:
Andras Slemmer 2016-08-15 17:31:02 +01:00
commit 9d9164980e
2 changed files with 15 additions and 12 deletions

View File

@ -21,6 +21,7 @@ import java.io.File
import java.net.ServerSocket import java.net.ServerSocket
import java.net.Socket import java.net.Socket
import java.net.SocketException import java.net.SocketException
import java.net.URLClassLoader
import java.nio.file.Paths import java.nio.file.Paths
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@ -85,7 +86,6 @@ sealed class PortAllocation {
* @param baseDirectory The base directory node directories go into, defaults to "build/<timestamp>/". The node * @param baseDirectory The base directory node directories go into, defaults to "build/<timestamp>/". The node
* directories themselves are "<baseDirectory>/<legalName>/", where legalName defaults to "<randomName>-<messagingPort>" * directories themselves are "<baseDirectory>/<legalName>/", where legalName defaults to "<randomName>-<messagingPort>"
* and may be specified in [DriverDSL.startNode]. * and may be specified in [DriverDSL.startNode].
* @param quasarJarPath The path to quasar.jar, relative to cwd. Defaults to "lib/quasar.jar". TODO remove this once we can bundle quasar properly.
* @param portAllocation The port allocation strategy to use for the messaging and the web server addresses. Defaults to incremental. * @param portAllocation The port allocation strategy to use for the messaging and the web server addresses. Defaults to incremental.
* @param debugPortAllocation The port allocation strategy to use for jvm debugging. Defaults to incremental. * @param debugPortAllocation The port allocation strategy to use for jvm debugging. Defaults to incremental.
* @param dsl The dsl itself * @param dsl The dsl itself
@ -93,7 +93,6 @@ sealed class PortAllocation {
*/ */
fun <A> driver( fun <A> driver(
baseDirectory: String = "build/${getTimestampAsDirectoryName()}", baseDirectory: String = "build/${getTimestampAsDirectoryName()}",
quasarJarPath: String = "lib/quasar.jar",
portAllocation: PortAllocation = PortAllocation.Incremental(10000), portAllocation: PortAllocation = PortAllocation.Incremental(10000),
debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005), debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005),
dsl: DriverDSLExposedInterface.() -> A dsl: DriverDSLExposedInterface.() -> A
@ -101,14 +100,12 @@ fun <A> driver(
driverDsl = DriverDSL( driverDsl = DriverDSL(
portAllocation = portAllocation, portAllocation = portAllocation,
debugPortAllocation = debugPortAllocation, debugPortAllocation = debugPortAllocation,
baseDirectory = baseDirectory, baseDirectory = baseDirectory
quasarJarPath = quasarJarPath
), ),
coerce = { it }, coerce = { it },
dsl = dsl dsl = dsl
) )
/** /**
* This is a helper method to allow extending of the DSL, along the lines of * This is a helper method to allow extending of the DSL, along the lines of
* interface SomeOtherExposedDSLInterface : DriverDSLExposedInterface * interface SomeOtherExposedDSLInterface : DriverDSLExposedInterface
@ -185,8 +182,7 @@ fun <A> poll(f: () -> A?): A {
class DriverDSL( class DriverDSL(
val portAllocation: PortAllocation, val portAllocation: PortAllocation,
val debugPortAllocation: PortAllocation, val debugPortAllocation: PortAllocation,
val baseDirectory: String, val baseDirectory: String
val quasarJarPath: String
) : DriverDSLInternalInterface { ) : DriverDSLInternalInterface {
override val networkMapCache = InMemoryNetworkMapCache() override val networkMapCache = InMemoryNetworkMapCache()
@ -195,6 +191,15 @@ class DriverDSL(
private var networkMapNodeInfo: NodeInfo? = null private var networkMapNodeInfo: NodeInfo? = null
private val registeredProcesses = LinkedList<Process>() private val registeredProcesses = LinkedList<Process>()
//TODO: remove this once we can bundle quasar properly.
private val quasarJarPath: String by lazy {
val cl = ClassLoader.getSystemClassLoader()
val urls = (cl as URLClassLoader).urLs
val quasarPattern = ".*quasar.*\\.jar$".toRegex()
val quasarPath = urls.map { it.path }.first { quasarPattern.matches(it) }
quasarPath
}
val driverNodeConfiguration = NodeConfigurationFromConfig( val driverNodeConfiguration = NodeConfigurationFromConfig(
NodeConfiguration.loadConfig( NodeConfiguration.loadConfig(
baseDirectoryPath = Paths.get(baseDirectory, "driver-artemis"), baseDirectoryPath = Paths.get(baseDirectory, "driver-artemis"),

View File

@ -1,6 +1,5 @@
package com.r3corda.node.driver package com.r3corda.node.driver
import com.google.common.net.HostAndPort
import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.NodeInfo
import com.r3corda.core.node.services.NetworkMapCache import com.r3corda.core.node.services.NetworkMapCache
import com.r3corda.node.services.api.RegulatorService import com.r3corda.node.services.api.RegulatorService
@ -10,7 +9,6 @@ import org.junit.Test
class DriverTests { class DriverTests {
companion object { companion object {
fun nodeMustBeUp(networkMapCache: NetworkMapCache, nodeInfo: NodeInfo, nodeName: String) { fun nodeMustBeUp(networkMapCache: NetworkMapCache, nodeInfo: NodeInfo, nodeName: String) {
val address = nodeInfo.address as ArtemisMessagingComponent.Address val address = nodeInfo.address as ArtemisMessagingComponent.Address
@ -33,7 +31,7 @@ class DriverTests {
@Test @Test
fun simpleNodeStartupShutdownWorks() { fun simpleNodeStartupShutdownWorks() {
val (notary, regulator) = driver(quasarJarPath = "../lib/quasar.jar") { val (notary, regulator) = driver {
val notary = startNode("TestNotary", setOf(NotaryService.Type)) val notary = startNode("TestNotary", setOf(NotaryService.Type))
val regulator = startNode("Regulator", setOf(RegulatorService.Type)) val regulator = startNode("Regulator", setOf(RegulatorService.Type))
@ -47,7 +45,7 @@ class DriverTests {
@Test @Test
fun startingNodeWithNoServicesWorks() { fun startingNodeWithNoServicesWorks() {
val noService = driver(quasarJarPath = "../lib/quasar.jar") { val noService = driver {
val noService = startNode("NoService") val noService = startNode("NoService")
nodeMustBeUp(networkMapCache, noService, "NoService") nodeMustBeUp(networkMapCache, noService, "NoService")
noService noService
@ -57,7 +55,7 @@ class DriverTests {
@Test @Test
fun randomFreePortAllocationWorks() { fun randomFreePortAllocationWorks() {
val nodeInfo = driver(quasarJarPath = "../lib/quasar.jar", portAllocation = PortAllocation.RandomFree()) { val nodeInfo = driver(portAllocation = PortAllocation.RandomFree()) {
val nodeInfo = startNode("NoService") val nodeInfo = startNode("NoService")
nodeMustBeUp(networkMapCache, nodeInfo, "NoService") nodeMustBeUp(networkMapCache, nodeInfo, "NoService")
nodeInfo nodeInfo