Skip to content

Commit

Permalink
Checking that the smoke tests don't have the node on their classpath.
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsasari committed Nov 2, 2017
1 parent 2e0e78e commit 837e880
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 67 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,59 @@ apply plugin: 'com.jfrog.artifactory'

description 'Corda core'

evaluationDependsOn(':node:capsule')

configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime

smokeTestCompile.extendsFrom compile
smokeTestRuntime.extendsFrom runtime
}

sourceSets {
integrationTest {
kotlin {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/kotlin')
}
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
}
smokeTest {
kotlin {
// We must NOT have any Node code on the classpath, so do NOT
// include the test or integrationTest dependencies here.
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/smoke-test/kotlin')
}
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/smoke-test/java')
}
}
}

processSmokeTestResources {
// Bring in the fully built corda.jar for use by NodeFactory in the smoke tests
from(project(':node:capsule').tasks['buildCordaJAR']) {
rename 'corda-(.*)', 'corda.jar'
}
}

buildscript {
repositories {
mavenCentral()
}
}

dependencies {

testCompile "junit:junit:$junit_version"
testCompile "commons-fileupload:commons-fileupload:$fileupload_version"

Expand Down Expand Up @@ -48,6 +93,11 @@ dependencies {
// Guava: Google utilities library.
testCompile "com.google.guava:guava:$guava_version"

// Smoke tests do NOT have any Node code on the classpath!
smokeTestCompile project(':smoke-test-utils')
smokeTestCompile "org.assertj:assertj-core:${assertj_version}"
smokeTestCompile "junit:junit:$junit_version"

// RxJava: observable streams of events.
compile "io.reactivex:rxjava:$rxjava_version"

Expand Down Expand Up @@ -87,6 +137,22 @@ task testJar(type: Jar) {
from sourceSets.test.output
}

task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}

task smokeTestJar(type: Jar) {
classifier 'smokeTests'
from sourceSets.smokeTest.output
}

task smokeTest(type: Test) {
dependsOn smokeTestJar
testClassesDirs = sourceSets.smokeTest.output.classesDirs
classpath = sourceSets.smokeTest.runtimeClasspath
}

artifacts {
testArtifacts testJar
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.corda.node
package net.corda.core.cordapp

import co.paralleluniverse.fibers.Suspendable
import net.corda.core.flows.*
Expand All @@ -11,7 +11,6 @@ import net.corda.core.internal.list
import net.corda.core.messaging.startFlow
import net.corda.core.utilities.getOrThrow
import net.corda.core.utilities.unwrap
import net.corda.node.internal.cordapp.CordappLoader
import net.corda.nodeapi.User
import net.corda.smoketesting.NodeConfig
import net.corda.smoketesting.NodeProcess
Expand All @@ -23,6 +22,7 @@ import kotlin.streams.toList

class CordappSmokeTest {
private companion object {
private const val CORDAPPS_DIR_NAME = "cordapps"
val user = User("user1", "test", permissions = setOf("ALL"))
val port = AtomicInteger(15100)
}
Expand All @@ -38,9 +38,10 @@ class CordappSmokeTest {
users = listOf(user)
)


@Test
fun `FlowContent appName returns the filename of the CorDapp jar`() {
val cordappsDir = (factory.baseDirectory(aliceConfig) / CordappLoader.CORDAPPS_DIR_NAME).createDirectories()
val cordappsDir = (factory.baseDirectory(aliceConfig) / CORDAPPS_DIR_NAME).createDirectories()
// Find the jar file for the smoke tests of this module
val selfCordapp = Paths.get("build", "libs").list {
it.filter { "-smokeTests" in it.toString() }.toList().single()
Expand All @@ -61,7 +62,7 @@ class CordappSmokeTest {

@Test
fun `empty cordapps directory`() {
(factory.baseDirectory(aliceConfig) / CordappLoader.CORDAPPS_DIR_NAME).createDirectories()
(factory.baseDirectory(aliceConfig) / CORDAPPS_DIR_NAME).createDirectories()
factory.create(aliceConfig).close()
}

Expand Down
40 changes: 0 additions & 40 deletions node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ configurations {

integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime

smokeTestCompile.extendsFrom compile
smokeTestRuntime.extendsFrom runtime
}

sourceSets {
Expand All @@ -40,20 +37,6 @@ sourceSets {
srcDir file('src/integration-test/resources')
}
}
smokeTest {
kotlin {
// We must NOT have any Node code on the classpath, so do NOT
// include the test or integrationTest dependencies here.
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/smoke-test/kotlin')
}
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/smoke-test/java')
}
}
}

// Use manual resource copying of log4j2.xml rather than source sets.
Expand All @@ -62,13 +45,6 @@ processResources {
from file("$rootDir/config/dev/log4j2.xml")
}

processSmokeTestResources {
// Bring in the fully built corda.jar for use by NodeFactory in the smoke tests
from(project(':node:capsule').tasks.buildCordaJAR) {
rename 'corda-(.*)', 'corda.jar'
}
}

// To find potential version conflicts, run "gradle htmlDependencyReport" and then look in
// build/reports/project/dependencies/index.html for green highlighted parts of the tree.

Expand Down Expand Up @@ -181,11 +157,6 @@ dependencies {
integrationTestCompile "junit:junit:$junit_version"
integrationTestCompile "org.assertj:assertj-core:${assertj_version}"

// Smoke tests do NOT have any Node code on the classpath!
smokeTestCompile project(':smoke-test-utils')
smokeTestCompile "org.assertj:assertj-core:${assertj_version}"
smokeTestCompile "junit:junit:$junit_version"

// Jetty dependencies for NetworkMapClient test.
// Web stuff: for HTTP[S] servlets
testCompile "org.eclipse.jetty:jetty-servlet:${jetty_version}"
Expand All @@ -203,17 +174,6 @@ task integrationTest(type: Test) {
classpath = sourceSets.integrationTest.runtimeClasspath
}

task smokeTestJar(type: Jar) {
classifier 'smokeTests'
from sourceSets.smokeTest.output
}

task smokeTest(type: Test) {
dependsOn smokeTestJar
testClassesDirs = sourceSets.smokeTest.output.classesDirs
classpath = sourceSets.smokeTest.runtimeClasspath
}

jar {
baseName 'corda-node'
}
Expand Down
1 change: 1 addition & 0 deletions node/src/main/kotlin/net/corda/node/Corda.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This class is used by the smoke tests as a check that the node module isn't on their classpath
@file:JvmName("Corda")

package net.corda.node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit.SECONDS

class NodeProcess(
val config: NodeConfig,
val nodeDir: Path,
private val config: NodeConfig,
private val nodeDir: Path,
private val node: Process,
private val client: CordaRPCClient
) : AutoCloseable {
private companion object {
val log = loggerFor<NodeProcess>()
val javaPath: Path = Paths.get(System.getProperty("java.home"), "bin", "java")
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").withZone(systemDefault())
}

fun connect(): CordaRPCConnection {
Expand All @@ -43,14 +41,25 @@ class NodeProcess(
(nodeDir / "artemis").toFile().deleteRecursively()
}

class Factory(val buildDirectory: Path = Paths.get("build"),
val cordaJar: Path = Paths.get(this::class.java.getResource("/corda.jar").toURI())) {
val nodesDirectory = buildDirectory / formatter.format(Instant.now())

init {
nodesDirectory.createDirectories()
class Factory(
private val buildDirectory: Path = Paths.get("build"),
private val cordaJar: Path = Paths.get(this::class.java.getResource("/corda.jar").toURI())
) {
companion object {
val javaPath: Path = Paths.get(System.getProperty("java.home"), "bin", "java")
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").withZone(systemDefault())
init {
try {
Class.forName("net.corda.node.Corda")
throw Error("Smoke test has the node in its classpath. Please remove the offending dependency.")
} catch (e: ClassNotFoundException) {
// If the class can't be found then we're good!
}
}
}

private val nodesDirectory = (buildDirectory / formatter.format(Instant.now())).createDirectories()

fun baseDirectory(config: NodeConfig): Path = nodesDirectory / config.commonName

fun create(config: NodeConfig): NodeProcess {
Expand Down

0 comments on commit 837e880

Please sign in to comment.