Skip to content

Commit 2e63ca6

Browse files
authored
ENT-11065: Remove the need for JVM flags in client code (corda#7635)
1 parent 406f7ff commit 2e63ca6

File tree

63 files changed

+465
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+465
-825
lines changed

build.gradle

+9-32
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,6 @@ buildscript {
121121
ext.fontawesomefx_commons_version = constants.getProperty("fontawesomefxCommonsVersion")
122122
ext.fontawesomefx_fontawesome_version = constants.getProperty("fontawesomefxFontawesomeVersion")
123123
ext.javaassist_version = constants.getProperty("javaassistVersion")
124-
ext.test_add_opens = [
125-
'--add-opens', 'java.base/java.time=ALL-UNNAMED',
126-
'--add-opens', 'java.base/java.io=ALL-UNNAMED',
127-
'--add-opens', 'java.base/java.util=ALL-UNNAMED',
128-
'--add-opens', 'java.base/java.net=ALL-UNNAMED',
129-
'--add-opens', 'java.base/java.nio=ALL-UNNAMED',
130-
'--add-opens', 'java.base/java.lang.invoke=ALL-UNNAMED',
131-
'--add-opens', 'java.base/java.security.cert=ALL-UNNAMED',
132-
'--add-opens', 'java.base/java.security=ALL-UNNAMED',
133-
'--add-opens', 'java.base/javax.net.ssl=ALL-UNNAMED',
134-
'--add-opens', 'java.base/java.lang=ALL-UNNAMED',
135-
'--add-opens', 'java.base/java.util.concurrent=ALL-UNNAMED',
136-
'--add-opens', 'java.sql/java.sql=ALL-UNNAMED'
137-
]
138-
ext.test_add_exports = [
139-
'--add-exports', 'java.base/sun.nio.ch=ALL-UNNAMED'
140-
]
141124

142125
ext.corda_revision = {
143126
try {
@@ -282,11 +265,6 @@ allprojects {
282265
toolVersion = "0.8.7"
283266
}
284267

285-
test {
286-
jvmArgs test_add_opens
287-
jvmArgs test_add_exports
288-
}
289-
290268
java {
291269
withSourcesJar()
292270
withJavadocJar()
@@ -330,15 +308,14 @@ allprojects {
330308
attributes('Corda-Docs-Link': corda_docs_link)
331309
}
332310
}
333-
311+
334312
tasks.withType(Test).configureEach {
313+
jvmArgs += project(":node:capsule").file("src/main/resources/node-jvm-args.txt").readLines()
314+
jvmArgs += "--add-modules=jdk.incubator.foreign" // For the SharedMemoryIncremental
335315
forkEvery = 20
336316
ignoreFailures = project.hasProperty('tests.ignoreFailures') ? project.property('tests.ignoreFailures').toBoolean() : false
337317
failFast = project.hasProperty('tests.failFast') ? project.property('tests.failFast').toBoolean() : false
338318

339-
// Prevent the project from creating temporary files outside of the build directory.
340-
systemProperty 'java.io.tmpdir', buildDir.absolutePath
341-
342319
maxHeapSize = "1g"
343320

344321
if (project.path.startsWith(':experimental') && System.getProperty("experimental.test.enable") == null) {
@@ -351,15 +328,15 @@ allprojects {
351328
// ex.append = false
352329
}
353330

354-
maxParallelForks = (System.env.CORDA_TESTING_FORKS == null) ? 1 : "$System.env.CORDA_TESTING_FORKS".toInteger()
355-
356-
systemProperty 'java.security.egd', 'file:/dev/./urandom'
357-
}
358-
359-
tasks.withType(Test).configureEach {
360331
if (name.contains("integrationTest")) {
361332
maxParallelForks = (System.env.CORDA_INT_TESTING_FORKS == null) ? 1 : "$System.env.CORDA_INT_TESTING_FORKS".toInteger()
333+
} else {
334+
maxParallelForks = (System.env.CORDA_TESTING_FORKS == null) ? 1 : "$System.env.CORDA_TESTING_FORKS".toInteger()
362335
}
336+
337+
// Prevent the project from creating temporary files outside of the build directory.
338+
systemProperty 'java.io.tmpdir', buildDir.absolutePath
339+
systemProperty 'java.security.egd', 'file:/dev/./urandom'
363340
}
364341

365342
group 'net.corda'

client/rpc/build.gradle

+61-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ description 'Corda client RPC modules'
1010
configurations {
1111
integrationTestImplementation.extendsFrom testImplementation
1212
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
13+
14+
smokeTestImplementation.extendsFrom compile
15+
smokeTestRuntimeOnly.extendsFrom runtimeOnly
1316
}
1417

1518
sourceSets {
@@ -28,55 +31,95 @@ sourceSets {
2831
srcDirs "src/integration-test/resources"
2932
}
3033
}
34+
smokeTest {
35+
kotlin {
36+
// We must NOT have any Node code on the classpath, so do NOT
37+
// include the test or integrationTest dependencies here.
38+
compileClasspath += main.output
39+
runtimeClasspath += main.output
40+
srcDir file('src/smoke-test/kotlin')
41+
}
42+
java {
43+
compileClasspath += main.output
44+
runtimeClasspath += main.output
45+
srcDir file('src/smoke-test/java')
46+
}
47+
}
3148
}
3249

3350
dependencies {
3451
implementation project(':core')
3552
implementation project(':node-api')
3653
implementation project(':serialization')
37-
3854
// For caches rather than guava
3955
implementation "com.github.ben-manes.caffeine:caffeine:$caffeine_version"
40-
4156
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
57+
implementation "io.reactivex:rxjava:$rxjava_version"
58+
implementation("org.apache.activemq:artemis-core-client:${artemis_version}") {
59+
exclude group: 'org.jgroups', module: 'jgroups'
60+
}
61+
implementation "com.google.guava:guava-testlib:$guava_version"
4262

63+
testImplementation project(':node')
64+
testImplementation project(':node-driver')
65+
testImplementation project(':client:mock')
66+
testImplementation project(':core-test-utils')
4367
testImplementation "junit:junit:$junit_version"
44-
45-
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
46-
testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"
47-
4868
// Unit testing helpers.
4969
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
5070
testImplementation "org.assertj:assertj-core:${assertj_version}"
5171
testImplementation "io.dropwizard.metrics:metrics-core:$metrics_version"
5272

53-
testImplementation project(':node')
54-
testImplementation project(':node-driver')
55-
testImplementation project(':client:mock')
56-
testImplementation project(':core-test-utils')
73+
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
74+
testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"
5775

5876
integrationTestImplementation project(path: ':node-api', configuration: 'testArtifacts')
5977
integrationTestImplementation project(':common-configuration-parsing')
6078
integrationTestImplementation project(':finance:contracts')
6179
integrationTestImplementation project(':finance:workflows')
6280
integrationTestImplementation project(':test-utils')
63-
6481
integrationTestImplementation "co.paralleluniverse:quasar-core:$quasar_version"
6582
integrationTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockito_kotlin_version"
6683

67-
implementation "io.reactivex:rxjava:$rxjava_version"
68-
implementation("org.apache.activemq:artemis-core-client:${artemis_version}") {
69-
exclude group: 'org.jgroups', module: 'jgroups'
84+
smokeTestImplementation project(':core')
85+
smokeTestImplementation project(':node-api')
86+
smokeTestImplementation project(':finance:contracts')
87+
smokeTestImplementation project(':finance:workflows')
88+
smokeTestImplementation project(':smoke-test-utils')
89+
smokeTestImplementation project(':testing:cordapps:sleeping')
90+
smokeTestImplementation "junit:junit:$junit_version"
91+
smokeTestImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
92+
smokeTestImplementation "com.google.guava:guava:$guava_version"
93+
smokeTestImplementation "org.hamcrest:hamcrest-library:2.1"
94+
95+
smokeTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
96+
smokeTestRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"
97+
}
98+
99+
processSmokeTestResources {
100+
// Bring in the fully built corda.jar for use by NodeFactory in the smoke tests
101+
from(project(":node:capsule").tasks['buildCordaJAR']) {
102+
rename 'corda-(.*)', 'corda.jar'
103+
}
104+
from(project(':finance:workflows').tasks['jar']) {
105+
rename '.*finance-workflows-.*', 'cordapp-finance-workflows.jar'
106+
}
107+
from(project(':finance:contracts').tasks['jar']) {
108+
rename '.*finance-contracts-.*', 'cordapp-finance-contracts.jar'
109+
}
110+
from(project(':testing:cordapps:sleeping').tasks['jar']) {
111+
rename 'testing-sleeping-cordapp-*', 'cordapp-sleeping.jar'
70112
}
71-
implementation "com.google.guava:guava-testlib:$guava_version"
72113
}
73114

74-
task integrationTest(type: Test) {
115+
tasks.register('integrationTest', Test) {
75116
testClassesDirs = sourceSets.integrationTest.output.classesDirs
76117
classpath = sourceSets.integrationTest.runtimeClasspath
118+
}
77119

78-
jvmArgs test_add_opens
79-
jvmArgs test_add_exports
120+
tasks.register('smokeTest', Test) {
121+
testClassesDirs = sourceSets.smokeTest.output.classesDirs
122+
classpath = sourceSets.smokeTest.runtimeClasspath
80123
}
81124

82125
jar {

client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt

+2-11
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import org.junit.Test
5454
import rx.subjects.PublishSubject
5555
import java.net.URLClassLoader
5656
import java.nio.file.Paths
57-
import java.util.*
57+
import java.util.Currency
5858
import java.util.concurrent.CountDownLatch
5959
import java.util.concurrent.Executors
6060
import java.util.concurrent.ScheduledExecutorService
@@ -255,21 +255,12 @@ class CordaRPCClientTest : NodeBasedTest(FINANCE_CORDAPPS, notaries = listOf(DUM
255255
fun `additional class loader used by WireTransaction when it deserialises its components`() {
256256
val financeLocation = Cash::class.java.location.toPath().toString()
257257
val classPathWithoutFinance = ProcessUtilities.defaultClassPath.filter { financeLocation !in it }
258-
val moduleOpens = listOf(
259-
"--add-opens", "java.base/java.time=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED",
260-
"--add-opens", "java.base/java.util=ALL-UNNAMED", "--add-opens", "java.base/java.net=ALL-UNNAMED",
261-
"--add-opens", "java.base/java.nio=ALL-UNNAMED", "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED",
262-
"--add-opens", "java.base/java.security.cert=ALL-UNNAMED", "--add-opens", "java.base/javax.net.ssl=ALL-UNNAMED",
263-
"--add-opens", "java.base/java.util.concurrent=ALL-UNNAMED", "--add-opens", "java.sql/java.sql=ALL-UNNAMED",
264-
"--add-opens", "java.base/java.lang=ALL-UNNAMED"
265-
)
266258

267259
// Create a Cash.State object for the StandaloneCashRpcClient to get
268260
node.services.startFlow(CashIssueFlow(100.POUNDS, OpaqueBytes.of(1), identity), InvocationContext.shell()).flatMap { it.resultFuture }.getOrThrow()
269261
val outOfProcessRpc = ProcessUtilities.startJavaProcess<StandaloneCashRpcClient>(
270262
classPath = classPathWithoutFinance,
271-
arguments = listOf(node.node.configuration.rpcOptions.address.toString(), financeLocation),
272-
extraJvmArguments = moduleOpens
263+
arguments = listOf(node.node.configuration.rpcOptions.address.toString(), financeLocation)
273264
)
274265
assertThat(outOfProcessRpc.waitFor()).isZero() // i.e. no exceptions were thrown
275266
}

client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class RPCStabilityTests {
8989
}
9090

9191
@Test(timeout=300_000)
92-
@Ignore("TODO JDK17:Fixme")
9392
fun `client and server dont leak threads`() {
9493
fun startAndStop() {
9594
rpcDriver {
@@ -122,7 +121,6 @@ class RPCStabilityTests {
122121
}
123122

124123
@Test(timeout=300_000)
125-
@Ignore("TODO JDK17:Fixme")
126124
fun `client doesnt leak threads when it fails to start`() {
127125
fun startAndStop() {
128126
rpcDriver {
@@ -491,7 +489,6 @@ class RPCStabilityTests {
491489
* In this test we create a number of out of process RPC clients that call [TrackSubscriberOps.subscribe] in a loop.
492490
*/
493491
@Test(timeout=300_000)
494-
@Ignore("TODO JDK17:Fixme")
495492
fun `server cleans up queues after disconnected clients`() {
496493
rpcDriver {
497494
val trackSubscriberOpsImpl = object : TrackSubscriberOps {
@@ -547,7 +544,7 @@ class RPCStabilityTests {
547544
}
548545

549546
@Test(timeout=300_000)
550-
@Ignore // TODO: This is ignored because Artemis slow consumers are broken. I'm not deleting it in case we can get the feature fixed.
547+
@Ignore // TODO: This is ignored because Artemis slow consumers are broken. I'm not deleting it in case we can get the feature fixed.
551548
fun `slow consumers are kicked`() {
552549
rpcDriver {
553550
val server = startRpcServer(maxBufferedBytesPerClient = 10 * 1024 * 1024, ops = SlowConsumerRPCOpsImpl()).get()

testing/client-rpc/src/smoke-test/kotlin/net/corda/kotlin/rpc/StandaloneCordaRPClientTest.kt client/rpc/src/smoke-test/kotlin/net/corda/kotlin/rpc/StandaloneCordaRPClientTest.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import net.corda.nodeapi.internal.config.User
4040
import net.corda.sleeping.SleepingFlow
4141
import net.corda.smoketesting.NodeConfig
4242
import net.corda.smoketesting.NodeProcess
43-
import org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM
4443
import org.hamcrest.text.MatchesPattern
4544
import org.junit.After
4645
import org.junit.Before
@@ -50,6 +49,7 @@ import org.junit.Test
5049
import org.junit.rules.ExpectedException
5150
import java.io.FilterInputStream
5251
import java.io.InputStream
52+
import java.io.OutputStream.nullOutputStream
5353
import java.util.Currency
5454
import java.util.concurrent.CountDownLatch
5555
import java.util.concurrent.atomic.AtomicInteger
@@ -67,7 +67,7 @@ class StandaloneCordaRPClientTest {
6767
val rpcUser = User("rpcUser", "test", permissions = setOf("InvokeRpc.startFlow", "InvokeRpc.killFlow"))
6868
val flowUser = User("flowUser", "test", permissions = setOf("StartFlow.net.corda.finance.flows.CashIssueFlow"))
6969
val port = AtomicInteger(15200)
70-
const val attachmentSize = 2116
70+
const val ATTACHMENT_SIZE = 2116
7171
val timeout = 60.seconds
7272
}
7373

@@ -111,13 +111,13 @@ class StandaloneCordaRPClientTest {
111111

112112
@Test(timeout=300_000)
113113
fun `test attachments`() {
114-
val attachment = InputStreamAndHash.createInMemoryTestZip(attachmentSize, 1)
114+
val attachment = InputStreamAndHash.createInMemoryTestZip(ATTACHMENT_SIZE, 1)
115115
assertFalse(rpcProxy.attachmentExists(attachment.sha256))
116116
val id = attachment.inputStream.use { rpcProxy.uploadAttachment(it) }
117117
assertEquals(attachment.sha256, id, "Attachment has incorrect SHA256 hash")
118118

119-
val hash = HashingInputStream(Hashing.sha256(), rpcProxy.openAttachment(id)).use { it ->
120-
it.copyTo(NULL_OUTPUT_STREAM)
119+
val hash = HashingInputStream(Hashing.sha256(), rpcProxy.openAttachment(id)).use {
120+
it.copyTo(nullOutputStream())
121121
SecureHash.createSHA256(it.hash().asBytes())
122122
}
123123
assertEquals(attachment.sha256, hash)
@@ -126,13 +126,13 @@ class StandaloneCordaRPClientTest {
126126
@Ignore("CORDA-1520 - After switching from Kryo to AMQP this test won't work")
127127
@Test(timeout=300_000)
128128
fun `test wrapped attachments`() {
129-
val attachment = InputStreamAndHash.createInMemoryTestZip(attachmentSize, 1)
129+
val attachment = InputStreamAndHash.createInMemoryTestZip(ATTACHMENT_SIZE, 1)
130130
assertFalse(rpcProxy.attachmentExists(attachment.sha256))
131131
val id = WrapperStream(attachment.inputStream).use { rpcProxy.uploadAttachment(it) }
132132
assertEquals(attachment.sha256, id, "Attachment has incorrect SHA256 hash")
133133

134-
val hash = HashingInputStream(Hashing.sha256(), rpcProxy.openAttachment(id)).use { it ->
135-
it.copyTo(NULL_OUTPUT_STREAM)
134+
val hash = HashingInputStream(Hashing.sha256(), rpcProxy.openAttachment(id)).use {
135+
it.copyTo(nullOutputStream())
136136
SecureHash.createSHA256(it.hash().asBytes())
137137
}
138138
assertEquals(attachment.sha256, hash)

core-tests/build.gradle

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ dependencies {
107107
smokeTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
108108
smokeTestRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}"
109109
smokeTestRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"
110+
smokeTestRuntimeOnly "org.slf4j:slf4j-simple:$slf4j_version"
110111

111112
smokeTestCompile project(':smoke-test-utils')
112113
smokeTestCompile "org.assertj:assertj-core:${assertj_version}"
@@ -143,9 +144,6 @@ task smokeTest(type: Test) {
143144
dependsOn smokeTestJar
144145
testClassesDirs = sourceSets.smokeTest.output.classesDirs
145146
classpath = sourceSets.smokeTest.runtimeClasspath
146-
147-
jvmArgs test_add_opens
148-
jvmArgs test_add_exports
149147
}
150148

151149
idea {

core-tests/src/smoke-test/kotlin/net/corda/coretests/NodeVersioningTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class NodeVersioningTest {
4848
users = listOf(superUser)
4949
)
5050

51-
private lateinit var notary: NodeProcess
51+
private var notary: NodeProcess? = null
5252

5353
@Before
5454
fun setUp() {
@@ -57,7 +57,7 @@ class NodeVersioningTest {
5757

5858
@After
5959
fun done() {
60-
notary.close()
60+
notary?.close()
6161
}
6262

6363
@Test(timeout=300_000)

0 commit comments

Comments
 (0)