Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query should accept a Gatling Expression #1

Open
jigarkhwar opened this issue Mar 24, 2024 · 3 comments
Open

Query should accept a Gatling Expression #1

jigarkhwar opened this issue Mar 24, 2024 · 3 comments

Comments

@jigarkhwar
Copy link
Contributor

Tinkoff/gatling-jdbc-plugin#77

@bgrgincic
Copy link

bgrgincic commented Jan 16, 2025

Hi, until this is resolved, is there any way to actually pass parameters from one .exec to another exec.?

Any variant I tried didn't work as Session doesn't seem to be compatible with any builder from org.galaxio.gatling.javaapi.JdbcDsl.

e.g. example that doesn't work because QueryActionBuilder cannot be converted to Session:

   public static ScenarioBuilder scn = scenario("Simplified JDBC Scenario")
           .exec(http("Fetch ID")
                   .post("endpoint")
                   .check(xpath("//path").saveAs("id"))) // Extract 'id' from HTTP response
           .exec(session -> {
              // Extract 'id' from session
              String id = session.getString("id");
              // Build and return the JDBC query dynamically
              return jdbc("Check Test Table")
                      .queryP("SELECT * FROM TEST_TABLE WHERE id = :id") // Parameterized query
                      .params(Map.of("id", id)) // Pass the 'id' as a parameter
                      .check(
                                 // Ensure the query result is not empty
                              allResults().saveAs("queryResult")    // Save query result to session
                      );
           });

This suggests this plugin only works with static SQL queries which is odd because then it reduces the need to even include it within the .exec Gatling DSL chain.

@slandelle
Copy link
Contributor

slandelle commented Jan 16, 2025

This is not how Gatling works, it's not specific to this third party plugin.
Gatling methods are builders/definitions that are built once when the test is created, not something that you can use at runtime.

Instead, have you tried:

.exec(
             jdbc("Check Test Table")
                      .queryP("SELECT * FROM TEST_TABLE WHERE id = :id")
                      .params(Map.of("id", "#{id}")) 
                      .check(
                                 // Ensure the query result is not empty
                              allResults().saveAs("queryResult")
                      );
        )

@bgrgincic
Copy link

Hi @slandelle , you're right this does work (with curly brackets instead of colon in queryP, e.g. {id} ).

I misinterpreted this ticket and my own experimentation thought me to believe referencing session variables like "#{id}" would not work with this plugin.

Working code for me was:

   public static ScenarioBuilder scn = scenario("Simplified JDBC Scenario")
           .exec(http("Fetch ID")
                   .post("endpoint")
                   .check(xpath("//path").saveAs("id")))
           .exec(jdbc("Check Test Table")
                   .queryP("SELECT * FROM TEST_TABLE WHERE id = {id}")
                   .params(Map.of("id", "#{id}"))
                   .check(
                           // Ensure the query result is not empty
                           allResults().saveAs("queryResult")
                   ));

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants