Post-review updates; added integration tests

This commit is contained in:
Chris Cochrane 2022-06-08 13:36:50 +01:00
parent b76fc7de59
commit 500be9cbcd
No known key found for this signature in database
GPG Key ID: 4D4602B5BBC63950
4 changed files with 84 additions and 7 deletions

View File

@ -0,0 +1,8 @@
package net.corda.nodeapi.internal
enum class NodeStatus {
WAITING_TO_START,
STARTING,
STARTED,
STOPPING
}

View File

@ -0,0 +1,45 @@
package net.corda.node.jmx
import com.fasterxml.jackson.databind.ObjectMapper
import net.corda.nodeapi.internal.NodeStatus
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.JmxPolicy
import net.corda.testing.driver.driver
import org.junit.Test
import java.net.HttpURLConnection
import java.net.HttpURLConnection.*
import java.net.URL
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class NodeStatus {
@Test(timeout=300_000)
fun `node status is published via JMX`() {
driver(DriverParameters(notarySpecs = emptyList(), jmxPolicy = JmxPolicy.defaultEnabled())) {
val jmxAddress = startNode().get().jmxAddress.toString()
val nodeStatusURL = URL("http://$jmxAddress/jolokia/read/net.corda:name=Status,type=Node")
var jmxInfo = ""
with(nodeStatusURL.openConnection() as HttpURLConnection) {
requestMethod = "GET"
inputStream.bufferedReader().use {
it.lines().forEach { line ->
jmxInfo += line
}
}
}
assertTrue {
jmxInfo.isNotEmpty()
}
val jsonTree = ObjectMapper().readTree(jmxInfo)
val httpStatus = jsonTree.get("status").asInt()
val nodeStatus = jsonTree.get("value").get("Value").asText()
assertEquals(httpStatus, HTTP_OK)
assertEquals(nodeStatus, NodeStatus.STARTED.toString())
}
}
}

View File

@ -0,0 +1,29 @@
package net.corda.node.jmx
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.JmxPolicy
import net.corda.testing.driver.driver
import org.junit.Test
import java.net.HttpURLConnection
import java.net.URL
import kotlin.test.assertTrue
class Publish {
@Test(timeout=300_000)
fun `node publishes node information via JMX when configured to do so`() {
driver(DriverParameters(notarySpecs = emptyList(), jmxPolicy = JmxPolicy.defaultEnabled())) {
val jmxAddress = startNode().get().jmxAddress.toString()
val nodeStatusURL = URL("http://$jmxAddress/jolokia/read/net.corda:*")
var httpResponse = HttpURLConnection.HTTP_NOT_FOUND
with(nodeStatusURL.openConnection() as HttpURLConnection) {
requestMethod = "GET"
httpResponse = responseCode
}
assertTrue {
httpResponse == HttpURLConnection.HTTP_OK
}
}
}
}

View File

@ -147,6 +147,7 @@ import net.corda.node.utilities.BindableNamedCacheFactory
import net.corda.node.utilities.NamedThreadFactory
import net.corda.node.utilities.NotaryLoader
import net.corda.nodeapi.internal.NodeInfoAndSigned
import net.corda.nodeapi.internal.NodeStatus
import net.corda.nodeapi.internal.SignedNodeInfo
import net.corda.nodeapi.internal.cordapp.CordappLoader
import net.corda.nodeapi.internal.cryptoservice.CryptoService
@ -384,13 +385,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
protected val keyStoreHandler = KeyStoreHandler(configuration, cryptoService)
enum class NodeStatus {
WAITING_TO_START,
STARTING,
STARTED,
STOPPING
}
@Volatile
private var nodeStatus = NodeStatus.WAITING_TO_START
private fun <T : Any> T.tokenize(): T {