Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
809 views
in Technique[技术] by (71.8m points)

karate - Error using DBUtils in first scenario

When I use DBUtils.java in Eclipse and run the tests there it works fine, but when I run it through Jenkins the first time that DBUtils are used is failing. And the second works... The first time that it uses db.readRows it fails.

    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 }

Error:

   * 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
question from:https://stackoverflow.com/questions/65941623/whats-the-best-way-to-handle-database-records-with-date-type-fields

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First may I gently remind you that DBUtils.java was created as a demo example and is not part of the core of Karate. I am beginning to regret having put this there because of questions like this. See another example.

EDIT - Since this question comes up a lot: You are expected to write your own code to connect to your database, execute SQL and unpack the results the way you want. Please don't tag questions around this as "karate".

Anyway, please work with somebody in your team or org to fix this problem:

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: 
Could not get JDBC Connection; nested exception is
java.sql.SQLRecoverableException: IO Error: Connection reset

It is quite possible that your Jenkins box is not able to establish a connection to the database and the ports are fire-walled off etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...