2

We are currently using karate 0.9.6 in our testing framework and requirement is somehow to match entire response body with file stored as a json(it's a finance based application where we need to verify entire response body)

I am trying to migrate to 1.0.1 as per the upgrade guide

The scenario in which we are asserting against the saved response is failing with Java Heap space error after upgrading to 1.0.1

Due to security constraint i can't put the response body here so i tried with open source api with large response body and it is failing to with below use case

Given url "https://jsonplaceholder.typicode.com/photos"
And json expected_resp =read('classpath:<path_to_saved_file>/response.json')
When method GET 
Then status 200
Then match response  == '#(^^expected_resp)'

enter image description here

PS: I've already all the steps mentioned in here

Ketan Sethi
  • 124
  • 2
  • 9
  • Which Java version of Java are you using? Have you tried increasing the heap size? https://stackoverflow.com/questions/1565388/increase-heap-size-in-java – anutter Apr 26 '21 at 17:46

1 Answers1

2

Sorry that's not enough info to replicate. I tried the following and it works:

Given url "https://jsonplaceholder.typicode.com/photos"
When method GET 
Then status 200

We have anyway opened an issue, but will close it within a day or two if we can't replicate: https://github.com/intuit/karate/issues/1572

This is an open-source project and we depend on contributions or at least better information from you.

EDIT: solution for very large JSON arrays is to sort the array (now easily possible in Karate 1.0) and then do an exact match - which will avoid the memory that is needed to do a contains match.

* def sorted = karate.sort(response, x => x.id)
* match sorted == read('photos.json')
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • have you saved the response in file and ran below assertion , all i can see is you made the GET request And json expected_resp =read('classpath:/response.json') When method GET Then status 200 Then match response == '#(^^expected_resp)' – Ketan Sethi Apr 24 '21 at 17:06
  • 1
    @KetanSethi ok. it would have been nice if you tried the RC releases we did for months so that we could have gotten this feedback earlier. so now this will take time to fix. you are welcome to contribute code or stick to the old version for some time. – Peter Thomas Apr 24 '21 at 17:21
  • 1
    As discussed over github issue mentioned above there is issue with karate for response matching with large json arrays.The workaround is to use karate.sort and then do an exact match – Ketan Sethi Apr 25 '21 at 13:25