gpt4 book ai didi

java - 运行 sbt 测试套件两次会导致 jdbc 驱动程序未找到错误

转载 作者:行者123 更新时间:2023-12-02 04:26:48 26 4
gpt4 key购买 nike

我第一次运行依赖于 jdbc sql lite 驱动程序的测试套件时,测试套件通过了。如果我尝试再次运行测试套件,测试将失败,因为找不到适合数据库的驱动程序。这是控制台 session :

> > test-only *EclairTest*
15:56:27.386 TKD [EclairTest-akka.actor.default-dispatcher-14] ERROR a.h.i.engine.client.PoolMasterActor - connection pool for PoolGateway(hcps = HostConnectionPoolSetup(localhost,18332,ConnectionPoolSetup(ConnectionPoolSettings(4,0,5,32,1,30 seconds,ClientConnectionSettings(Some(User-Agent: akka-http/10.1.1),10 seconds,1 minute,512,None,WebSocketSettings(<function0>,ping,Duration.Inf,<function0>),List(),ParserSettings(2048,16,64,64,8192,64,8388608,256,1048576,Strict,RFC6265,true,Full,Error,Map(If-Range -> 0, If-Modified-Since -> 0, If-Unmodified-Since -> 0, default -> 12, Content-MD5 -> 0, Date -> 0, If-Match -> 0, If-None-Match -> 0, User-Agent -> 32),false,true,<function1>,<function1>,<function2>),None,TCPTransport),New,1 second),akka.http.scaladsl.HttpConnectionContext$@5fb80e0c,akka.event.MarkerLoggingAdapter@7da2ada2))) has shut down unexpectedly
[ERROR] [06/13/2018 15:56:27.404] [EclairTest-akka.actor.default-dispatcher-4] [akka.actor.ActorSystemImpl(EclairTest)] exception while executing timer task
[info] EclairTest:
[info] EclairTest
[info] - should connect to a running eclair instance
[info] ScalaTest
[info] Run completed in 3 seconds, 2 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[success] Total time: 5 s, completed Jun 13, 2018 3:56:27 PM

> test-only *EclairTest*
[info] EclairTest:
[info] com.suredbits.api.ln.EclairTest *** ABORTED ***
[info] java.sql.SQLException: No suitable driver found for jdbc:sqlite:/home/chris/.eclair/regtest/eclair.sqlite
[info] at java.sql.DriverManager.getConnection(DriverManager.java:689)
[info] at java.sql.DriverManager.getConnection(DriverManager.java:270)
[info] at fr.acinq.eclair.NodeParams$.makeNodeParams(NodeParams.scala:136)
[info] at fr.acinq.eclair.Setup.<init>(Setup.scala:71)
[info] at com.suredbits.api.ln.EclairTest.<init>(EclairTest.scala:20)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[info] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[info] at java.lang.Class.newInstance(Class.java:442)
[info] ...
[info] ScalaTest
[info] Run completed in 589 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 1
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] *** 1 SUITE ABORTED ***
[error] Error: Total 1, Failed 0, Errors 1, Passed 0
[error] Error during tests:
[error] com.suredbits.api.ln.EclairTest
[error] (api/test:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 1 s, completed Jun 13, 2018 3:56:31 PM

这对我来说似乎很奇怪。您认为什么可能导致此问题?如果我关闭 sbt 并重新启动,我会看到相同的行为。

<小时/>

测试如下所示:

class EclairTest extends TestKit(ActorSystem("EclairTest")) with FlatSpecLike with BeforeAndAfterAll {

implicit val dispatcher = system.dispatcher

behavior of "EclairTest"

//assumes eclair is running
val datadir = new File("/home/chris/.eclair")
val setup = new Setup(
datadir = datadir,
actorSystem = system
)
val params = setup.nodeParams
val kitF: Future[Kit] = setup.bootstrap

it should "connect to a running eclair instance" in {
val balance: Future[fr.acinq.bitcoin.Satoshi] = kitF.flatMap(_.wallet.getBalance)
balance.map(b => assert(b.toLong >= 0))
}

override def afterAll: Unit = {
TestKit.shutdownActorSystem(system)
}
}

并且该依赖项被捆绑到另一个依赖项中,但我还使用

显式包含了 sqlite
val hikari = ("com.typesafe.slick" %% "slick-hikaricp" % V.slickV).exclude("org.slf4j","slf4j-api")
val slick = "com.typesafe.slick" %% "slick" % V.slickV withSources() withJavadoc()
val dbcp = "commons-dbcp" % "commons-dbcp" % "1.4"
val postgresql = "org.postgresql" % "postgresql" % "9.4.1210"
val sqlite = "org.xerial" % "sqlite-jdbc" % V.sqliteV

lazy val api = project
.in(file("."))
.enablePlugins()
.settings(
mainClass := Some("com.suredbits.api.Main"),
fork in test := true,
resolvers += Resolver.sonatypeRepo("releases"),
resolvers += Resolver.mavenLocal,
libraryDependencies ++= Deps.api
)
<小时/>

开源项目以及开源项目的pom.xml文件定义在这里:https://github.com/ACINQ/eclair/blob/master/eclair-core/pom.xml#L175-L179

最佳答案

看起来 Setup.bootstrap 方法声明了 Eclair 库中的数据库,依赖于 JVM 退出来清理-在它之后,并且似乎没有提供允许您在测试结束时手动执行此操作的机制。 (如果有这样的机制,使用它也能达到目的。)

默认情况下,测试在 SBT 构建实例运行的同一个 JVM 中运行,因此,当您在第一次运行测试时声明的资源仍然存在。第二次运行测试。除此之外,在第二次及后续运行中,他们无法声明数据库资源,因为它们已经被声明了。

通过添加:

fork in Test := true

对于您的SBT构建,您将强制每个测试实例在其自己的JVM实例中运行,因此它每次都可以重新启动。

关于java - 运行 sbt 测试套件两次会导致 jdbc 驱动程序未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50846188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com