-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontextual-bandit-integration-test.sh
More file actions
executable file
·212 lines (173 loc) · 9.26 KB
/
Copy pathcontextual-bandit-integration-test.sh
File metadata and controls
executable file
·212 lines (173 loc) · 9.26 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env bash
echo
echo "Usage: contextual-bandit-integration-test.sh"
echo "run from harness/java-sdk or from the integration-test.sh"
echo "Make sure to set export HARNESS_CA_CERT=/path/to/harness.pem!!! or all sending to Harness will fail."
echo
# several flags are passed in via export from the integration test, otherwise they are undefined
# so this script will execute the defaults
# point to the harness host, use https://... for SSL and set the credentials if using Auth
# export "HARNESS_CLIENT_USER_ID"=xyz
# export "HARNESS_CLIENT_USER_SECRET"=abc
host=localhost
engine_1=test_cb
engine_2=test_cb_2
#test_queries=data/2-user-query.json
#engine_1_behavior_events=data/joe-context-tags-2.json
#engine_1_profile_events=data/joe-profile-location.json
#engine_2_behavior_events=data/john-context-tags-2.json
#engine_2_profile_events=data/john-profile-location.json
sleep_seconds=1
# export HARNESS_CA_CERT=/Users/pat/harness/rest-server/server/src/main/resources/keys/harness.pem
cd example
# initialize these in case not running from integrated test script
skip_restarts=${skip_restarts:-false}
clean_test_artifacts=${clean_test_artifacts:-false}
echo
echo "----------------------------------------------------------------------------------------------------------------"
echo "TESTING SIMILAR PROFILES, 2 PEOPLE $set, INTO 2 DIFFERENT ENGINES"
echo "----------------------------------------------------------------------------------------------------------------"
harness delete $engine_1
sleep $sleep_seconds
harness delete $engine_2
sleep $sleep_seconds
harness add data/$engine_1.json
sleep $sleep_seconds
harness add data/$engine_2.json
harness status
harness status engines
# The test is to create 2 engines, 2 users with profile data convert on the same variant in one engine and only
# one user converts on a variant on the second engine. both engines should return the same variant for both users
# because profile is in common.
echo
echo "Sending events to create testGroup: 1, user: joe, and one conversion event with location new york to test_cb"
echo
#mvn compile
# mvn exec:java -Dexec.mainClass="EventsClientExample" -Dexec.args="$1 $2 $3" -Dexec.cleanupDaemonThreads=false
mvn exec:java -Dexec.mainClass="EventsClientExample" -Dexec.args="$host $engine_1 data/joe-profile-location.json" -Dexec.cleanupDaemonThreads=false
echo
echo "Sending events to create testGroup: 1, user: john, and one conversion event with location new york to test_cb"
echo
mvn exec:java -Dexec.mainClass="EventsClientExample" -Dexec.args="$host $engine_1 data/john-profile-location.json" -Dexec.cleanupDaemonThreads=false
echo
echo "Sending events to create testGroup: 1, user: john, and one conversion event with location new york to test_cb_2"
echo
mvn exec:java -Dexec.mainClass="EventsClientExample" -Dexec.args="$host $engine_2 data/joe-profile-location.json" -Dexec.cleanupDaemonThreads=false
echo "================================== Before restart queries =================================="
echo "================================== Before restart queries ==================================" > test-profile-results.txt
echo
echo "Sending queries for joe and john to test_cb"
echo
mvn exec:java -Dexec.mainClass="QueriesClientExample" -Dexec.args="$host $engine_1 data/2-user-query.json" -Dexec.cleanupDaemonThreads=false >> test-profile-results.txt
echo
echo "Sending queries for joe and john to test_cb_2"
echo
mvn exec:java -Dexec.mainClass="QueriesClientExample" -Dexec.args="$host $engine_2 data/2-user-query.json" -Dexec.cleanupDaemonThreads=false >> test-profile-results.txt
echo
echo "----------------------------------------------------------------------------------------------------------------"
echo "TESTING CONTEXTUAL BANDIT MODEL PERSISTENCE BY RESTARTING HARNESS AND MAKING QUERIES"
echo "The results should be the same as before the restart"
echo "----------------------------------------------------------------------------------------------------------------"
echo
echo "Harness running, queries return correct results"
ls -al /tmp/harness/models/
if [ "$skip_restarts" == false ]; then
sleep 10
harness stop
echo "Stopped, model persisted"
ls -al /tmp/harness/models/
#sleep 10
harness start -f
fi
echo "Started, models ussed to initilaize"
ls -al /tmp/harness/models/
echo "================================== After restart queries =================================="
echo "================================== After restart queries ==================================" >> test-profile-results.txt
echo
echo "Sending queries for joe and john to test_cb"
echo
mvn exec:java -Dexec.mainClass="QueriesClientExample" -Dexec.args="$host $engine_1 data/2-user-query.json" -Dexec.cleanupDaemonThreads=false >> test-profile-results.txt
echo
echo "Sending queries for joe and john to test_cb_2"
echo
mvn exec:java -Dexec.mainClass="QueriesClientExample" -Dexec.args="$host $engine_2 data/2-user-query.json" -Dexec.cleanupDaemonThreads=false >> test-profile-results.txt
echo
echo "----------------------------------------------------------------------------------------------------------------"
echo "TESTING SIMILAR BEHAVIORS, 2 PEOPLE'S CONVERSIONS, INTO 2 DIFFERENT ENGINES"
echo "----------------------------------------------------------------------------------------------------------------"
echo
harness delete $engine_1
sleep $sleep_seconds
harness delete $engine_2
sleep $sleep_seconds
harness add data/$engine_1.json
sleep $sleep_seconds
harness add data/$engine_2.json
harness status
harness status engines
# The test is to create 2 engines, 2 users with tag preference behavioral data convert on the same variant in one engine and
# only one user converts on a variant on the second engine. both engines should return the same variant for both users
# because tag preferences are in common is in common.
echo
echo "Sending events to create testGroup: 1, user: joe, and one conversion event with no contextualTags to test_cb"
echo
#mvn compile
# mvn exec:java -Dexec.mainClass="EventsClientExample" -Dexec.args="$1 $2 $3" -Dexec.cleanupDaemonThreads=false
mvn exec:java -Dexec.mainClass="EventsClientExample" -Dexec.args="$host $engine_1 data/joe-context-tags-2.json" -Dexec.cleanupDaemonThreads=false
echo
echo "Sending events to create testGroup: 1, user: john, and one conversion event with no contextualTags to test_cb_2"
echo
mvn exec:java -Dexec.mainClass="EventsClientExample" -Dexec.args="$host $engine_1 data/john-context-tags-2.json" -Dexec.cleanupDaemonThreads=false
echo
echo "Sending events to create testGroup: 1, user: john, and one conversion event with no contextualTags to test_cb_2"
echo
mvn exec:java -Dexec.mainClass="EventsClientExample" -Dexec.args="$host $engine_2 data/joe-context-tags-2.json" -Dexec.cleanupDaemonThreads=false
echo "================================== Before restart behavior queries =================================="
echo "================================== Before restart behavior queries ==================================" > test-behavior-results.txt
echo
echo "Sending queries for joe and john to test_cb"
echo
mvn exec:java -Dexec.mainClass="QueriesClientExample" -Dexec.args="$host $engine_1 data/2-user-query.json" -Dexec.cleanupDaemonThreads=false >> test-behavior-results.txt
echo
echo "Sending queries for joe and john to test_cb_2"
echo
mvn exec:java -Dexec.mainClass="QueriesClientExample" -Dexec.args="$host $engine_2 data/2-user-query.json" -Dexec.cleanupDaemonThreads=false >> test-behavior-results.txt
echo
echo "----------------------------------------------------------------------------------------------------------------"
echo "TESTING CONTEXTUAL BANDIT MODEL PERSISTENCE BY RESTARTING HARNESS AND MAKING QUERIES"
echo "The results should be the same as before the restart"
echo "----------------------------------------------------------------------------------------------------------------"
echo
echo "Harness running, queries return correct results"
ls -al /tmp/harness/models/
if [ "$skip_restarts" == false ]; then
sleep 10
harness stop
echo "Stopped, model persisted"
ls -al /tmp/harness/models/
#sleep 10
harness start -f
fi
echo "Started, models ussed to initilaize"
ls -al /tmp/harness/models/
echo
echo "Sending queries for joe and john to test_cb"
echo
echo "================================== After restart queries =================================="
echo "================================== After restart queries ==================================" >> test-behavior-results.txt
mvn exec:java -Dexec.mainClass="QueriesClientExample" -Dexec.args="$host $engine_1 data/2-user-query.json" -Dexec.cleanupDaemonThreads=false >> test-behavior-results.txt
echo
echo "Sending queries for joe and john to test_cb_2"
echo
mvn exec:java -Dexec.mainClass="QueriesClientExample" -Dexec.args="$host $engine_2 data/2-user-query.json" -Dexec.cleanupDaemonThreads=false >> test-behavior-results.txt
echo "---------------------- profile query differences should only be timing ----------------------------"
diff test-profile-results.txt data/expected-test-profile-results.txt | grep Results
echo
echo "---------------------- behavior differences should only be timing ----------------------------"
diff test-behavior-results.txt data/expected-test-behavior-results.txt | grep Results
echo
if [ "$clean_test_artifacts" == true ]; then
harness delete $engine_1
harness delete $engine_2
fi
cd ..