mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Behave: use existing Core common utility functions for Logger creation and Ti… (#2990)
* Use existing Core common utility functions for Logger creation and Time durations. * Updated JUnit tests.
This commit is contained in:
parent
7ad19af93f
commit
5dc71fc350
@ -5,7 +5,6 @@ import net.corda.core.internal.uncheckedCast
|
|||||||
import net.corda.core.serialization.CordaSerializable
|
import net.corda.core.serialization.CordaSerializable
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import rx.Observable
|
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.concurrent.ExecutionException
|
import java.util.concurrent.ExecutionException
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
|
@ -3,26 +3,6 @@ package net.corda.behave
|
|||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
|
|
||||||
// TODO Most of these are available in corda core
|
|
||||||
|
|
||||||
val Int.millisecond: Duration
|
|
||||||
get() = Duration.ofMillis(this.toLong())
|
|
||||||
|
|
||||||
val Int.milliseconds: Duration
|
|
||||||
get() = Duration.ofMillis(this.toLong())
|
|
||||||
|
|
||||||
val Int.second: Duration
|
|
||||||
get() = Duration.ofSeconds(this.toLong())
|
|
||||||
|
|
||||||
val Int.seconds: Duration
|
|
||||||
get() = Duration.ofSeconds(this.toLong())
|
|
||||||
|
|
||||||
val Int.minute: Duration
|
|
||||||
get() = Duration.ofMinutes(this.toLong())
|
|
||||||
|
|
||||||
val Int.minutes: Duration
|
|
||||||
get() = Duration.ofMinutes(this.toLong())
|
|
||||||
|
|
||||||
fun CountDownLatch.await(duration: Duration) =
|
fun CountDownLatch.await(duration: Duration) =
|
||||||
this.await(duration.toMillis(), java.util.concurrent.TimeUnit.MILLISECONDS)
|
this.await(duration.toMillis(), java.util.concurrent.TimeUnit.MILLISECONDS)
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package net.corda.behave.logging
|
|
||||||
|
|
||||||
import org.slf4j.Logger
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
|
|
||||||
// TODO Already available in corda core
|
|
||||||
|
|
||||||
inline fun <reified T> getLogger(): Logger =
|
|
||||||
LoggerFactory.getLogger(T::class.java)
|
|
@ -1,7 +1,7 @@
|
|||||||
package net.corda.behave.monitoring
|
package net.corda.behave.monitoring
|
||||||
|
|
||||||
import net.corda.behave.await
|
import net.corda.behave.await
|
||||||
import net.corda.behave.seconds
|
import net.corda.core.utilities.seconds
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
|
@ -4,14 +4,14 @@ import net.corda.behave.database.DatabaseType
|
|||||||
import net.corda.behave.file.LogSource
|
import net.corda.behave.file.LogSource
|
||||||
import net.corda.behave.file.currentDirectory
|
import net.corda.behave.file.currentDirectory
|
||||||
import net.corda.behave.file.stagingRoot
|
import net.corda.behave.file.stagingRoot
|
||||||
import net.corda.behave.logging.getLogger
|
|
||||||
import net.corda.behave.minutes
|
|
||||||
import net.corda.behave.node.Distribution
|
import net.corda.behave.node.Distribution
|
||||||
import net.corda.behave.node.Node
|
import net.corda.behave.node.Node
|
||||||
import net.corda.behave.node.configuration.NotaryType
|
import net.corda.behave.node.configuration.NotaryType
|
||||||
import net.corda.behave.process.JarCommand
|
import net.corda.behave.process.JarCommand
|
||||||
import net.corda.core.CordaException
|
import net.corda.core.CordaException
|
||||||
import net.corda.core.internal.*
|
import net.corda.core.internal.*
|
||||||
|
import net.corda.core.utilities.contextLogger
|
||||||
|
import net.corda.core.utilities.minutes
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
@ -285,7 +285,7 @@ class Network private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val log = getLogger<Network>()
|
val log = contextLogger()
|
||||||
const val CLEANUP_ON_ERROR = false
|
const val CLEANUP_ON_ERROR = false
|
||||||
|
|
||||||
fun new(timeout: Duration = 2.minutes
|
fun new(timeout: Duration = 2.minutes
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package net.corda.behave.node
|
package net.corda.behave.node
|
||||||
|
|
||||||
import net.corda.behave.file.stagingRoot
|
import net.corda.behave.file.stagingRoot
|
||||||
import net.corda.behave.logging.getLogger
|
|
||||||
import net.corda.behave.service.Service
|
|
||||||
import net.corda.core.internal.copyTo
|
import net.corda.core.internal.copyTo
|
||||||
import net.corda.core.internal.createDirectories
|
import net.corda.core.internal.createDirectories
|
||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.internal.exists
|
import net.corda.core.internal.exists
|
||||||
|
import net.corda.core.utilities.contextLogger
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
@ -82,7 +81,7 @@ class Distribution private constructor(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
protected val log = getLogger<Service>()
|
private val log = contextLogger()
|
||||||
|
|
||||||
private val distributions = mutableListOf<Distribution>()
|
private val distributions = mutableListOf<Distribution>()
|
||||||
|
|
||||||
|
@ -5,11 +5,9 @@ import net.corda.behave.database.DatabaseType
|
|||||||
import net.corda.behave.file.LogSource
|
import net.corda.behave.file.LogSource
|
||||||
import net.corda.behave.file.currentDirectory
|
import net.corda.behave.file.currentDirectory
|
||||||
import net.corda.behave.file.stagingRoot
|
import net.corda.behave.file.stagingRoot
|
||||||
import net.corda.behave.logging.getLogger
|
|
||||||
import net.corda.behave.monitoring.PatternWatch
|
import net.corda.behave.monitoring.PatternWatch
|
||||||
import net.corda.behave.node.configuration.*
|
import net.corda.behave.node.configuration.*
|
||||||
import net.corda.behave.process.JarCommand
|
import net.corda.behave.process.JarCommand
|
||||||
import net.corda.behave.seconds
|
|
||||||
import net.corda.behave.service.Service
|
import net.corda.behave.service.Service
|
||||||
import net.corda.behave.service.ServiceSettings
|
import net.corda.behave.service.ServiceSettings
|
||||||
import net.corda.behave.ssh.MonitoringSSHClient
|
import net.corda.behave.ssh.MonitoringSSHClient
|
||||||
@ -20,6 +18,8 @@ import net.corda.core.internal.div
|
|||||||
import net.corda.core.internal.exists
|
import net.corda.core.internal.exists
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
|
import net.corda.core.utilities.loggerFor
|
||||||
|
import net.corda.core.utilities.seconds
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
@ -35,7 +35,7 @@ class Node(
|
|||||||
private val settings: ServiceSettings = ServiceSettings()
|
private val settings: ServiceSettings = ServiceSettings()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val log = getLogger<Node>()
|
private val log = loggerFor<Node>()
|
||||||
|
|
||||||
private val runtimeDirectory = rootDirectory / config.name
|
private val runtimeDirectory = rootDirectory / config.name
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.corda.behave.node.configuration
|
package net.corda.behave.node.configuration
|
||||||
|
|
||||||
import net.corda.behave.database.DatabaseType
|
import net.corda.behave.database.DatabaseType
|
||||||
import net.corda.behave.logging.getLogger
|
|
||||||
import net.corda.behave.node.Distribution
|
import net.corda.behave.node.Distribution
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
import net.corda.core.internal.writeText
|
import net.corda.core.internal.writeText
|
||||||
|
import net.corda.core.utilities.contextLogger
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
class Configuration(
|
class Configuration(
|
||||||
@ -53,7 +53,7 @@ class Configuration(
|
|||||||
.joinToString("\n")
|
.joinToString("\n")
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val log = getLogger<Configuration>()
|
private val log = contextLogger()
|
||||||
const val DEFAULT_PASSWORD = "S0meS3cretW0rd"
|
const val DEFAULT_PASSWORD = "S0meS3cretW0rd"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package net.corda.behave.process
|
package net.corda.behave.process
|
||||||
|
|
||||||
import net.corda.behave.*
|
import net.corda.behave.await
|
||||||
import net.corda.behave.file.currentDirectory
|
import net.corda.behave.file.currentDirectory
|
||||||
import net.corda.behave.logging.getLogger
|
|
||||||
import net.corda.behave.process.output.OutputListener
|
import net.corda.behave.process.output.OutputListener
|
||||||
|
import net.corda.behave.waitFor
|
||||||
|
import net.corda.core.utilities.loggerFor
|
||||||
|
import net.corda.core.utilities.minutes
|
||||||
|
import net.corda.core.utilities.seconds
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscriber
|
import rx.Subscriber
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
@ -18,7 +21,7 @@ open class Command(
|
|||||||
private val timeout: Duration = 2.minutes
|
private val timeout: Duration = 2.minutes
|
||||||
): Closeable {
|
): Closeable {
|
||||||
|
|
||||||
protected val log = getLogger<Command>()
|
protected val log = loggerFor<Command>()
|
||||||
|
|
||||||
private val terminationLatch = CountDownLatch(1)
|
private val terminationLatch = CountDownLatch(1)
|
||||||
|
|
||||||
@ -74,7 +77,7 @@ open class Command(
|
|||||||
}).start()
|
}).start()
|
||||||
val streamIsClosed = outputCapturedLatch.await(timeout)
|
val streamIsClosed = outputCapturedLatch.await(timeout)
|
||||||
val timeout = if (!streamIsClosed || isInterrupted) {
|
val timeout = if (!streamIsClosed || isInterrupted) {
|
||||||
1.second
|
1.seconds
|
||||||
} else {
|
} else {
|
||||||
timeout
|
timeout
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.corda.behave.service
|
package net.corda.behave.service
|
||||||
|
|
||||||
import net.corda.behave.logging.getLogger
|
import net.corda.core.utilities.loggerFor
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
|
|
||||||
abstract class Service(
|
abstract class Service(
|
||||||
@ -11,7 +11,7 @@ abstract class Service(
|
|||||||
|
|
||||||
private var isRunning: Boolean = false
|
private var isRunning: Boolean = false
|
||||||
|
|
||||||
protected val log = getLogger<Service>()
|
protected val log = loggerFor<Service>()
|
||||||
|
|
||||||
fun start(): Boolean {
|
fun start(): Boolean {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package net.corda.behave.service
|
package net.corda.behave.service
|
||||||
|
|
||||||
import net.corda.behave.minute
|
import net.corda.core.utilities.minutes
|
||||||
import net.corda.behave.second
|
import net.corda.core.utilities.seconds
|
||||||
import net.corda.behave.seconds
|
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
|
|
||||||
data class ServiceSettings(
|
data class ServiceSettings(
|
||||||
val timeout: Duration = 1.minute,
|
val timeout: Duration = 1.minutes,
|
||||||
val startupDelay: Duration = 1.second,
|
val startupDelay: Duration = 1.seconds,
|
||||||
val startupTimeout: Duration = 15.seconds,
|
val startupTimeout: Duration = 15.seconds,
|
||||||
val pollInterval: Duration = 1.second
|
val pollInterval: Duration = 1.seconds
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.corda.behave.ssh
|
package net.corda.behave.ssh
|
||||||
|
|
||||||
import net.corda.behave.logging.getLogger
|
import net.corda.core.utilities.contextLogger
|
||||||
import org.apache.sshd.client.SshClient
|
import org.apache.sshd.client.SshClient
|
||||||
import org.apache.sshd.client.channel.ChannelShell
|
import org.apache.sshd.client.channel.ChannelShell
|
||||||
import org.apache.sshd.client.session.ClientSession
|
import org.apache.sshd.client.session.ClientSession
|
||||||
@ -96,7 +96,7 @@ open class SSHClient private constructor(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val log = getLogger<SSHClient>()
|
private val log = contextLogger()
|
||||||
|
|
||||||
fun connect(
|
fun connect(
|
||||||
port: Int,
|
port: Int,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.corda.behave.monitoring
|
package net.corda.behave.monitoring
|
||||||
|
|
||||||
import net.corda.behave.second
|
import net.corda.core.utilities.seconds
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
@ -10,14 +10,14 @@ class MonitoringTests {
|
|||||||
@Test
|
@Test
|
||||||
fun `watch gets triggered when pattern is observed`() {
|
fun `watch gets triggered when pattern is observed`() {
|
||||||
val observable = Observable.just("first", "second", "third")
|
val observable = Observable.just("first", "second", "third")
|
||||||
val result = PatternWatch(observable, "c.n").await(1.second)
|
val result = PatternWatch(observable, "c.n").await(1.seconds)
|
||||||
assertThat(result).isTrue()
|
assertThat(result).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `watch does not get triggered when pattern is not observed`() {
|
fun `watch does not get triggered when pattern is not observed`() {
|
||||||
val observable = Observable.just("first", "second", "third")
|
val observable = Observable.just("first", "second", "third")
|
||||||
val result = PatternWatch(observable, "forth").await(1.second)
|
val result = PatternWatch(observable, "forth").await(1.seconds)
|
||||||
assertThat(result).isFalse()
|
assertThat(result).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ class MonitoringTests {
|
|||||||
val watch2 = PatternWatch(observable, "ond")
|
val watch2 = PatternWatch(observable, "ond")
|
||||||
val watch3 = PatternWatch(observable, "ird")
|
val watch3 = PatternWatch(observable, "ird")
|
||||||
val aggregate = watch1 * watch2 * watch3
|
val aggregate = watch1 * watch2 * watch3
|
||||||
assertThat(aggregate.await(1.second)).isTrue()
|
assertThat(aggregate.await(1.seconds)).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -38,7 +38,7 @@ class MonitoringTests {
|
|||||||
val watch2 = PatternWatch(observable, "ond")
|
val watch2 = PatternWatch(observable, "ond")
|
||||||
val watch3 = PatternWatch(observable, "baz")
|
val watch3 = PatternWatch(observable, "baz")
|
||||||
val aggregate = watch1 * watch2 * watch3
|
val aggregate = watch1 * watch2 * watch3
|
||||||
assertThat(aggregate.await(1.second)).isFalse()
|
assertThat(aggregate.await(1.seconds)).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -48,7 +48,7 @@ class MonitoringTests {
|
|||||||
val watch2 = PatternWatch(observable, "ond")
|
val watch2 = PatternWatch(observable, "ond")
|
||||||
val watch3 = PatternWatch(observable, "bar")
|
val watch3 = PatternWatch(observable, "bar")
|
||||||
val aggregate = watch1 / watch2 / watch3
|
val aggregate = watch1 / watch2 / watch3
|
||||||
assertThat(aggregate.await(1.second)).isTrue()
|
assertThat(aggregate.await(1.seconds)).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -58,7 +58,7 @@ class MonitoringTests {
|
|||||||
val watch2 = PatternWatch(observable, "baz")
|
val watch2 = PatternWatch(observable, "baz")
|
||||||
val watch3 = PatternWatch(observable, "bar")
|
val watch3 = PatternWatch(observable, "bar")
|
||||||
val aggregate = watch1 / watch2 / watch3
|
val aggregate = watch1 / watch2 / watch3
|
||||||
assertThat(aggregate.await(1.second)).isFalse()
|
assertThat(aggregate.await(1.seconds)).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ package net.corda.behave.network
|
|||||||
|
|
||||||
import net.corda.behave.database.DatabaseType
|
import net.corda.behave.database.DatabaseType
|
||||||
import net.corda.behave.node.configuration.NotaryType
|
import net.corda.behave.node.configuration.NotaryType
|
||||||
import net.corda.behave.seconds
|
import net.corda.core.utilities.seconds
|
||||||
import org.junit.Ignore
|
import org.junit.Ignore
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user