question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[KAFKA]Cannot inject ZeroCode variables into Validators

See original GitHub issue

Description:

This is my usecase:

Details were already provided initially. Copy pasting it again

  1. Consuming from Kafka multiple messages which are from different partitions.
  2. Need to validate the ID field of each message consumed. This ID is Random.Number generated in a previous test (REST POST).
  3. Trying to access this ID deterministically using validators and it is not working. Below is the validator being used. While consuming we are trying to validate the ID of the message consumed.
{
  "name": "consume_from_test-topic",
      "url": "kafka-topic:test-topic",
      "operation": "consume",
      "request": {
        "consumerLocalConfigs": {
          "recordType": "JSON",
          "commitSync": false,
          "showRecordsConsumed": true,
          "maxNoOfRetryPollsOrTimeouts": 2    
        }
      },
"validators": [
			{
				"field": "$..journals[?(@.id==${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id})]",
				"value": "${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id}"
			}
]
}

This is my actual request and actual response

Paste a sample or example here:

Complete logs already attached, as previously requested.

This is what I want to assert or validate

Paste a sample or example here:

Need to validate the value of ID field of each message consumed. This ID is Random.UUID Number generated in a previous test (REST POST)

Further details:

@authorjapps Scenario:

  1. Consuming from Kafka multiple messages which are from different partitions.
  2. Need to validate the ID field of each message consumed. This ID is Random.Number generated in a previous test (REST POST).
  3. Trying to access this ID deterministically using validators and it is not working. Below is the validator being used. While consuming we are trying to validate the ID of the message consumed.
{
  "name": "consume_from_test-topic",
      "url": "kafka-topic:test-topic",
      "operation": "consume",
      "request": {
        "consumerLocalConfigs": {
          "recordType": "JSON",
          "commitSync": false,
          "showRecordsConsumed": true,
          "maxNoOfRetryPollsOrTimeouts": 2    
        }
      },
"validators": [
			{
				"field": "$..journals[?(@.id==${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id})]",
				"value": "${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id}"
			}
]
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
authorjappscommented, Nov 1, 2022

Thank you, great job. Will review and merge soon.

Final bit and help needed when you get chance: Would you mind adding a basic helloword-type example for this please into the Docs?

Doc link: <will create a paste the doc page link here soon>

This will be very useful for most users.

1reaction
RDBreedcommented, Nov 2, 2020

Already did understand what is needed:

  • he has a step in which he posts some data with a list to a backend rest server
  • this backend application will put this received datalist as separate records on the kafka topic
  • next step of the test will get the data records from the kafka topic

The assertion to check here, that the data that was put on the backend rest server, is the same as received from the kafka topic. That is why it was tried to match the outcome of the kafka topic with the request to the backend rest server and because order may be different for the records, the jsonpath matcher in the “field” was used to get the correct record ($..journals[?(@.id==${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id})] which means get the record with an id that matches with the original request list the first one’s id) and then perform a (second imo unnecessary because if the jsonpath matching above is not getting a result, it doesn’t exist and if is matches, then we know the outcome too) check with the value (${$.send_valid_unique_identifiers.response.body.rawJournals.[0].id}. which means the value of the original request list the first one’s id)… Right?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 4: using component variables inside custom validator ...
Class methods do not have this bound to the current instance, they are dependent on the caller to pass the appropriate this to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found