Gatling wrapper shell script fails with ClassNotFound

47 Views Asked by At

I am trying to script a gatling run on localhost. I wrote a shell script for that.

The script is as follows:

#!/bin/bash

do_run() {
    local instance="$1"
    local users="$2"
    local endpoint="$3"
    local token="$4"

    echo "Instance: $instance"
    echo "Users: $users"
    echo "Endpoint: $endpoint"
    echo "Token: $token"

    # Test that the endpoint works
    curl -s -X POST -H "content-type: application/json" -H "Authorization: Bearer ${token}" \
    $endpoint \
    -d '{"dataframe_records": [{"id": 0}]}'

    if [ $? -eq 0 ]; then
        echo 'Smoke test successful'
    else
        echo 'Smoke test failed'
        return
    fi

    echo

    RESULTS_FOLDER="${HOME}/results/${instance}/${users}"
    echo "Remove results folder $RESULTS_FOLDER"
    rm -rf $RESULTS_FOLDER

    echo "Create results folder $RESULTS_FOLDER"
    mkdir -p $RESULTS_FOLDER

    echo
    echo "Simulation Command Line:"
    echo

    echo JAVA_HOME=/usr/lib/jvm/java-11-amazon-corretto.x86_64 \
    ${HOME}/gatling-charts-highcharts-bundle-3.10.3/bin/gatling.sh \
    -rm local \
    -s "\"OnlineTableSimulation\"" \
    -sf "/home/ec2-user/perf-test/simulation" \
    -rf "\"${HOME}/results/${instance}/${users}\"" \
    -erjo "\"-Dconcurrent_users=${users} -Dendpoint=${endpoint} -Dtoken=${token}\"" \
    -rd "\"${instance} instance, ${users} concurrent users\""

    export JAVA_HOME=/usr/lib/jvm/java-11-amazon-corretto.x86_64

    echo
    echo "Running simulation:"
    echo
    
    ${HOME}/gatling-charts-highcharts-bundle-3.10.3/bin/gatling.sh \
    -erjo "\"-Dconcurrent_users=${users} -Dendpoint=${endpoint} -Dtoken=${token}\"" \
    -rm local \
    -s "\"OnlineTableSimulation\"" \
    -sf "/home/ec2-user/perf-test/simulation" \
    -rf "\"${HOME}/results/${instance}/${users}\"" \
    -rd "\"${instance} instance, ${users} concurrent users\""

    if [ $? -eq 0 ]; then
        echo 'stress test successful'
    else
        echo 'stress test failed'
        return
    fi
}

SMALL_ENDPOINT="https://contoso.com"
MEDIUM_ENDPOINT="https://contoso.com"
LARGE_ENDPOINT="https://contoso.com"


SMALL_TOKEN="token"

MEDIUM_TOKEN="token"

LARGE_TOKEN="token"

for i in {1000,2000,4000};
do
    do_run "medium" $i $MEDIUM_ENDPOINT $MEDIUM_TOKEN
done

for i in {1000,2000,4000};
do
    do_run "large" $i $LARGE_ENDPOINT $LARGE_TOKEN
done

This is the gatling.sh script:

#!/bin/bash
#
# Copyright 2011-2023 GatlingCorp (http://gatling.io)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if [ -n "$JAVA_HOME" ]; then
    JAVA="$JAVA_HOME"/bin/java
else
    JAVA=java
fi

OLDDIR=$(pwd)
BIN_DIR=$(dirname "$0")
cd "${BIN_DIR}/.." && DEFAULT_GATLING_HOME=$(pwd) && cd "${OLDDIR}"

GATLING_HOME="${GATLING_HOME:=${DEFAULT_GATLING_HOME}}"

JAVA_OPTS="${JAVA_OPTS} -Xms32M -Xmx128M"

# Setup classpath
CLASSPATH="$GATLING_HOME/lib/*"

echo "$JAVA" $JAVA_OPTS -cp "$CLASSPATH" io.gatling.bundle.GatlingCLI "$@"
"$JAVA" $JAVA_OPTS -cp "$CLASSPATH" io.gatling.bundle.GatlingCLI "$@"

When I run my script, I get the following error:

GATLING_HOME is set to /home/ec2-user/gatling-charts-highcharts-bundle-3.10.3
20:00:35.108 [DEBUG] i.g.c.ZincCompiler$ - [zinc] IncrementalCompile -----------
20:00:35.116 [DEBUG] i.g.c.ZincCompiler$ - IncrementalCompile.incrementalCompile
20:00:35.121 [DEBUG] i.g.c.ZincCompiler$ - previous = Stamps for: 1 products, 1 sources, 2 libraries
20:00:35.122 [DEBUG] i.g.c.ZincCompiler$ - current source = Set(/home/ec2-user/perf-test/simulation/com/contoso/simulation/OnlineTableSimulation.java)
20:00:35.163 [DEBUG] i.g.c.ZincCompiler$ - > initialChanges = InitialChanges(Changes(added = Set(), removed = Set(), changed = Set(), unmodified = ...),Set(),Set(),API Changes: Set())
20:00:35.167 [DEBUG] i.g.c.ZincCompiler$ - No changes
20:00:35.256 [DEBUG] i.g.c.ZincCompiler$ - Compilation successful
Error: Could not find or load main class "-Dconcurrent_users=4000
Caused by: java.lang.ClassNotFoundException: "-Dconcurrent_users=4000

For some reason, it is messing the -erjo parameter and considering that as part of the simulation class. Even though I passed in the simulation class using -s parameter separately.

However, if I copy the command line printed by the shell script, and run it separately in the terminal, it works fine.

I tried moving the -erjo option as the first and last argument to the script, but those didnt work either.

I think I am messing the shell script somehow. Any idea what I am doing wrong?

0

There are 0 best solutions below