diff --git a/.github/workflows/irs-load-test.yaml b/.github/workflows/irs-load-test.yaml new file mode 100644 index 0000000000..4ce332edbb --- /dev/null +++ b/.github/workflows/irs-load-test.yaml @@ -0,0 +1,41 @@ +name: IRS Load Test + +on: + workflow_dispatch: # Trigger manually + inputs: + irs-host: + type: choice + description: IRS environment to test + default: 'https://irs-full.dev.demo.catena-x.net' + required: true + options: + - 'https://irs-full.dev.demo.catena-x.net' + - 'https://irs.dev.demo.catena-x.net' + - 'https://irs.int.demo.catena-x.net' + test-cycles: + type: string + description: Number of Test Cycles + default: '20' + required: false + +jobs: + gatling-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Run Gatling tests + env: + KEYCLOAK_HOST: ${{ secrets.KEYCLOAK_OAUTH2_CLIENT_TOKEN_URI }} + KEYCLOAK_CLIENT_SECRET: ${{ secrets.KEYCLOAK_OAUTH2_CLIENT_ID }} + KEYCLOAK_CLIENT_ID: ${{ secrets.KEYCLOAK_OAUTH2_CLIENT_ID }} + IRS_HOST: ${{ github.event.inputs.irs-host || 'https://irs-full.dev.demo.catena-x.net' }} + TEST_CYCLES: ${{ github.event.inputs.test-cycles || '20' }} + run: | + mvn gatling:test -pl irs-load-tests + + - name: Archive Report + uses: actions/upload-artifact@v3 + with: + name: gatling-report + path: irs-load-tests/target/gatling/ diff --git a/Dockerfile b/Dockerfile index 1aa7a2e6dc..0f3cf4cce1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ COPY irs-testing irs-testing COPY irs-report-aggregate irs-report-aggregate COPY cucumber-tests cucumber-tests COPY docs docs +COPY irs-load-tests irs-load-tests # the --mount option requires BuildKit. RUN --mount=type=cache,target=/root/.m2 mvn -B clean package -pl :$BUILD_TARGET -am -DskipTests diff --git a/irs-load-tests/pom.xml b/irs-load-tests/pom.xml new file mode 100644 index 0000000000..e21ae12e05 --- /dev/null +++ b/irs-load-tests/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + + org.eclipse.tractusx.irs + irs-parent-spring-boot + ${revision} + ../irs-parent-spring-boot + + + irs-load-tests + + IRS Load Tests + Item Relationship Service Load Tests + + + + io.gatling.highcharts + gatling-charts-highcharts + 3.9.2 + test + + + + + + + io.gatling + gatling-maven-plugin + 4.3.0 + + + + diff --git a/irs-load-tests/src/test/java/org/eclipse/tractusx/irs/IRSLoadTestSimulation.java b/irs-load-tests/src/test/java/org/eclipse/tractusx/irs/IRSLoadTestSimulation.java new file mode 100644 index 0000000000..b01a1db31f --- /dev/null +++ b/irs-load-tests/src/test/java/org/eclipse/tractusx/irs/IRSLoadTestSimulation.java @@ -0,0 +1,59 @@ +package org.eclipse.tractusx.irs; + +import static io.gatling.javaapi.core.CoreDsl.RawFileBody; +import static io.gatling.javaapi.core.CoreDsl.StringBody; +import static io.gatling.javaapi.core.CoreDsl.atOnceUsers; +import static io.gatling.javaapi.core.CoreDsl.jsonPath; +import static io.gatling.javaapi.core.CoreDsl.scenario; +import static io.gatling.javaapi.http.HttpDsl.http; +import static io.gatling.javaapi.http.HttpDsl.status; + +import java.util.HashMap; +import java.util.Map; + +import io.gatling.javaapi.core.ScenarioBuilder; +import io.gatling.javaapi.core.Simulation; +import io.gatling.javaapi.http.HttpProtocolBuilder; + +public class IRSLoadTestSimulation extends Simulation { + { + final String keycloak_host = System.getenv("KEYCLOAK_HOST"); + final String clientSecret = System.getenv("KEYCLOAK_CLIENT_SECRET"); + final String clientId = System.getenv("KEYCLOAK_CLIENT_ID"); + String body = "grant_type=client_credentials&client_id=" + clientId + "&client_secret=" + clientSecret; + final String irsUrl = System.getenv("IRS_HOST"); + final int testCycles = Integer.parseInt(System.getenv("TEST_CYCLES")); + + Map headers_0 = new HashMap<>(); + headers_0.put("Content-Type", "application/x-www-form-urlencoded"); + + HttpProtocolBuilder httpProtocol = http.baseUrl(irsUrl) + .acceptHeader("*/*"); + + Map headers_1 = new HashMap<>(); + headers_1.put("Authorization", "Bearer #{access_token}"); + headers_1.put("Content-Type", "application/json"); + + ScenarioBuilder scn = scenario("IRS Load Test") + .exec(http("Get access token") + .post(keycloak_host) + .body(StringBody(body)) + .asFormUrlEncoded() + .headers(headers_0) + .check(status().is(200)) + .check(jsonPath( + "$.access_token") + .saveAs("access_token"))) + .exec(http("Start Job") + .post(irsUrl+"/irs/jobs") + .headers(headers_1) + .body(RawFileBody("org/eclipse/tractusx/irs/loadtest/IRS-start-job-body.json")) + .check(jsonPath("$.id") + .saveAs("id"))) + .exec(http("Get Job") + .get("/irs/jobs/#{id}?returnUncompletedJob=true") + .headers(headers_1)); + + setUp(scn.injectOpen(atOnceUsers(testCycles))).protocols(httpProtocol); + } +} diff --git a/irs-load-tests/src/test/resources/org/eclipse/tractusx/irs/loadtest/IRS-start-job-body.json b/irs-load-tests/src/test/resources/org/eclipse/tractusx/irs/loadtest/IRS-start-job-body.json new file mode 100644 index 0000000000..ddac6cc053 --- /dev/null +++ b/irs-load-tests/src/test/resources/org/eclipse/tractusx/irs/loadtest/IRS-start-job-body.json @@ -0,0 +1,10 @@ +{ + "bomLifecycle": "asBuilt", + "aspects": [ + "AssemblyPartRelationship" + ], + "depth": 10, + "direction": "downward", + "collectAspects": true, + "globalAssetId": "urn:uuid:d3c0bf85-d44f-47c5-990d-fec8a36065c6" +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 423d364f35..c1fffb7ec3 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ irs-report-aggregate cucumber-tests docs + irs-load-tests