-
Notifications
You must be signed in to change notification settings - Fork 45
/
test_client.php
335 lines (282 loc) · 10.2 KB
/
test_client.php
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
/*
* Gearman PHP Extension
*
* Copyright (C) 2008 James M. Luedke <[email protected]>,
* Eric Day <[email protected]>
* All rights reserved.
*
* Use and distribution licensed under the PHP license. See
* the LICENSE file in this directory for full text.
*/
/* client */
echo "# TESTING CLIENT INTERFACE\n";
$client = gearman_client_create();
if (! is_object($client))
{
echo "gearman_client_create() FAILED\n";
exit(0);
}
else
echo "gearman_client_create() pass\n";
/*
$client_new = gearman_client_clone($client);
if (! is_object($client_new))
{
echo "gearman_client_clone() FAILED\n";
exit(0);
}
else
echo "gearman_client_clone() pass\n";
unset($client_new);
echo "unset client pass\n";
*/
$ret= gearman_client_error($client);
if ($ret != GEARMAN_SUCCESS)
{
echo "gearman_client_error() FAILED\n";
exit(0);
}
else
echo "gearman_client_error() pass\n";
$ret= gearman_client_get_errno($client);
if ($ret != 0)
{
echo "gearman_client_get_errno() FAILED\n";
exit(0);
}
else
echo "gearman_client_get_errno() pass\n";
if (! gearman_client_add_options($client, GEARMAN_CLIENT_UNBUFFERED_RESULT))
{
echo "gearman_client_set_options() FAILED\n";
exit(0);
}
gearman_client_remove_options($client, GEARMAN_CLIENT_UNBUFFERED_RESULT);
echo "gearman_client_set_options() pass\n";
/*
if (! gearman_client_add_server($client))
{
echo "gearman_client_add_server() FAILED\n";
exit(0);
}
echo "gearman_client_add_server() pass\n";
*/
if (! gearman_client_add_servers($client, "127.0.0.1:4730"))
{
echo "gearman_client_add_servers() FAILED\n";
exit(0);
}
echo "gearman_client_add_servers() pass\n";
$value = gearman_client_do_normal($client, "test_worker", "gearman_client_do");
if ($client->returnCode() != GEARMAN_SUCCESS)
{
echo "gearman_client_do_normal() FAILED\n";
exit(0);
}
else
echo "gearman_client_do_normal() pass -> $value\n";
$job_handle = gearman_client_do_background($client, "test_worker", "gearman_client_do_background");
if ($client->returnCode() != GEARMAN_SUCCESS)
{
echo "gearman_client_do_background() FAILED\n";
exit(0);
}
else
echo "gearman_client_do_background() pass -> $job_handle\n";
$value = gearman_client_do_high($client, "test_worker", "gearman_client_do_high");
if ($client->returnCode() != GEARMAN_SUCCESS)
{
echo "gearman_client_do_high() FAILED\n";
exit(0);
}
else
echo "gearman_client_do_high() pass -> $value\n";
$value = gearman_client_do_low($client, "test_worker", "gearman_client_do_low");
if ($client->returnCode() != GEARMAN_SUCCESS)
{
echo "gearman_client_do_low() FAILED\n";
exit(0);
}
else
echo "gearman_client_do_low() pass -> $value\n";
$value = gearman_client_do_high_background($client, "test_worker", "gearman_client_do_high_background");
if ($client->returnCode() != GEARMAN_SUCCESS)
{
echo "gearman_client_do_high_background() FAILED\n";
exit(0);
}
else
echo "gearman_client_do_high_background() pass -> $value\n";
$value = gearman_client_do_low_background($client, "test_worker", "gearman_client_do_low_background");
if ($client->returnCode() != GEARMAN_SUCCESS)
{
echo "gearman_client_do_low_background() FAILED\n";
exit(0);
}
else
echo "gearman_client_do_low_background() pass -> $value\n";
$job_handle = gearman_client_do_background($client, "test_gearman_job_status", "test_gearman_job_status");
if ($client->returnCode() != GEARMAN_SUCCESS)
{
echo "gearman_client_do_background() FAILED -> while checking status\n";
exit(0);
}
sleep(1);
list($is_known, $is_running, $numerator, $denominator) = gearman_client_job_status($client, $job_handle);
if ($client->returnCode() != GEARMAN_SUCCESS || ! $is_known || ! $is_running || ! $numerator || ! $denominator)
{
echo "gearman_client_job_status() FAILED\n";
}
else
echo "gearman_client_job_status() pass -> is_known: $is_known is_running: $is_running $numerator / $denominator\n";
if ($job_handle != gearman_client_do_job_handle($client))
{
echo "gearman_client_do_job_handle() FAILED\n";
exit(0);
}
else
echo "gearman_client_do_job_handle() pass -> $job_handle\n";
gearman_client_ping($client, "gearman_client_ping");
echo "gearman_client_ping() pass\n";
gearman_client_add_task($client, "test_gearman_job", "test_gearman_job", "test_gearman_job");
echo "gearman_client_add_task() pass\n";
/* run a task see if they all work */
$res = gearman_client_run_tasks($client);
echo "gearman_client_run_tasks() pass\n";
/* clear all the callbacks so they dont mess with other test */
gearman_client_clear_callbacks($client);
echo "gearman_client_clear_callbacks() pass\n";
/* set all of our callback functions */
/*
gearman_client_set_workload_fn($client, "test_gearman_client_set_workload_fn");
echo "gearman_client_set_workload_fn() pass\n";
*/
gearman_client_set_created_callback($client, "test_gearman_client_set_created_callback");
// XXX gearman_client_set_data_fn($client, "test_gearman_client_set_data_fn");
gearman_client_set_warning_callback($client, "test_gearman_client_set_warning_callback");
gearman_client_set_status_callback($client, "test_gearman_client_set_status_callback");
gearman_client_set_complete_callback($client, "test_gearman_client_set_complete_callback");
gearman_client_set_exception_callback($client, "test_gearman_client_set_exception_callback");
gearman_client_set_fail_callback($client, "test_gearman_client_set_fail_callback");
gearman_client_add_task($client, "test_set_callback_callback", "test_set_callback_callback", "test_set_callback_callback");
/* run a task see if they all work */
$res = gearman_client_run_tasks($client);
// gearman_client_clear_fn($client);
/* test tasks interface */
gearman_client_clear_callback($client);
gearman_client_set_complete_callback($client, "test_gearman_tasks");
gearman_client_add_task($client, "test_tasks", "test_tasks", "test_tasks");
$res = gearman_client_run_tasks($client);
gearman_client_clear_callback($client);
# You can turn off auto task destruction by unsetting this flag on a gearman client.
gearman_client_remove_options($client, GEARMAN_CLIENT_FREE_TASKS);
$task = gearman_client_add_task_background($client, "test_tasks_background", "test_tasks_background", "test_tasks_background");
gearman_client_set_status_callback($client, "test_gearman_task_status");
$res = gearman_client_run_tasks($client);
$job_handle = gearman_task_job_handle($task);
gearman_client_add_task_status($client, $job_handle);
echo "\tgearman_client_add_task_status() pass\n";
$res = gearman_client_run_tasks($client);
function test_gearman_task_status($task)
{
$is_known = gearman_task_is_known($task);
if ($is_known)
echo "\tgearman_task_is_known() pass\n";
else
echo "\tgearman_task_is_known() FAILED\n";
sleep(1);
$is_running = gearman_task_is_running($task);
if ($is_running)
echo "\tgearman_task_is_running() pass\n";
else
echo "\tgearman_task_is_running() pass\n";
}
echo "gearman_client_add_task_background() pass\n";
gearman_client_clear_callback($client);
gearman_client_add_task_high($client, "test_tasks_high", "test_tasks_high", "test_tasks_high");
echo "gearman_client_add_task_high() pass\n";
gearman_client_add_task_low($client, "test_tasks_low", "test_tasks_low", "test_tasks_low");
echo "gearman_client_add_task_low() pass\n";
gearman_client_add_task_high_background($client, "test_tasks_high_background", "test_tasks_high_background", "test_tasks_high_background");
echo "gearman_client_add_task_high_background() pass\n";
gearman_client_add_task_low_background($client, "test_tasks_low_background", "test_tasks_low_background", "test_tasks_low_background");
echo "gearman_client_add_task_low_background() pass\n";
$res = gearman_client_run_tasks($client);
/* XXX add task high seems to break things
*/
$value = gearman_client_do($client, "exit_test", "exit_test");
echo "DONE $ret\n";
/* XXX does not seem to call cb as i would expect
$data = "gearman_job_exception";
gearman_client_add_task($client, "test_gearman_job_exception", $data, NULL);
$data = "gearman_job_fail";
gearman_client_add_task($client, "test_gearman_job_fail", $data, NULL);
*/
/* XXX can not test till I have the gearman low level functions done
$task_new = gearman_task_create();
gearman_task_fn_arg($task_new);
echo "gearman_task_fn_arg() pass\n";
*/
/*
* Test Functions
*/
function test_gearman_client_set_fail_callback($task)
{
echo "\tgearman_client_set_fail_callback() pass\n";
}
function test_gearman_client_set_exception_callback($task)
{
echo "\tgearman_client_set_exception_callback() pass\n";
}
function test_gearman_client_set_complete_callback($task)
{
echo "\tgearman_client_set_complete_callback() pass\n";
}
function test_gearman_client_set_status_callback($task)
{
echo "\tgearman_client_set_status_callback() pass\n";
}
function test_gearman_client_set_warning_callback($task)
{
echo "\tgearman_client_set_warning_callback() pass\n";
}
function test_gearman_client_set_data_callback($task)
{
echo "\tgearman_client_set_data_callback() pass\n";
}
function test_gearman_client_set_created_callback($task)
{
echo "\tgearman_client_set_created_callback() pass\n";
}
function test_gearman_client_set_workload_callback($task)
{
echo "\tgearman_client_set_workload_callback() pass\n";
}
function test_gearman_tasks($task)
{
$is_known= false;
$is_running= false;
echo "Testing Task Functions\n";
$func = gearman_task_function_name($task);
echo "\tgearman_task_function_name() pass - $func\n";
$uuid = gearman_task_unique($task);
echo "\tgearman_task_unique() pass - $uuid\n";
$job_handle = gearman_task_job_handle($task);
echo "\tgearman_task_job_handle() pass - $job_handle\n";
$numerator = gearman_task_numerator($task);
echo "\tgearman_task_numerator() pass - $numerator\n";
$denominator = gearman_task_denominator($task);
echo "\tgearman_task_denominator() pass - $denominator\n";
$data = gearman_task_data($task);
echo "\tgearman_task_data() pass - $data\n";
$data_size = gearman_task_data_size($task);
echo "\tgearman_task_data_size() pass - $data_size\n";
/* XXX Not sure how to test task data yet
gearman_task_take_data($task);
echo "gearman_task_take_data() pass\n";
gearman_task_send_data()
gearman_task_recv_data()
*/
}
?>