当我在Eclipse中使用DBUtils.java并在其中运行测试时,它可以正常工作,但是当我通过Jenkins运行它时,第一次使用DBUtils失败。第二个作品... 第一次使用db.readRows失败。
Scenario: Account Create
Given path 'accounts'
And header Authorization = setup.authorization
And request {identifier: KarateCreation, subscribers:[{identifier:KarateCreation, firstName:KarateCreation, lastName:KarateCreation}]}
When method POST
And match response contains { id: '#number', identifier: KarateCreation }
Then status 201
* def id = response.id
* def accountNumber = response.identifier
# use jdbc to validate
* def config = { url: #(dbConnectionString), driverClassName: 'oracle.jdbc.OracleDriver' }
* def DbUtils = Java.type('restapi.util.DbUtils')
* def db = new DbUtils(config)
* def rs = db.readRows("SELECT ACCOUNTID, ACCOUNTNUMBER FROM ACCOUNT WHERE ACCOUNTNUMBER = 'KarateCreation'")
* match rs contains { ACCOUNTID: '#(id)', ACCOUNTNUMBER: KarateCreation }
错误:
* def rs = db.readRows("SELECT ACCOUNTID, ACCOUNTNUMBER FROM ACCOUNT WHERE ACCOUNTNUMBER = 'KarateCreation'")(Scenario: Account Create) Time elapsed: 0.039 sec <<< ERROR!
java.lang.RuntimeException: javascript evaluation failed: db.readRows("SELECT ACCOUNTID, ACCOUNTNUMBER FROM ACCOUNT WHERE ACCOUNTNUMBER = 'KarateCreation'")
at com.intuit.karate.ScriptBindings.eval(ScriptBindings.java:115)
at com.intuit.karate.ScriptBindings.updateBindingsAndEval(ScriptBindings.java:103)
at com.intuit.karate.ScriptBindings.evalInNashorn(ScriptBindings.java:88)
at com.intuit.karate.Script.evalJsExpression(Script.java:362)
at com.intuit.karate.Script.evalKarateExpression(Script.java:284)
at com.intuit.karate.Script.evalKarateExpression(Script.java:170)
at com.intuit.karate.Script.assign(Script.java:598)
at com.intuit.karate.Script.assign(Script.java:524)
at com.intuit.karate.StepDefs.def(StepDefs.java:305)
at ✽.* def rs = db.readRows("SELECT ACCOUNTID, ACCOUNTNUMBER FROM ACCOUNT WHERE ACCOUNTNUMBER = 'KarateCreation'")(restapi/accounts/accounts.feature:31)
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLRecoverableException: IO Error: Connection reset
答案 0 :(得分:1)
首先,我想提醒您,DBUtils.java
是作为演示示例创建的,它不是空手道核心的一部分。由于诸如此类的问题,我对此感到遗憾。参见another example。
无论如何,请与您的团队或组织中的某人一起解决此问题:
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException:
Could not get JDBC Connection; nested exception is
java.sql.SQLRecoverableException: IO Error: Connection reset
您的Jenkins机器很可能无法建立与数据库的连接,并且端口被防火墙隔离等。