Karate API -> Database Validation -> Matching one value returned in an object from database [duplicate] - karate

This question already has an answer here:
Karate - Database testing - getting timestamp displayed as nano
(1 answer)
Closed 1 year ago.
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

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.

Related

Database timeout in Azure SQL

We have a .Net Core API accessing Azure SQL (Gen5, 4 vCores)
Since quite some time,
the API keeps throwing below exception for a specific READ operation
Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout
Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
The READ operation has code to read rows of data and convert an XML column into a specific output format.
Most of the read operation extracts hardly 4-5 rows # a time.
The tables involved in the query have ~ 500,000 rows
We are clueless on Root Cause of this issue.
Any hints on where to start looking # for root cause?
Any pointer would be highly appreciated.
NOTE : Connection string has following settings, apart from others
MultipleActiveResultSets=True;Connection Timeout=60
Overall code looks something like this.
HINT: The above timeout exception comes # ConvertHistory, when the 2nd table is being read.
HttpGet]
public async Task<IEnumerable<SalesOrders>> GetNewSalesOrders()
{
var SalesOrders = await _db.SalesOrders.Where(o => o.IsImported == false).OrderBy(o => o.ID).ToListAsync();
var orders = new List<SalesOrder>();
foreach (var so in SalesOrders)
{
var order = ConvertSalesOrder(so);
orders.Add(order);
}
return orders;
}
private SalesOrder ConvertSalesOrder(SalesOrder o)
{
var newOrder = new SalesOrder();
var oXml = o.XMLContent.LoadFromXMLString<SalesOrder>();
...
newOrder.BusinessUnit = oXml.BusinessUnit;
var history = ConvertHistory(o.ID);
newOrder.history = history;
return newOrder;
}
private SalesOrderHistory[] ConvertHistory(string id)
{
var history = _db.OrderHistory.Where(o => o.ID == id);
...
}
Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
From Microsoft Document,
You will get this error in both conditions Connection timeout or Query or command timeout. first identify it from call stack of the error messages.
If you found it as a connection issue you can either Increase connection timeout parameter. if you are still getting same error, it is causing due to a network issue.
from information that you provided It is Query or command timeout error to work around this error you can set CommandTimeout for query or command
command.CommandTimeout = 10;
The default timeout value is 30 seconds, the query will continue to run until it is finished if the time-out value is set to 0 (no time limit).
For more information refer Troubleshoot query time-out errors provided by Microsoft.

Karate framework : Issue calling js or java interop function during Scenario Outline in Karate for multi-line JSON [duplicate]

This question already has an answer here:
Karate - Database testing - getting timestamp displayed as nano
(1 answer)
Closed 1 year ago.
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
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.

Error using DBUtils in first scenario [duplicate]

This question already has an answer here:
Karate - Database testing - getting timestamp displayed as nano
(1 answer)
Closed 1 year ago.
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
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.

HP ALM OTA-API: How to update a test in testlab knowing the id?

I know the id of a test that is in a Testset and want to update your status, know how to do it using the API OTA?
Edit:
Thanks but current answer unfortunately doesn't work for me .
I put the example ( java) :
ITestSetFactory sTestFactory = (itdc.testSetFactory()).queryInterface(ITestSetFactory.class);
ITDFilter filterF=sTestFactory.filter().queryInterface(ITDFilter.class);
filterF.filter("TC_TEST_ID","531729");
System.out.println(filterF.newList().count());
The error:
Exception in thread "main" com4j.ComException: 800403ea (Unknown error) : Failed to Get Test Set Value : .\invoke.cpp:517
at com4j.Wrapper.invoke(Wrapper.java:166)
at com.sun.proxy.$Proxy13.newList(Unknown Source)
at TestQC.main(TestQC.java:64)
Any suggestions ?
The error occurs because you use the TestSetFactory instead of the TSTestFactory. You should use itdc.tsTestFactory() because it is TSTest objects you want to manipulate (aka test instances), not TestSet objects. The simplest way is to get the TSTestFactory of your TDConnection object, and use a filter to get the TSTest object and then set its status. Example code in Ruby:
ts_test_factory = tdc.TSTestFactory
filter = ts_test_factory.Filter
filter["TC_TEST_ID"] = "123" # test id from test plan
found_test_instances = filter.NewList
test_instance = found_test_instances.Item(1) # be careful if the test occurs in many test sets
test_instance.Status = "Passed"
test_instance.Post

Google BigQuery getQueryResults returning 404 Error for valid Job Id

I have created Google query job with my own job id successfully. And able to use the job id again and got successful results yesterday.
But the same Job id not working fine.
I have tried the job id with project Id in the google bigquery UI got the same error as '404' below
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found: Table<projectId:some random generated String.some random generated String>"
}
],
"code": 404,
"message": "Not Found: Table <projectId:some random generated String.some random generated String>
}
}
Please help me, is there any life time for Job? Or any specific Configuration required while creating Job Id to work permanently?
I am using Java API of Google Bigquery to do the above implementation. Find the logic used below:
Query Job Creation logic:
String query = "SELECT count(*) AS TOTAL_RECORDS FROM :dataset.:tablename;"
String expectedJobId = "someuniqueString";
JobConfigurationQuery queryConfig = new JobConfigurationQuery()
.setQuery(query);
queryConfig.setUseQueryCache(true);
JobConfiguration config = new JobConfiguration()
.setQuery(queryConfig);
JobReference jobReference = new JobReference();
jobReference.setJobId(expectedJobId);
jobReference.setProjectId(PROJECT_ID);
Job job = new Job().setId(expectedJobId).setConfiguration(
config);
job.setJobReference(jobReference);
job = bigqueryService.jobs()
.insert(PROJECT_ID, job).execute();
Results Retrieved using above JobId :
GetQueryResults queryRequest = bigqueryService.jobs()
.getQueryResults(PROJECT_ID, expectedJobId);
GetQueryResultsResponse queryResponse = queryRequest.execute();
The error you're seeing is not a problem looking up the job but looking up the result table. As you noticed, getQueryResults() for a particular job will only work for up to 24 hours; after that the table that is created to store the results will expire and get cleaned up.
If you find that this happens within the 24 hour window, you might want to check to make sure the job actually completed successfully. You can use bigqueryService.jobs.get() to look up the job status.
If that doesn't help, if you send the job id we (the BigQuery team) can look up in the server logs what is going on with that job.
Sometimes the problem is incorrect dataset location. In my code I have a config based on which I set the dataset location while executing a query. I messed up the location and started getting this error. After 2 hours of debugging finally found the issue.
Corrected the dataset location and it worked fine.