Skip to content

Commit

Permalink
ported Bash scripts to Scala-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
spamegg1 committed Jul 13, 2024
1 parent bc4a13a commit 8da55e1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 51 deletions.
39 changes: 28 additions & 11 deletions installGatling.sc
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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")
21 changes: 0 additions & 21 deletions installGatling.sh

This file was deleted.

36 changes: 29 additions & 7 deletions runGatling.sc
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 0 additions & 12 deletions runGatling.sh

This file was deleted.

0 comments on commit 8da55e1

Please sign in to comment.