Skip to content

Commit

Permalink
Add srcipt to compile otp, build a graph, run server and perform a AP…
Browse files Browse the repository at this point in the history
…I call and test result
  • Loading branch information
t2gran committed Mar 8, 2024
1 parent 58ba141 commit 78a3e9c
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
30 changes: 30 additions & 0 deletions script/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Scripts

This folder is intended for various scripts used during the OTP development. They are provided
"as is" and the "owner" may do whatever she/he likes with it.

If you want to submit your own scripts, you need to include:
- A header at the beginning of the script stating who the owner is.
- The scrip should print some usage documentation if invoked with `--help` and `-h`.

The regular pull-request approval process is required for submitting new scripts and changing
existing one. The reviewers are responsible for:
- [ ] Is this script relevant for OTP and at least one active member of the OTP community?
- [ ] Is the script harmful?
- [ ] Does the script have sufficient documentation?
- [ ] Owner section
- [ ] Print help with `-h` and `--help`

### Example
```
# Owner: J. Brown, Fun & Fast Transit Inc
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "The purpouse of the script is .."
echo "Usage: ..."
echo "Parameters: "
:
fi
```

102 changes: 102 additions & 0 deletions script/run-and-test-otp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

## Owner: Thomas Gran, Entur AS

# [ EDIT HERE ] ----------------------------------------------------------

# Match or NOT Match. The script return success 0 - Good if a match is found(-l) or not found(-L)
# -l : Match
# -L : Not match
MATCH="-L"


# The HTTP URL query to call using curl"
QUERY="http://localhost:8080/otp/routers/default/plan?"
QUERY+="fromPlace=63.30959874454729%2C9.858169555664064&"
QUERY+="toPlace=63.26723697045908%2C9.811992645263674&"
QUERY+="time=14%3A50&date=03-07-2024&"
QUERY+="mode=FLEX_ACCESS%2CFLEX_EGRESS%2CTRANSIT&"
QUERY+="searchWindow=780"

ACCEPT_HEADER="accept: application/json, */*"

# The string token to search for"
SEARCH_FOR="No trip found"

# File catalog where the the OTP config files is (build-config.json & router-config.json)
DATA_DIR=../data/fix-error-access

# ----------------------------------------------------------- [ EDIT END ]

if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "This script: "
echo " 1. Compile OTP"
echo " 2. Run OTP - build a graph and start the server"
echo " 3. Send a request using curl"
echo " 4. Test the response, search for a unexpected token. If the token is"
echo " NOT present the test is GOOD, if not it is BAD"
echo ""
echo "You need to edit the following variables in the beginning of the script:"
echo " - QUERY - the HTTP URL query to call using curl"
echo " - SEARCH_FOR - The string token to search for - if it is present the test FAILS!"
echo " - DATA_DIR - File catalog where the the OTP config files is (build-config.json & router-config.json)"
echo ""
echo "This script is intended used together with 'git bisect' (binary search for good and bad"
echo "commits), but it works well with manual changes in the code as well. When you have found"
echo "the bad commit, you may manually undo it line by line to find the problem."
echo ""
echo "ARGUMENTS"
echo " --help | -h : Help"
echo " --skipCompile | -c : Skip Maven compile"
exit 0
fi

# Files used to store intermediate results - check the files if the script
# is not working as expected.
OTP_LOG=target/otp.log
RESPONSE_FILE=target/response.json


if [ "$1" != "--skipCompile" ] && [ "$1" != "-c" ]; then
echo "Build project with maven"
mvn clean package -Dps -DskipTests
fi

echo "Start OTP, output: $OTP_LOG"
mv target/otp-*-shaded.jar target/otp-shaded.jar
java -Xmx16G -jar target/otp-shaded.jar ${DATA_DIR} --build --save --serve > ${OTP_LOG} &
OTP_PID=$!

tail -F ${OTP_LOG} &
TAIL_PID=$!

while ! grep "Grizzly server running" ${OTP_LOG};do echo "#";sleep 1;done

echo "OTP Server up and running"

echo "Query: $QUERY"
curl -s -o ${RESPONSE_FILE} "$QUERY" -H "$ACCEPT_HEADER"

echo "Test results does NOT match (-L) or match (-l)"
grep ${MATCH} "${SEARCH_FOR}" ${RESPONSE_FILE}
OK=$?

echo "Shutdown..."
echo "Kill Otp Server PID: ${OTP_PID}"
kill $OTP_PID

# Allow OTP to shutdown before we kill the tail and return, this is not critical it is just
# a bit confusing if the script is done, while OTP is still writing to the console.
sleep 3
echo "Kill Tail PID: ${TAIL_PID}"
kill $TAIL_PID

echo ""

if [ "$OK" == 0 ]; then
echo "Test is OK - GOOD"
exit 0
else
echo "Test failed - BAD"
exit 1
fi

0 comments on commit 78a3e9c

Please sign in to comment.