-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add script to compile, build, run, call API and test response [ci skip] #5737
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 script 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 purpose of the script is .." | ||
echo "Usage: ..." | ||
echo "Parameters: " | ||
: | ||
fi | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/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. Compiles OTP" | ||
echo " 2. Runs OTP - build a graph and start the server" | ||
echo " 3. Sends a request using curl" | ||
echo " 4. Tests 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 "Before using this script you should copy it to a folder which is NOT" | ||
echo "under version control and then edit it. You must provide a query, a test and the" | ||
echo "path to the otp data root directory with the OTP configuration files. You need to" | ||
echo "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 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be possible to use
| tee "${OTP_LOG}"
instead of redirection to file, keep the console output and skip thetail
process below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it will work, I need the the java PID (see line 68) to terminate the java process later, so if we use
tee
then I think we get thetee
PID instead. I tried something like it, but it did not work. Not sure if I did the exact same thing as you suggested.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice it doesn't matter that much: even if it's the
tee
pid that is killed, the whole pipe is still terminated.Nevermind, it doesn't matter. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good tip, I didn't know that. I will leave it as is for now. Do not want to spend more time on it.