Session - how to get values of feeded 2 records

Hi,

I wondering how to get from session object values of feeded 2 records.
As I see there is java.lang.Object and I don’t have idea how to extract from it values.

I want to System.out.println values of this object.

Any hint is appreciated :sunglasses:

My code:

package pl.gemiusz;

import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;

public class Case0015UUIDfeederTwoRecordsAtTheSameTimeSimulation extends Simulation {

    HttpProtocolBuilder httpProtocol =
            http
                    .baseUrl("https://postman-echo.com");

    Iterator<Map<String, Object>> feederUUID =
            Stream.generate((Supplier<Map<String, Object>>) () -> {
                        String uuidString = UUID.randomUUID().toString();
                        return Collections.singletonMap("uuidString", uuidString);
                    }
            ).iterator();

    ScenarioBuilder scn =
            scenario("GeMi_UUIDfeederTwoRecordsAtTheSameTimeSimulation")
                    .feed(feederUUID, 2)
                    .exec(
                            http("GeMi_UUIDfeederTwoRecordsAtTheSameTimeSimulation_get")
                                    .get("/get?foo=#{uuidString(0)}&bar=#{uuidString(1)}")
                                    .check(jmesPath("args.foo").isEL("#{uuidString(0)}"))
                                    .check(jmesPath("args.bar").isEL("#{uuidString(1)}"))
                    ).exec(session -> {
                        System.out.println("GeMi_feederUUID_uuidString(0): " + session.get("uuidString"));
                        return session;
                    });

    {
        setUp(scn.injectOpen(atOnceUsers(1)).protocols(httpProtocol));
    }
}

uuidString would be an array of Object.

1 Like

Thank you for hint.
I don’t know why I don’t make correct solution with Array yesterday - I have seen that is Array of Object :smiley:

Today I make it :rofl:

Full code:

package pl.gemiusz;

import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;

public class Case0015UUIDfeederTwoRecordsAtTheSameTimeSimulation extends Simulation {

    HttpProtocolBuilder httpProtocol =
            http
                    .baseUrl("https://postman-echo.com");

    Iterator<Map<String, Object>> feederUUID =
            Stream.generate((Supplier<Map<String, Object>>) () -> {
                        String uuidString = UUID.randomUUID().toString();
                        return Collections.singletonMap("uuidString", uuidString);
                    }
            ).iterator();

    ScenarioBuilder scn =
            scenario("GeMi_UUIDfeederTwoRecordsAtTheSameTimeSimulation")
                    .feed(feederUUID, 2)
                    .exec(
                            http("GeMi_UUIDfeederTwoRecordsAtTheSameTimeSimulation_get")
                                    .get("/get?foo=#{uuidString(0)}&bar=#{uuidString(1)}")
                                    .check(jmesPath("args.foo").isEL("#{uuidString(0)}"))
                                    .check(jmesPath("args.bar").isEL("#{uuidString(1)}"))
                    ).exec(session -> {
                        Object[] uuidStringArray = session.get("uuidString");
                        System.out.println("GeMi_feederUUID_uuidString(0): " + uuidStringArray[0]);
                        System.out.println("GeMi_feederUUID_uuidString(1): " + uuidStringArray[1]);
                        return session;
                    });

    {
        setUp(scn.injectOpen(atOnceUsers(1)).protocols(httpProtocol));
    }
}

Code in Repo:
Case0015UUIDfeederTwoRecordsAtTheSameTimeSimulation

1 Like