Merge lp:~clint-fewbar/gearmand/round-robin into lp:gearmand/1.0
- round-robin
- Merge into 1.0
Proposed by
Clint Byrum
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~clint-fewbar/gearmand/round-robin |
Merge into: | lp:gearmand/1.0 |
Diff against target: |
355 lines (+253/-1) (has conflicts) 4 files modified
.bzrignore (+2/-0) tests/include.am (+26/-1) tests/round_robin.c (+199/-0) tests/test_gearmand.c (+26/-0) Text conflict in tests/include.am |
To merge this branch: | bzr merge lp:~clint-fewbar/gearmand/round-robin |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gearman-developers | Pending | ||
Review via email: mp+19424@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Clint Byrum (clint-fewbar) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2010-01-26 05:53:44 +0000 | |||
3 | +++ .bzrignore 2010-02-16 17:23:15 +0000 | |||
4 | @@ -72,3 +72,5 @@ | |||
5 | 72 | tests/worker_test.res | 72 | tests/worker_test.res |
6 | 73 | tests/tokyocabinet_test | 73 | tests/tokyocabinet_test |
7 | 74 | tests/tokyocabinet_test.res | 74 | tests/tokyocabinet_test.res |
8 | 75 | tests/round_robin_test | ||
9 | 76 | tests/round_robin_test.res | ||
10 | 75 | 77 | ||
11 | === modified file 'tests/include.am' | |||
12 | --- tests/include.am 2010-02-10 01:48:52 +0000 | |||
13 | +++ tests/include.am 2010-02-16 17:23:16 +0000 | |||
14 | @@ -55,11 +55,20 @@ | |||
15 | 55 | tests_tokyocabinet_test_LDADD= ${TEST_LDADD} | 55 | tests_tokyocabinet_test_LDADD= ${TEST_LDADD} |
16 | 56 | 56 | ||
17 | 57 | noinst_PROGRAMS+= \ | 57 | noinst_PROGRAMS+= \ |
18 | 58 | <<<<<<< TREE | ||
19 | 58 | tests/client_test \ | 59 | tests/client_test \ |
20 | 59 | tests/cpp_test \ | 60 | tests/cpp_test \ |
21 | 60 | tests/internals_test \ | 61 | tests/internals_test \ |
22 | 61 | tests/regression_test \ | 62 | tests/regression_test \ |
23 | 62 | tests/worker_test | 63 | tests/worker_test |
24 | 64 | ======= | ||
25 | 65 | tests/client_test \ | ||
26 | 66 | tests/cpp_test \ | ||
27 | 67 | tests/internals_test \ | ||
28 | 68 | tests/regression_test \ | ||
29 | 69 | tests/round_robin_test \ | ||
30 | 70 | tests/worker_test | ||
31 | 71 | >>>>>>> MERGE-SOURCE | ||
32 | 63 | 72 | ||
33 | 64 | noinst_HEADERS+= \ | 73 | noinst_HEADERS+= \ |
34 | 65 | tests/test.h \ | 74 | tests/test.h \ |
35 | @@ -75,6 +84,9 @@ | |||
36 | 75 | tests_regression_test_SOURCES= tests/regression.c | 84 | tests_regression_test_SOURCES= tests/regression.c |
37 | 76 | tests_regression_test_LDADD= ${TEST_LDADD} libgearman/libgearmancore.la | 85 | tests_regression_test_LDADD= ${TEST_LDADD} libgearman/libgearmancore.la |
38 | 77 | 86 | ||
39 | 87 | tests_round_robin_test_SOURCES= tests/round_robin.c | ||
40 | 88 | tests_round_robin_test_LDADD= ${TEST_LDADD} libgearman/libgearmancore.la | ||
41 | 89 | |||
42 | 78 | tests_worker_test_SOURCES= tests/worker_test.c | 90 | tests_worker_test_SOURCES= tests/worker_test.c |
43 | 79 | tests_worker_test_LDADD= ${TEST_LDADD} | 91 | tests_worker_test_LDADD= ${TEST_LDADD} |
44 | 80 | 92 | ||
45 | @@ -85,6 +97,9 @@ | |||
46 | 85 | test-client: | 97 | test-client: |
47 | 86 | @tests/client_test $(ARG1) $(ARG2) | 98 | @tests/client_test $(ARG1) $(ARG2) |
48 | 87 | 99 | ||
49 | 100 | test-round-robin: | ||
50 | 101 | tests/round_robin_test $(ARG1) $(ARG2) | ||
51 | 102 | |||
52 | 88 | test-worker: | 103 | test-worker: |
53 | 89 | @tests/worker_test $(ARG1) $(ARG2) | 104 | @tests/worker_test $(ARG1) $(ARG2) |
54 | 90 | 105 | ||
55 | @@ -104,11 +119,14 @@ | |||
56 | 104 | $(TOKYOCABINET_TEST) $(ARG1) $(ARG2) | 119 | $(TOKYOCABINET_TEST) $(ARG1) $(ARG2) |
57 | 105 | $(TOKYOCABINET_RM) | 120 | $(TOKYOCABINET_RM) |
58 | 106 | 121 | ||
60 | 107 | check-local: test-client test-worker test-internals test-libmemcached test-sqlite test-tokyocabinet | 122 | check-local: test-client test-round-robin test-worker test-internals test-libmemcached test-sqlite test-tokyocabinet |
61 | 108 | 123 | ||
62 | 109 | gdb-client: ${noinst_PROGRAMS} | 124 | gdb-client: ${noinst_PROGRAMS} |
63 | 110 | $(LIBTOOL) --mode=execute gdb tests/client_test | 125 | $(LIBTOOL) --mode=execute gdb tests/client_test |
64 | 111 | 126 | ||
65 | 127 | gdb-round-robin: ${noinst_PROGRAMS} | ||
66 | 128 | $(LIBTOOL) --mode=execute gdb tests/round_robin_test | ||
67 | 129 | |||
68 | 112 | gdb-worker: ${noinst_PROGRAMS} | 130 | gdb-worker: ${noinst_PROGRAMS} |
69 | 113 | $(LIBTOOL) --mode=execute gdb tests/worker_test | 131 | $(LIBTOOL) --mode=execute gdb tests/worker_test |
70 | 114 | 132 | ||
71 | @@ -118,6 +136,9 @@ | |||
72 | 118 | valgrind-client: | 136 | valgrind-client: |
73 | 119 | $(VALGRIND_COMMAND) tests/client_test $(ARG1) $(ARG2) | 137 | $(VALGRIND_COMMAND) tests/client_test $(ARG1) $(ARG2) |
74 | 120 | 138 | ||
75 | 139 | valgrind-round-robin: | ||
76 | 140 | $(VALGRIND_COMMAND) tests/round_robin_test $(ARG1) $(ARG2) | ||
77 | 141 | |||
78 | 121 | valgrind-worker: | 142 | valgrind-worker: |
79 | 122 | $(VALGRIND_COMMAND) tests/worker_test $(ARG1) $(ARG2) | 143 | $(VALGRIND_COMMAND) tests/worker_test $(ARG1) $(ARG2) |
80 | 123 | 144 | ||
81 | @@ -137,6 +158,7 @@ | |||
82 | 137 | $(VALGRIND_COMMAND) $(TOKYOCABINET_TEST) $(ARG1) $(ARG2) | 158 | $(VALGRIND_COMMAND) $(TOKYOCABINET_TEST) $(ARG1) $(ARG2) |
83 | 138 | $(TOKYOCABINET_RM) | 159 | $(TOKYOCABINET_RM) |
84 | 139 | 160 | ||
85 | 161 | <<<<<<< TREE | ||
86 | 140 | GEARMAN_CLIENT_TEST= bin/gearman | 162 | GEARMAN_CLIENT_TEST= bin/gearman |
87 | 141 | GEARMAN_PIDFILE = ${abs_top_builddir}/tests/Xugear.pid | 163 | GEARMAN_PIDFILE = ${abs_top_builddir}/tests/Xugear.pid |
88 | 142 | 164 | ||
89 | @@ -148,3 +170,6 @@ | |||
90 | 148 | 170 | ||
91 | 149 | valgrind: ${noinst_PROGRAMS} valgrind-client valgrind-worker valgrind-internals valgrind-sqlite valgrind-tokyocabinetn | 171 | valgrind: ${noinst_PROGRAMS} valgrind-client valgrind-worker valgrind-internals valgrind-sqlite valgrind-tokyocabinetn |
92 | 150 | 172 | ||
93 | 173 | ======= | ||
94 | 174 | valgrind: ${noinst_PROGRAMS} valgrind-client valgrind-round-robin valgrind-worker valgrind-internals valgrind-sqlite valgrind-tokyocabinetn | ||
95 | 175 | >>>>>>> MERGE-SOURCE | ||
96 | 151 | 176 | ||
97 | === added file 'tests/round_robin.c' | |||
98 | --- tests/round_robin.c 1970-01-01 00:00:00 +0000 | |||
99 | +++ tests/round_robin.c 2010-02-16 17:23:16 +0000 | |||
100 | @@ -0,0 +1,199 @@ | |||
101 | 1 | /* Gearman server and library | ||
102 | 2 | * Copyright (C) 2008 Brian Aker, Eric Day | ||
103 | 3 | * All rights reserved. | ||
104 | 4 | * | ||
105 | 5 | * Use and distribution licensed under the BSD license. See | ||
106 | 6 | * the COPYING file in the parent directory for full text. | ||
107 | 7 | */ | ||
108 | 8 | |||
109 | 9 | #include "config.h" | ||
110 | 10 | |||
111 | 11 | #if defined(NDEBUG) | ||
112 | 12 | # undef NDEBUG | ||
113 | 13 | #endif | ||
114 | 14 | |||
115 | 15 | #include <assert.h> | ||
116 | 16 | #include <stdio.h> | ||
117 | 17 | #include <stdlib.h> | ||
118 | 18 | #include <string.h> | ||
119 | 19 | #include <unistd.h> | ||
120 | 20 | |||
121 | 21 | #include <libgearman/gearman.h> | ||
122 | 22 | #include "test.h" | ||
123 | 23 | #include "test_gearmand.h" | ||
124 | 24 | |||
125 | 25 | #define WORKER_TEST_PORT 32123 | ||
126 | 26 | |||
127 | 27 | typedef struct | ||
128 | 28 | { | ||
129 | 29 | pid_t gearmand_pid; | ||
130 | 30 | gearman_worker_st worker; | ||
131 | 31 | bool run_worker; | ||
132 | 32 | } worker_test_st; | ||
133 | 33 | |||
134 | 34 | /* Prototypes */ | ||
135 | 35 | test_return_t queue_add(void *object); | ||
136 | 36 | test_return_t queue_worker(void *object); | ||
137 | 37 | |||
138 | 38 | test_return_t pre(void *object); | ||
139 | 39 | test_return_t post(void *object); | ||
140 | 40 | |||
141 | 41 | void *world_create(test_return_t *error); | ||
142 | 42 | test_return_t world_destroy(void *object); | ||
143 | 43 | |||
144 | 44 | /* append test for worker */ | ||
145 | 45 | static void *append_function(gearman_job_st *job __attribute__((unused)), | ||
146 | 46 | void *context, size_t *result_size, | ||
147 | 47 | gearman_return_t *ret_ptr __attribute__((unused))) | ||
148 | 48 | { | ||
149 | 49 | /* this will will set the last char in the context (buffer) to the */ | ||
150 | 50 | /* first char of the work */ | ||
151 | 51 | char * buf = (char *)context; | ||
152 | 52 | char * work = (char *)gearman_job_workload(job); | ||
153 | 53 | buf += strlen(buf); | ||
154 | 54 | *buf = *work; | ||
155 | 55 | *result_size= 0; | ||
156 | 56 | return NULL; | ||
157 | 57 | } | ||
158 | 58 | |||
159 | 59 | test_return_t queue_add(void *object) | ||
160 | 60 | { | ||
161 | 61 | worker_test_st *test= (worker_test_st *)object; | ||
162 | 62 | gearman_client_st client; | ||
163 | 63 | char job_handle[GEARMAN_JOB_HANDLE_SIZE]; | ||
164 | 64 | |||
165 | 65 | uint8_t * value= (uint8_t *)strdup("0"); | ||
166 | 66 | size_t value_length= 1; | ||
167 | 67 | uint8_t i; | ||
168 | 68 | |||
169 | 69 | test->run_worker= false; | ||
170 | 70 | |||
171 | 71 | if (gearman_client_create(&client) == NULL) | ||
172 | 72 | return TEST_FAILURE; | ||
173 | 73 | |||
174 | 74 | if (gearman_client_add_server(&client, NULL, | ||
175 | 75 | WORKER_TEST_PORT) != GEARMAN_SUCCESS) | ||
176 | 76 | { | ||
177 | 77 | return TEST_FAILURE; | ||
178 | 78 | } | ||
179 | 79 | |||
180 | 80 | /* send strings "0", "1" ... "9" to alternating between 2 queues */ | ||
181 | 81 | /* queue1 = 1,3,5,7,9 */ | ||
182 | 82 | /* queue2 = 0,2,4,6,8 */ | ||
183 | 83 | for (i=0; i<10; i++) { | ||
184 | 84 | if (gearman_client_do_background(&client, i % 2 ? "queue1" : "queue2", NULL, value, | ||
185 | 85 | value_length, job_handle) != GEARMAN_SUCCESS) | ||
186 | 86 | { | ||
187 | 87 | return TEST_FAILURE; | ||
188 | 88 | } | ||
189 | 89 | *value = (uint8_t)(*value + 1); | ||
190 | 90 | } | ||
191 | 91 | |||
192 | 92 | gearman_client_free(&client); | ||
193 | 93 | free(value); | ||
194 | 94 | |||
195 | 95 | test->run_worker= true; | ||
196 | 96 | return TEST_SUCCESS; | ||
197 | 97 | } | ||
198 | 98 | |||
199 | 99 | test_return_t queue_worker(void *object) | ||
200 | 100 | { | ||
201 | 101 | worker_test_st *test= (worker_test_st *)object; | ||
202 | 102 | gearman_worker_st *worker= &(test->worker); | ||
203 | 103 | char buffer[11]; | ||
204 | 104 | int i; | ||
205 | 105 | memset(buffer, 0, 11); | ||
206 | 106 | |||
207 | 107 | if (!test->run_worker) | ||
208 | 108 | return TEST_FAILURE; | ||
209 | 109 | |||
210 | 110 | if (gearman_worker_add_function(worker, "queue1", 5, append_function, | ||
211 | 111 | buffer) != GEARMAN_SUCCESS) | ||
212 | 112 | { | ||
213 | 113 | return TEST_FAILURE; | ||
214 | 114 | } | ||
215 | 115 | |||
216 | 116 | if (gearman_worker_add_function(worker, "queue2", 5, append_function, | ||
217 | 117 | buffer) != GEARMAN_SUCCESS) | ||
218 | 118 | { | ||
219 | 119 | return TEST_FAILURE; | ||
220 | 120 | } | ||
221 | 121 | |||
222 | 122 | for (i=0; i<10; i++) { | ||
223 | 123 | if (gearman_worker_work(worker) != GEARMAN_SUCCESS) | ||
224 | 124 | return TEST_FAILURE; | ||
225 | 125 | } | ||
226 | 126 | |||
227 | 127 | // expect buffer to be reassembled in a predictable round robin order | ||
228 | 128 | if( strcmp(buffer, "1032547698") ) | ||
229 | 129 | { | ||
230 | 130 | fprintf(stderr, "\n\nexpecting 0123456789, got %s\n\n", buffer); | ||
231 | 131 | return TEST_FAILURE; | ||
232 | 132 | } | ||
233 | 133 | |||
234 | 134 | return TEST_SUCCESS; | ||
235 | 135 | } | ||
236 | 136 | |||
237 | 137 | |||
238 | 138 | void *world_create(test_return_t *error) | ||
239 | 139 | { | ||
240 | 140 | worker_test_st *test; | ||
241 | 141 | const char *argv[2]= { "test_gearmand", "--round-robin"}; | ||
242 | 142 | pid_t gearmand_pid; | ||
243 | 143 | |||
244 | 144 | gearmand_pid= test_gearmand_start(WORKER_TEST_PORT, NULL, (char **)argv, 2); | ||
245 | 145 | |||
246 | 146 | test= malloc(sizeof(worker_test_st)); | ||
247 | 147 | if (! test) | ||
248 | 148 | { | ||
249 | 149 | *error= TEST_MEMORY_ALLOCATION_FAILURE; | ||
250 | 150 | return NULL; | ||
251 | 151 | } | ||
252 | 152 | |||
253 | 153 | memset(test, 0, sizeof(worker_test_st)); | ||
254 | 154 | if (gearman_worker_create(&(test->worker)) == NULL) | ||
255 | 155 | { | ||
256 | 156 | *error= TEST_FAILURE; | ||
257 | 157 | return NULL; | ||
258 | 158 | } | ||
259 | 159 | |||
260 | 160 | if (gearman_worker_add_server(&(test->worker), NULL, WORKER_TEST_PORT) != GEARMAN_SUCCESS) | ||
261 | 161 | { | ||
262 | 162 | *error= TEST_FAILURE; | ||
263 | 163 | return NULL; | ||
264 | 164 | } | ||
265 | 165 | |||
266 | 166 | test->gearmand_pid= gearmand_pid; | ||
267 | 167 | |||
268 | 168 | *error= TEST_SUCCESS; | ||
269 | 169 | |||
270 | 170 | return (void *)test; | ||
271 | 171 | } | ||
272 | 172 | |||
273 | 173 | test_return_t world_destroy(void *object) | ||
274 | 174 | { | ||
275 | 175 | worker_test_st *test= (worker_test_st *)object; | ||
276 | 176 | gearman_worker_free(&(test->worker)); | ||
277 | 177 | test_gearmand_stop(test->gearmand_pid); | ||
278 | 178 | free(test); | ||
279 | 179 | |||
280 | 180 | return TEST_SUCCESS; | ||
281 | 181 | } | ||
282 | 182 | |||
283 | 183 | test_st tests[] ={ | ||
284 | 184 | {"add", 0, queue_add }, | ||
285 | 185 | {"worker", 0, queue_worker }, | ||
286 | 186 | {0, 0, 0} | ||
287 | 187 | }; | ||
288 | 188 | |||
289 | 189 | collection_st collection[] ={ | ||
290 | 190 | {"round_robin", 0, 0, tests}, | ||
291 | 191 | {0, 0, 0, 0} | ||
292 | 192 | }; | ||
293 | 193 | |||
294 | 194 | void get_world(world_st *world) | ||
295 | 195 | { | ||
296 | 196 | world->collections= collection; | ||
297 | 197 | world->create= world_create; | ||
298 | 198 | world->destroy= world_destroy; | ||
299 | 199 | } | ||
300 | 0 | 200 | ||
301 | === modified file 'tests/test_gearmand.c' | |||
302 | --- tests/test_gearmand.c 2010-01-28 21:45:14 +0000 | |||
303 | +++ tests/test_gearmand.c 2010-02-16 17:23:16 +0000 | |||
304 | @@ -46,6 +46,10 @@ | |||
305 | 46 | pid_t gearmand_pid; | 46 | pid_t gearmand_pid; |
306 | 47 | gearmand_st *gearmand; | 47 | gearmand_st *gearmand; |
307 | 48 | gearman_conf_st conf; | 48 | gearman_conf_st conf; |
308 | 49 | gearman_conf_module_st module; | ||
309 | 50 | const char *name; | ||
310 | 51 | const char *value; | ||
311 | 52 | bool round_robin= false; | ||
312 | 49 | 53 | ||
313 | 50 | gearmand_pid= fork(); | 54 | gearmand_pid= fork(); |
314 | 51 | assert(gearmand_pid != -1); | 55 | assert(gearmand_pid != -1); |
315 | @@ -74,12 +78,32 @@ | |||
316 | 74 | assert(ret == GEARMAN_SUCCESS); | 78 | assert(ret == GEARMAN_SUCCESS); |
317 | 75 | #endif | 79 | #endif |
318 | 76 | 80 | ||
319 | 81 | (void)gearman_conf_module_create(&conf, &module, NULL); | ||
320 | 82 | |||
321 | 83 | #ifndef MCO | ||
322 | 84 | #define MCO(__name, __short, __value, __help) \ | ||
323 | 85 | gearman_conf_module_add_option(&module, __name, __short, __value, __help); | ||
324 | 86 | #endif | ||
325 | 87 | |||
326 | 88 | MCO("round-robin", 'R', NULL, "Assign work in round-robin order per worker" | ||
327 | 89 | "connection. The default is to assign work in the order of functions " | ||
328 | 90 | "added by the worker.") | ||
329 | 91 | |||
330 | 77 | ret= gearman_conf_parse_args(&conf, argc, argv); | 92 | ret= gearman_conf_parse_args(&conf, argc, argv); |
331 | 78 | assert(ret == GEARMAN_SUCCESS); | 93 | assert(ret == GEARMAN_SUCCESS); |
332 | 79 | 94 | ||
333 | 95 | /* Check for option values that were given. */ | ||
334 | 96 | while (gearman_conf_module_value(&module, &name, &value)) | ||
335 | 97 | { | ||
336 | 98 | if (!strcmp(name, "round-robin")) | ||
337 | 99 | round_robin++; | ||
338 | 100 | } | ||
339 | 101 | |||
340 | 80 | gearmand= gearmand_create(NULL, port); | 102 | gearmand= gearmand_create(NULL, port); |
341 | 81 | assert(gearmand != NULL); | 103 | assert(gearmand != NULL); |
342 | 82 | 104 | ||
343 | 105 | gearmand_set_round_robin(gearmand, round_robin); | ||
344 | 106 | |||
345 | 83 | if (queue_type != NULL) | 107 | if (queue_type != NULL) |
346 | 84 | { | 108 | { |
347 | 85 | assert(argc); | 109 | assert(argc); |
348 | @@ -121,6 +145,8 @@ | |||
349 | 121 | } | 145 | } |
350 | 122 | } | 146 | } |
351 | 123 | 147 | ||
352 | 148 | |||
353 | 149 | |||
354 | 124 | ret= gearmand_run(gearmand); | 150 | ret= gearmand_run(gearmand); |
355 | 125 | assert(ret != GEARMAN_SUCCESS); | 151 | assert(ret != GEARMAN_SUCCESS); |
356 | 126 | 152 |
Adds tests for round-robin behavior