Skip to content

Commit 0861ffc

Browse files
committed
Colorize different outputs differently for visual disambiguation
1 parent e334c1b commit 0861ffc

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

testExamples.sh

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22
set -e # Fail on error
33
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT # Kill subprocesses on exit
44

5+
highlight() { grep --color -E "\S|$" "${@:1}" ; }
6+
echo "Comments and Results => Black"
7+
highlightServer () { export GREP_COLORS='ms=0;32'; highlight ; }
8+
echo "Server => Green" | highlightServer
9+
highlightClient () { export GREP_COLORS='ms=0;34'; highlight ; }
10+
echo "Client => Blue" | highlightClient
11+
highlightSupport () { export GREP_COLORS='ms=0;33'; highlight ; }
12+
echo "Support => Yellow" | highlightSupport
13+
highlightGradle () { export GREP_COLORS='ms=0;36'; highlight ; }
14+
echo "Gradle => Cyan" | highlightGradle
15+
lastStartedPid () { jobs -p | tail -n 1; }
16+
517
build() {
618
echo "Building project"
7-
./gradlew clean --console=plain
8-
./gradlew build --console=plain
19+
./gradlew clean --console=plain |& highlightGradle
20+
./gradlew build --console=plain |& highlightGradle
921
sleep 2s
1022
}
1123

@@ -14,11 +26,11 @@ localTest() {
1426
echo "Starting Local test"
1527

1628
# Run environment
17-
./gradlew :example:local-grpc-server:bootRun -x jar -x classes --console=plain &
18-
LOCAL_SERVER=$!
29+
./gradlew :example:local-grpc-server:bootRun -x jar -x classes --console=plain |& highlightServer &
30+
LOCAL_SERVER=`lastStartedPid`
1931
sleep 10s # Wait for the server to start
20-
./gradlew :example:local-grpc-client:bootRun -x jar -x classes --console=plain &
21-
LOCAL_CLIENT=$!
32+
./gradlew :example:local-grpc-client:bootRun -x jar -x classes --console=plain |& highlightClient &
33+
LOCAL_CLIENT=`lastStartedPid`
2234
sleep 30s # Wait for the client to start and the server to be ready
2335

2436
# Test
@@ -56,19 +68,21 @@ cloudTest() {
5668
# Run environment
5769
if [[ "$1" = "consul" ]]; then
5870
CONSUL=`docker run --name=consul -d --rm -p 8500:8500 consul`
71+
docker logs -f $CONSUL |& highlightSupport &
5972
stopCloudEnv() {
6073
echo "Stopping consul server"
6174
docker stop $CONSUL
6275
}
6376
elif [[ "$1" == "eureka" ]]; then
64-
./gradlew :example:cloud-eureka-server:bootRun -x jar -x classes --console=plain &
65-
EUREKA=$!
77+
./gradlew :example:cloud-eureka-server:bootRun -x jar -x classes --console=plain |& highlightSupport &
78+
EUREKA=`lastStartedPid`
6679
stopCloudEnv() {
6780
echo "Stopping eureka server"
6881
kill -s TERM $EUREKA
6982
}
7083
elif [[ "$1" = "nacos" ]]; then
7184
NACOS=`docker run --env MODE=standalone --name nacos -d --rm -p 8848:8848 nacos/nacos-server`
85+
docker logs -f $NACOS |& highlightSupport &
7286
stopCloudEnv() {
7387
echo "Stopping nacos server"
7488
docker stop $NACOS
@@ -83,16 +97,16 @@ cloudTest() {
8397
# curl -sSL https://zipkin.io/quickstart.sh | bash -s
8498
# fi
8599
# java -jar zipkin.jar &
86-
# ZIPKIN=$!
100+
# ZIPKIN=`lastStartedPid`
87101
# sleep 10s # Wait for the server to start
88102
# cd ..
89103

90-
./gradlew -Pdiscovery=$1 :example:cloud-grpc-server:bootRun -x jar -x classes --console=plain &
91-
CLOUD_SERVER=$!
104+
./gradlew -Pdiscovery=$1 :example:cloud-grpc-server:bootRun -x jar -x classes --console=plain |& highlightServer &
105+
CLOUD_SERVER=`lastStartedPid`
92106
sleep 10s # Wait for the server to start
93107

94-
./gradlew -Pdiscovery=$1 :example:cloud-grpc-client:bootRun -x jar -x classes --console=plain &
95-
CLOUD_CLIENT=$!
108+
./gradlew -Pdiscovery=$1 :example:cloud-grpc-client:bootRun -x jar -x classes --console=plain |& highlightClient &
109+
CLOUD_CLIENT=`lastStartedPid`
96110
sleep 30s # Wait for the client to start and the server to be ready
97111
sleep 60s # Wait for the discovery service to refresh
98112

@@ -111,8 +125,8 @@ cloudTest() {
111125
sleep 1s # Wait for the shutdown logs to pass
112126

113127
# and restart server
114-
./gradlew -Pdiscovery=$1 :example:cloud-grpc-server:bootRun -x jar -x classes --console=plain &
115-
CLOUD_SERVER=$!
128+
./gradlew -Pdiscovery=$1 :example:cloud-grpc-server:bootRun -x jar -x classes --console=plain |& highlightServer &
129+
CLOUD_SERVER=`lastStartedPid`
116130
sleep 30s # Wait for the server to start
117131
sleep 60s # Wait for the discovery service to refresh
118132

@@ -163,11 +177,11 @@ securityBasicAuthTest() {
163177
echo "Starting Security Basic Auth test"
164178

165179
# Run environment
166-
./gradlew :example:security-grpc-server:bootRun -x jar -x classes --console=plain &
167-
LOCAL_SERVER=$!
180+
./gradlew :example:security-grpc-server:bootRun -x jar -x classes --console=plain |& highlightServer &
181+
LOCAL_SERVER=`lastStartedPid`
168182
sleep 10s # Wait for the server to start
169-
./gradlew :example:security-grpc-client:bootRun -x jar -x classes --console=plain &
170-
LOCAL_CLIENT=$!
183+
./gradlew :example:security-grpc-client:bootRun -x jar -x classes --console=plain |& highlightClient &
184+
LOCAL_CLIENT=`lastStartedPid`
171185
sleep 30s # Wait for the client to start and the server to be ready
172186

173187
# Test

0 commit comments

Comments
 (0)