mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
Make logging available in IntelliJ between gradle clean and assemble (#929)
* Enforce absence of node from client rpc smokeTest classpath
This commit is contained in:
parent
77e1d54c43
commit
0aadc037ef
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@ -79,6 +79,8 @@
|
|||||||
<module name="simm-valuation-demo_test" target="1.8" />
|
<module name="simm-valuation-demo_test" target="1.8" />
|
||||||
<module name="smoke-test-utils_main" target="1.8" />
|
<module name="smoke-test-utils_main" target="1.8" />
|
||||||
<module name="smoke-test-utils_test" target="1.8" />
|
<module name="smoke-test-utils_test" target="1.8" />
|
||||||
|
<module name="test-common_main" target="1.8" />
|
||||||
|
<module name="test-common_test" target="1.8" />
|
||||||
<module name="test-utils_integrationTest" target="1.8" />
|
<module name="test-utils_integrationTest" target="1.8" />
|
||||||
<module name="test-utils_main" target="1.8" />
|
<module name="test-utils_main" target="1.8" />
|
||||||
<module name="test-utils_test" target="1.8" />
|
<module name="test-utils_test" target="1.8" />
|
||||||
|
@ -103,12 +103,6 @@ allprojects {
|
|||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
// Use manual resource copying of log4j2.xml rather than source sets.
|
|
||||||
// This prevents problems in IntelliJ with regard to duplicate source roots.
|
|
||||||
processTestResources {
|
|
||||||
from file("$rootDir/config/test/log4j2.xml")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-Xlint:-options" << "-parameters"
|
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-Xlint:-options" << "-parameters"
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,6 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processSmokeTestResources {
|
processSmokeTestResources {
|
||||||
from(file("$rootDir/config/test/log4j2.xml")) {
|
|
||||||
rename 'log4j2\\.xml', 'log4j2-test.xml'
|
|
||||||
}
|
|
||||||
from(project(':node:capsule').tasks.buildCordaJAR) {
|
from(project(':node:capsule').tasks.buildCordaJAR) {
|
||||||
rename 'corda-(.*)', 'corda.jar'
|
rename 'corda-(.*)', 'corda.jar'
|
||||||
}
|
}
|
||||||
@ -85,4 +82,4 @@ jar {
|
|||||||
|
|
||||||
publish {
|
publish {
|
||||||
name = jar.baseName
|
name = jar.baseName
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.corda.kotlin.rpc
|
||||||
|
|
||||||
|
import net.corda.core.div
|
||||||
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.Paths
|
||||||
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
class ValidateClasspathTest {
|
||||||
|
@Test
|
||||||
|
fun `node not on classpath`() {
|
||||||
|
val paths = System.getProperty("java.class.path").split(File.pathSeparatorChar).map { Paths.get(it) }
|
||||||
|
// First find core so that if node is there, it's in the form we expect:
|
||||||
|
assertFalse(paths.filter { it.contains("core" / "build") }.isEmpty())
|
||||||
|
assertTrue(paths.filter { it.contains("node" / "build") }.isEmpty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Path.contains(that: Path): Boolean {
|
||||||
|
val size = that.nameCount
|
||||||
|
(0..nameCount - size).forEach {
|
||||||
|
if (subpath(it, it + size) == that) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
package net.corda.core.utilities
|
|
||||||
|
|
||||||
import java.nio.file.Path
|
|
||||||
|
|
||||||
// TODO This doesn't belong in core and can be moved into node
|
|
||||||
object ProcessUtilities {
|
|
||||||
inline fun <reified C : Any> startJavaProcess(
|
|
||||||
arguments: List<String>,
|
|
||||||
classpath: String = defaultClassPath,
|
|
||||||
jdwpPort: Int? = null,
|
|
||||||
extraJvmArguments: List<String> = emptyList(),
|
|
||||||
inheritIO: Boolean = true,
|
|
||||||
errorLogPath: Path? = null,
|
|
||||||
workingDirectory: Path? = null
|
|
||||||
): Process {
|
|
||||||
return startJavaProcess(C::class.java.name, arguments, classpath, jdwpPort, extraJvmArguments, inheritIO, errorLogPath, workingDirectory)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startJavaProcess(
|
|
||||||
className: String,
|
|
||||||
arguments: List<String>,
|
|
||||||
classpath: String = defaultClassPath,
|
|
||||||
jdwpPort: Int? = null,
|
|
||||||
extraJvmArguments: List<String> = emptyList(),
|
|
||||||
inheritIO: Boolean = true,
|
|
||||||
errorLogPath: Path? = null,
|
|
||||||
workingDirectory: Path? = null
|
|
||||||
): Process {
|
|
||||||
val separator = System.getProperty("file.separator")
|
|
||||||
val javaPath = System.getProperty("java.home") + separator + "bin" + separator + "java"
|
|
||||||
val debugPortArgument = if (jdwpPort != null) {
|
|
||||||
listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$jdwpPort")
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
val allArguments = listOf(javaPath) +
|
|
||||||
debugPortArgument +
|
|
||||||
listOf("-Xmx200m", "-XX:+UseG1GC") +
|
|
||||||
extraJvmArguments +
|
|
||||||
listOf("-cp", classpath, className) +
|
|
||||||
arguments.toList()
|
|
||||||
return ProcessBuilder(allArguments).apply {
|
|
||||||
if (errorLogPath != null) redirectError(errorLogPath.toFile())
|
|
||||||
if (inheritIO) inheritIO()
|
|
||||||
if (workingDirectory != null) directory(workingDirectory.toFile())
|
|
||||||
}.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
val defaultClassPath: String get() = System.getProperty("java.class.path")
|
|
||||||
}
|
|
@ -37,7 +37,7 @@ class BootTests {
|
|||||||
assertThat(logConfigFile).isRegularFile()
|
assertThat(logConfigFile).isRegularFile()
|
||||||
driver(isDebug = true, systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString())) {
|
driver(isDebug = true, systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString())) {
|
||||||
val alice = startNode(ALICE.name).get()
|
val alice = startNode(ALICE.name).get()
|
||||||
val logFolder = alice.configuration.baseDirectory / "logs"
|
val logFolder = alice.configuration.baseDirectory / NodeStartup.LOGS_DIRECTORY_NAME
|
||||||
val logFile = logFolder.toFile().listFiles { _, name -> name.endsWith(".log") }.single()
|
val logFile = logFolder.toFile().listFiles { _, name -> name.endsWith(".log") }.single()
|
||||||
// Start second Alice, should fail
|
// Start second Alice, should fail
|
||||||
assertThatThrownBy {
|
assertThatThrownBy {
|
||||||
|
@ -19,6 +19,7 @@ include 'experimental'
|
|||||||
include 'experimental:sandbox'
|
include 'experimental:sandbox'
|
||||||
include 'experimental:quasar-hook'
|
include 'experimental:quasar-hook'
|
||||||
include 'verifier'
|
include 'verifier'
|
||||||
|
include 'test-common'
|
||||||
include 'test-utils'
|
include 'test-utils'
|
||||||
include 'smoke-test-utils'
|
include 'smoke-test-utils'
|
||||||
include 'tools:explorer'
|
include 'tools:explorer'
|
||||||
|
@ -4,5 +4,6 @@ description 'Utilities needed for smoke tests in Corda'
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Smoke tests do NOT have any Node code on the classpath!
|
// Smoke tests do NOT have any Node code on the classpath!
|
||||||
|
compile project(':test-common')
|
||||||
compile project(':client:rpc')
|
compile project(':client:rpc')
|
||||||
}
|
}
|
||||||
|
1
test-common/build.gradle
Normal file
1
test-common/build.gradle
Normal file
@ -0,0 +1 @@
|
|||||||
|
// Nothing needed here currently.
|
@ -27,6 +27,7 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile project(':test-common')
|
||||||
compile project(':finance')
|
compile project(':finance')
|
||||||
compile project(':core')
|
compile project(':core')
|
||||||
compile project(':node')
|
compile project(':node')
|
||||||
|
@ -12,7 +12,7 @@ import net.corda.core.div
|
|||||||
import net.corda.core.map
|
import net.corda.core.map
|
||||||
import net.corda.core.messaging.RPCOps
|
import net.corda.core.messaging.RPCOps
|
||||||
import net.corda.core.random63BitValue
|
import net.corda.core.random63BitValue
|
||||||
import net.corda.core.utilities.ProcessUtilities
|
import net.corda.testing.driver.ProcessUtilities
|
||||||
import net.corda.node.services.RPCUserService
|
import net.corda.node.services.RPCUserService
|
||||||
import net.corda.node.services.messaging.ArtemisMessagingServer
|
import net.corda.node.services.messaging.ArtemisMessagingServer
|
||||||
import net.corda.node.services.messaging.RPCServer
|
import net.corda.node.services.messaging.RPCServer
|
||||||
|
@ -792,7 +792,7 @@ class DriverDSL(
|
|||||||
"-javaagent:$quasarJarPath"
|
"-javaagent:$quasarJarPath"
|
||||||
val loggingLevel = if (debugPort == null) "INFO" else "DEBUG"
|
val loggingLevel = if (debugPort == null) "INFO" else "DEBUG"
|
||||||
|
|
||||||
ProcessUtilities.startJavaProcess(
|
ProcessUtilities.startCordaProcess(
|
||||||
className = "net.corda.node.Corda", // cannot directly get class for this, so just use string
|
className = "net.corda.node.Corda", // cannot directly get class for this, so just use string
|
||||||
arguments = listOf(
|
arguments = listOf(
|
||||||
"--base-directory=${nodeConf.baseDirectory}",
|
"--base-directory=${nodeConf.baseDirectory}",
|
||||||
@ -817,7 +817,7 @@ class DriverDSL(
|
|||||||
): ListenableFuture<Process> {
|
): ListenableFuture<Process> {
|
||||||
return executorService.submit<Process> {
|
return executorService.submit<Process> {
|
||||||
val className = "net.corda.webserver.WebServer"
|
val className = "net.corda.webserver.WebServer"
|
||||||
ProcessUtilities.startJavaProcess(
|
ProcessUtilities.startCordaProcess(
|
||||||
className = className, // cannot directly get class for this, so just use string
|
className = className, // cannot directly get class for this, so just use string
|
||||||
arguments = listOf("--base-directory", handle.configuration.baseDirectory.toString()),
|
arguments = listOf("--base-directory", handle.configuration.baseDirectory.toString()),
|
||||||
jdwpPort = debugPort,
|
jdwpPort = debugPort,
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package net.corda.testing.driver
|
||||||
|
|
||||||
|
import net.corda.core.div
|
||||||
|
import net.corda.core.exists
|
||||||
|
import java.io.File.pathSeparator
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
object ProcessUtilities {
|
||||||
|
inline fun <reified C : Any> startJavaProcess(
|
||||||
|
arguments: List<String>,
|
||||||
|
jdwpPort: Int? = null
|
||||||
|
): Process {
|
||||||
|
return startJavaProcessImpl(C::class.java.name, arguments, defaultClassPath, jdwpPort, emptyList(), null, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startCordaProcess(
|
||||||
|
className: String,
|
||||||
|
arguments: List<String>,
|
||||||
|
jdwpPort: Int?,
|
||||||
|
extraJvmArguments: List<String>,
|
||||||
|
errorLogPath: Path?,
|
||||||
|
workingDirectory: Path? = null
|
||||||
|
): Process {
|
||||||
|
// FIXME: Instead of hacking our classpath, use the correct classpath for className.
|
||||||
|
val classpath = defaultClassPath.split(pathSeparator).filter { !(it / "log4j2-test.xml").exists() }.joinToString(pathSeparator)
|
||||||
|
return startJavaProcessImpl(className, arguments, classpath, jdwpPort, extraJvmArguments, errorLogPath, workingDirectory)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startJavaProcessImpl(
|
||||||
|
className: String,
|
||||||
|
arguments: List<String>,
|
||||||
|
classpath: String,
|
||||||
|
jdwpPort: Int?,
|
||||||
|
extraJvmArguments: List<String>,
|
||||||
|
errorLogPath: Path?,
|
||||||
|
workingDirectory: Path?
|
||||||
|
): Process {
|
||||||
|
val command = mutableListOf<String>().apply {
|
||||||
|
add((System.getProperty("java.home") / "bin" / "java").toString())
|
||||||
|
(jdwpPort != null) && add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$jdwpPort")
|
||||||
|
add("-Xmx200m")
|
||||||
|
add("-XX:+UseG1GC")
|
||||||
|
addAll(extraJvmArguments)
|
||||||
|
add("-cp")
|
||||||
|
add(classpath)
|
||||||
|
add(className)
|
||||||
|
addAll(arguments)
|
||||||
|
}
|
||||||
|
return ProcessBuilder(command).apply {
|
||||||
|
if (errorLogPath != null) redirectError(errorLogPath.toFile()) // FIXME: Undone by inheritIO.
|
||||||
|
inheritIO()
|
||||||
|
if (workingDirectory != null) directory(workingDirectory.toFile())
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
val defaultClassPath: String get() = System.getProperty("java.class.path")
|
||||||
|
}
|
@ -13,7 +13,7 @@ import net.corda.core.div
|
|||||||
import net.corda.core.map
|
import net.corda.core.map
|
||||||
import net.corda.core.random63BitValue
|
import net.corda.core.random63BitValue
|
||||||
import net.corda.core.transactions.LedgerTransaction
|
import net.corda.core.transactions.LedgerTransaction
|
||||||
import net.corda.core.utilities.ProcessUtilities
|
import net.corda.testing.driver.ProcessUtilities
|
||||||
import net.corda.core.utilities.loggerFor
|
import net.corda.core.utilities.loggerFor
|
||||||
import net.corda.node.services.config.configureDevKeyAndTrustStores
|
import net.corda.node.services.config.configureDevKeyAndTrustStores
|
||||||
import net.corda.nodeapi.ArtemisMessagingComponent.Companion.NODE_USER
|
import net.corda.nodeapi.ArtemisMessagingComponent.Companion.NODE_USER
|
||||||
|
Loading…
Reference in New Issue
Block a user