每个测试套件中的第一个测试连接到DB失败



我们运行了超过2000个junit,大多数测试通过jdbc调用连接到Oracle数据库。由于某些原因,很少有测试无法连接到DB。下面是一些背景信息:

  • 我们正在CI服务器中运行测试—Jenkins
  • ANT正在使用<junit>任务和fork="true"运行测试
  • 只有少数测试失败,Could not connect to database错误,不一致,有时失败,有时不。
  • 失败的测试通常是每个测试套件中的第一个测试
  • 其他也连接到数据库的测试不会失败。

到目前为止,我们还没有解决它的运气。有人遇到类似的情况吗?

下面是堆栈跟踪:

Error Message
Could not connect to database using the connect string jdbc:oracle:thin:R71/R71@abc.def:1521:DB11g
Stacktrace
java.lang.RuntimeException: Could not connect to database using the connect string jdbc:oracle:thin:R71/R71@abc.def:1521:DB11g
    at com.abc.common.dao.JDBCUtils.getThinConnection(JDBCUtils.java:257)
    at com.abc.common.dao.JDBCUtils.getConnection(JDBCUtils.java:115)
    at com.abc.common.dao.JDBCUtils.queryForInt(JDBCUtils.java:714)
    at com.abc.test.utils.MetaDataLanguageDBTest.testMetaDataLanguages(MetaDataLanguageDBTest.java:13)
Caused by: java.sql.SQLRecoverableException: IO Error: Connection reset
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:428)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:207)
    at com.abc.common.dao.JDBCUtils.getThinConnection(JDBCUtils.java:254)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at oracle.net.ns.DataPacket.send(DataPacket.java:199)
    at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:211)
    at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:227)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:175)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:100)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:85)
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123)
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1122)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1099)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:288)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
    at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:366)
    at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:752)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:366)
Standard Error
java.sql.SQLRecoverableException: IO Error: Connection reset
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:428)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:207)
    at com.abc.common.dao.JDBCUtils.getThinConnection(JDBCUtils.java:254)
    at com.abc.common.dao.JDBCUtils.getConnection(JDBCUtils.java:115)
    at com.abc.common.dao.JDBCUtils.queryForInt(JDBCUtils.java:714)
    at com.abc.test.utils.MetaDataLanguageDBTest.testMetaDataLanguages(MetaDataLanguageDBTest.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:421)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:912)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:766)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at oracle.net.ns.DataPacket.send(DataPacket.java:199)
    at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:211)
    at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:227)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:175)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:100)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:85)
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123)
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1122)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1099)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:288)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
    at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:366)
    at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:752)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:366)
    ... 25 more

谢谢。

我知道这个问题很老了,但我刚刚遇到了同样的问题。我的解决方案是在我的测试中添加以下环境变量:

-Djava.security.egd=file:///dev/urandom

简而言之,Oracle JDBC驱动程序默认使用/dev/random,如果系统上没有足够的熵,它可以阻塞。

可能是您的连接即将耗尽。我会尝试使用由连接池支持的数据源。

相关内容

  • 没有找到相关文章

最新更新