你好,新年快乐
我正在使用Vert.x& Scala上的API应用程序。我正在使用此page中的代码示例来创建第一个基本API应用程序。
我的问题是,我在同一地址上进行了两次测试。端口,但不在同一条路线上,但只运行一个。另一方面,IDE返回
VerticleSpec *** ABORTED ***
[info] java.net.BindException: Address already in use
[info] at sun.nio.ch.Net.bind0(Native Method)
[info] at sun.nio.ch.Net.bind(Net.java:433)
[info] at sun.nio.ch.Net.bind(Net.java:425)
[info] at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
[info] at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:128)
[info] at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558)
[info] at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1283)
[info] at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)
[info] at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)
[info] at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:989)
那么,我怎样才能让我的所有测试都在运行?
EDIT Under是来自官方回购的一个文件。它部署和取消部署API的路由。那么,这意味着应该在一次测试后释放端口,对吧?
import io.vertx.lang.scala.json.{Json, JsonObject}
import io.vertx.lang.scala.{ScalaVerticle, VertxExecutionContext}
import io.vertx.scala.core.{DeploymentOptions, Vertx}
import org.scalatest.{AsyncFlatSpec, BeforeAndAfter}
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.reflect.runtime.universe._
import scala.util.{Failure, Success}
abstract class VerticleTesting[A <: ScalaVerticle: TypeTag] extends AsyncFlatSpec with BeforeAndAfter{
val vertx = Vertx.vertx
implicit val vertxExecutionContext = VertxExecutionContext(
vertx.getOrCreateContext()
)
private var deploymentId = ""
def config(): JsonObject = Json.emptyObj()
before {
deploymentId = Await.result(
vertx
.deployVerticleFuture("scala:" + implicitly[TypeTag[A]].tpe.typeSymbol.fullName,
DeploymentOptions().setConfig(config()))
.andThen {
case Success(d) => d
case Failure(t) => throw new RuntimeException(t)
},
10000 millis
)
}
after {
Await.result(
vertx.undeployFuture(deploymentId)
.andThen {
case Success(d) => d
case Failure(t) => throw new RuntimeException(t)
},
10000 millis
)
}
}
答案 0 :(得分:1)
好吧,我发现它是怎么做的。
在build.sbt中,我刚添加了这一行,它运行良好
parallelExecution in Test := false
所以,如果有人遇到这个问题,可能会有所帮助:)