1

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

1 Answers1

1

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.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Hi Peter. I'm not blaming DBUtil, because is working very well. What I don't know is why it is not able to connect in the first time using Jenkins. First scenario it is shows that error, but works in the second on – Carol Castro Aug 29 '18 at 15:15
  • @CarolCastro and I have tried to provide an answer. maybe someone else can provide a better one, but I doubt it. – Peter Thomas Aug 29 '18 at 15:16
  • 1
    I could fix doing it: Solution 2 - General Java JVM solution Take a look at $JAVA_HOME/jre/lib/security/java.security Change the line securerandom.source=file:/dev/random to securerandom.source=file:/dev/urandom https://stackoverflow.com/questions/6110395/sqlrecoverableexception-i-o-exception-connection-reset – Carol Castro Aug 30 '18 at 14:30