关闭钩子Corda集成测试
我有以下几点。它启动Jetty服务器关闭钩子Corda集成测试,corda,Corda,我有以下几点。它启动Jetty服务器 @CordaService class IOUService(private val serviceHub: AppServiceHub): SingletonSerializeAsToken() { init { val port = serviceHub.myInfo.addresses.first().port - 1002 log.println("IOUService init was called..."
@CordaService
class IOUService(private val serviceHub: AppServiceHub): SingletonSerializeAsToken() {
init {
val port = serviceHub.myInfo.addresses.first().port - 1002
log.println("IOUService init was called...")
log.println("Port: $port")
val jettyServer = JettyServer()
jettyServer.start(port)
}
}
我的问题是如何在运行集成测试时释放Jetty端口。下面是两个示例测试(基本上相同的测试两次以说明问题):
第一个测试将启动3个节点:一个公证人、BankA和BankB节点,详细信息如下:
Notary:
Advertised P2P messaging addresses : localhost:10000
RPC connection address : localhost:10001
RPC admin connection address : localhost:10002
Jetty Port: 8998
BankA:
Advertised P2P messaging addresses : localhost:10004
RPC connection address : localhost:10005
RPC admin connection address : localhost:10006
Jetty Port: 9002
BankB:
Advertised P2P messaging addresses : localhost:10008
RPC connection address : localhost:10009
RPC admin connection address : localhost:10010
Jetty Port: 9006
不幸的是,第二次测试将失败,因为码头端口仍然处于绑定状态:
[ERROR] 14:22:04,825 [driver-pool-thread-0] internal.Node.installCordaServices - Corda service com.example.flows.IOUService failed to instantiate. Reason was: Address already in use [errorCode=1pryyp4, moreInformationAt=https://errors.corda.net/OS/4.1/1pryyp4]
java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:9006
如何在集成测试期间注册关闭挂钩,以便关闭Jetty服务器
示例代码可在此处找到:
目前正在研究corda服务的适当生命周期。希望你将来能做到这一点 目前,没有一种简单的方法可以从节点内部实现这一点
[ERROR] 14:22:04,825 [driver-pool-thread-0] internal.Node.installCordaServices - Corda service com.example.flows.IOUService failed to instantiate. Reason was: Address already in use [errorCode=1pryyp4, moreInformationAt=https://errors.corda.net/OS/4.1/1pryyp4]
java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:9006