From 8da55e1bd78e32e96fa5c03c217ad09df227e60f Mon Sep 17 00:00:00 2001 From: spamegg1 Date: Sat, 13 Jul 2024 16:20:27 +0300 Subject: [PATCH] ported Bash scripts to Scala-cli --- installGatling.sc | 39 ++++++++++++++++++++++++++++----------- installGatling.sh | 21 --------------------- runGatling.sc | 36 +++++++++++++++++++++++++++++------- runGatling.sh | 12 ------------ 4 files changed, 57 insertions(+), 51 deletions(-) mode change 100644 => 100755 installGatling.sc delete mode 100755 installGatling.sh mode change 100644 => 100755 runGatling.sc delete mode 100755 runGatling.sh diff --git a/installGatling.sc b/installGatling.sc old mode 100644 new mode 100755 index 8f151f3..610fd32 --- a/installGatling.sc +++ b/installGatling.sc @@ -1,21 +1,38 @@ #!/usr/bin/env -S scala-cli +//> using dep com.lihaoyi::os-lib:0.10.2 // download Gatling Highcharts Bundle -// curl -O https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/3.10.5/gatling-charts-highcharts-bundle-3.10.5-bundle.zip +println("Downloading Gatling 3.10.5 to directory ./gatling") +println() + +val url = + "https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/3.10.5/gatling-charts-highcharts-bundle-3.10.5-bundle.zip" +os.proc("curl", "-O", url).call() // unzip, cleanup and rename folder -// unzip gatling-charts-highcharts-bundle-3.10.5-bundle.zip -// rm gatling-charts-highcharts-bundle-3.10.5-bundle.zip -// mv gatling-charts-highcharts-bundle-3.10.5 gatling +os.proc("unzip", "gatling-charts-highcharts-bundle-3.10.5-bundle.zip").call() +os.proc("rm", "gatling-charts-highcharts-bundle-3.10.5-bundle.zip").call() +os.proc("mv", "gatling-charts-highcharts-bundle-3.10.5", "gatling").call() -// echo "installed gatling 3.10.5 to directory ./gatling" +println() +println("Installed gatling 3.10.5 to directory ./gatling") +println() // There is a simulation (written in Java) included by default. Remove that. -// rm -rf ./gatling/user-files/simulations/* -// echo "removed included-by-default Java simulations in ./gatling/user-files/simulations" +val simDir = "./gatling/user-files/simulations" +os.proc("rm", "-rf", simDir + "/computerdatabase").call() +println("Removed included-by-default Java simulations in: " + simDir) +println() // Place our simulation there. -// cp src/main/scala/ch05/examples/loadSimulation.scala ./gatling/user-files/simulations/ -// echo "copied ch05 load simulation into ./gatling/user-files/simulations/" -// echo "now start the http server in another Terminal, and then run the simulation with:" -// echo "./runGatling.sh" +os.proc( + "cp", + "src/main/scala/ch05/examples/loadSimulation.scala", + "./gatling/user-files/simulations/" +).call() +println("Copied ch05 load simulation into ./gatling/user-files/simulations/") +println() + +println("Now start the Http server in another Terminal,") +println("and then run the simulation with:") +println("./runGatling.sc") diff --git a/installGatling.sh b/installGatling.sh deleted file mode 100755 index cf72c61..0000000 --- a/installGatling.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# download Gatling Highcharts Bundle -curl -O https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/3.10.5/gatling-charts-highcharts-bundle-3.10.5-bundle.zip - -# unzip, cleanup and rename folder -unzip gatling-charts-highcharts-bundle-3.10.5-bundle.zip -rm gatling-charts-highcharts-bundle-3.10.5-bundle.zip -mv gatling-charts-highcharts-bundle-3.10.5 gatling - -echo "installed gatling 3.10.5 to directory ./gatling" - -# There is a simulation (written in Java) included by default. Remove that. -rm -rf ./gatling/user-files/simulations/* -echo "removed included-by-default Java simulations in ./gatling/user-files/simulations" - -# Place our simulation there. -cp src/main/scala/ch05/examples/loadSimulation.scala ./gatling/user-files/simulations/ -echo "copied ch05 load simulation into ./gatling/user-files/simulations/" -echo "now start the http server in another Terminal, and then run the simulation with:" -echo "./runGatling.sh" diff --git a/runGatling.sc b/runGatling.sc old mode 100644 new mode 100755 index 5d7c215..8b89f33 --- a/runGatling.sc +++ b/runGatling.sc @@ -1,12 +1,34 @@ #!/usr/bin/env -S scala-cli +//> using dep com.lihaoyi::os-lib:0.10.2 // set environment variables -// export GATLING_URL=http://localhost:8080 -// export GATLING_USERS=1000 -// export GATLING_REQUESTS=50000 -// export GATLING_RAMP_TIME=0 -// echo "Finished setting up environment variables for Gatling simulation." +val gatlingEnv = Map( + "GATLING_URL" -> "http://localhost:8080", + "GATLING_USERS" -> "1000", + "GATLING_REQUESTS" -> "50000", + "GATLING_RAMP_TIME" -> "0" +) +println("Finished setting up environment variables for Gatling simulation.") +println() // interactively compile and run the simulation -// echo "Now running the Gatling binary:" -// ./gatling/bin/gatling.sh +println("Now running the Gatling binary:") +println() + +val sub = os + .proc("sh", os.pwd / "gatling" / "bin" / "gatling.sh") + .spawn( + env = gatlingEnv, + stdout = os.ProcessOutput.Readlines(println) // show script's output. + ) + +// Simulate the interactivity of the script here: +sub.waitFor(2000L) // wait for Gatling script to start and give us a prompt +println(">>>>> Choosing option [1] to run locally!") // show input +sub.stdin.writeLine("1") // run simulation locally +sub.stdin.flush() // send input +sub.waitFor(8000L) // wait for Gatling to check for updates +println(">>>>> Providing optional name: testSim") // show input +sub.stdin.writeLine("testSim") // give optional simulation name +sub.stdin.flush() // send input +sub.waitFor() // wait for simulation to fully run and finish. diff --git a/runGatling.sh b/runGatling.sh deleted file mode 100755 index 1b48adb..0000000 --- a/runGatling.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# set environment variables -export GATLING_URL=http://localhost:8080 -export GATLING_USERS=1000 -export GATLING_REQUESTS=50000 -export GATLING_RAMP_TIME=0 -echo "Finished setting up environment variables for Gatling simulation." - -# interactively compile and run the simulation -echo "Now running the Gatling binary:" -./gatling/bin/gatling.sh