forked from spring-cloud-samples/sleuth-documentation-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runAcceptanceTests.sh
executable file
·147 lines (113 loc) · 4.41 KB
/
runAcceptanceTests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
set -o errexit
# ======================================= FUNCTIONS START =======================================
CLOUD_DOMAIN=${DOMAIN:-run.pivotal.io}
CLOUD_TARGET=api.${DOMAIN}
CLOUD_PREFIX="docssleuth"
function login(){
cf api | grep ${CLOUD_TARGET} || cf api ${CLOUD_TARGET} --skip-ssl-validation
cf apps | grep OK || cf login
}
function app_domain(){
D=`cf apps | grep $1 | tr -s ' ' | cut -d' ' -f 6 | cut -d, -f1`
echo $D
}
function deploy_app(){
deploy_app_with_name $1 $1
}
function deploy_app_with_name(){
APP_DIR=$1
APP_NAME=$2
cd $APP_DIR
cf push $APP_NAME --no-start
APPLICATION_DOMAIN=`app_domain $APP_NAME`
echo determined that application_domain for $APP_NAME is $APPLICATION_DOMAIN.
cf env $APP_NAME | grep APPLICATION_DOMAIN || cf set-env $APP_NAME APPLICATION_DOMAIN $APPLICATION_DOMAIN
cf restart $APP_NAME
cd ..
}
function deploy_service(){
N=$1
D=`app_domain $N`
JSON='{"uri":"http://'$D'"}'
cf create-user-provided-service $N -p $JSON
}
function reset(){
app_name=$1
echo "going to remove ${app_name} if it exists"
cf apps | grep $app_name && cf d -f $app_name
echo "deleted ${app_name}"
}
# ======================================= FUNCTIONS END =======================================
# ======================================= BUILD START =======================================
root=`pwd`
./gradlew clean --parallel
echo -e "\n\nPrinting dependencies"
./gradlew allDeps
echo -e "\n\nBuilding builds in parallel"
./gradlew build --parallel --refresh-dependencies
# ======================================= BUILD END =======================================
# ======================================= DEPLOY START =======================================
echo -e "\nDeploying infrastructure apps\n\n"
READY_FOR_TESTS="no"
echo "Booting RabbitMQ"
# create RabbitMQ
APP_NAME="${CLOUD_PREFIX}-rabbitmq"
cf s | grep ${APP_NAME} && echo "found ${APP_NAME}" && READY_FOR_TESTS="yes" ||
cf cs cloudamqp lemur ${APP_NAME} && echo "Started RabbitMQ" && READY_FOR_TESTS="yes"
if [[ "${READY_FOR_TESTS}" == "no" ]] ; then
echo "RabbitMQ failed to start..."
exit 1
fi
# ====================================================
# Boot zipkin-stuff
echo -e "\n\nBooting up MySQL"
READY_FOR_TESTS="no"
# create MySQL DB
APP_NAME="${CLOUD_PREFIX}-mysql"
cf s | grep ${APP_NAME} && echo "found ${APP_NAME}" && READY_FOR_TESTS="yes" ||
cf cs cleardb spark ${APP_NAME} && echo "Started ${APP_NAME}" && READY_FOR_TESTS="yes"
if [[ "${READY_FOR_TESTS}" == "no" ]] ; then
echo "MySQL failed to start..."
exit 1
fi
# ====================================================
cd $root
echo -e "\n\nDeploying Zipkin Server"
zq=zipkin-server
ZQ_APP_NAME="${CLOUD_PREFIX}-$zq"
cd $root/$zq
reset $ZQ_APP_NAME
cf d -f $ZQ_APP_NAME
cd $root/zipkin-server
if [ -f "zipkin.jar" ]; then
echo "Zipkin was downloaded - will continue"
else
curl -sSL https://zipkin.io/quickstart.sh | bash -s
fi
cf push && READY_FOR_TESTS="yes"
if [[ "${READY_FOR_TESTS}" == "no" ]] ; then
echo "Zipkin Server failed to start..."
exit 1
fi
cd $root
# ====================================================
cd $root
echo -e "\n\nStarting brewery apps..."
deploy_app_with_name "service1" "${CLOUD_PREFIX}-service1"
deploy_app_with_name "service2" "${CLOUD_PREFIX}-service2"
deploy_app_with_name "service3" "${CLOUD_PREFIX}-service3"
deploy_app_with_name "service4" "${CLOUD_PREFIX}-service4"
# ====================================================
SERVICE1_HOST=`app_domain ${CLOUD_PREFIX}-service1`
ZIPKIN_SERVER_HOST=`app_domain ${CLOUD_PREFIX}-zipkin-server`
echo -e "Service1 host is [${SERVICE1_HOST}]"
echo -e "Zikpin server host is [${ZIPKIN_SERVER_HOST}]"
# ======================================= DEPLOY END =======================================
# ======================================= TEST START =======================================
echo -e "Running acceptance tests"
cd $root
ACCEPTANCE_TEST_OPTS="-DLOCAL_URL=http://${ZIPKIN_SERVER_HOST} -DserviceUrl=http://${SERVICE1_HOST} -Dzipkin.query.port=80"
echo -e "\n\nSetting test opts for sleuth stream to call ${ACCEPTANCE_TEST_OPTS}"
./gradlew :acceptance-tests:acceptanceTests "-DLOCAL_URL=http://${ZIPKIN_SERVER_HOST}" "-DserviceUrl=http://${SERVICE1_HOST}" "-Dzipkin.query.port=80" --stacktrace --no-daemon --configure-on-demand
# ======================================= TEST END =======================================