Merge lp:~chrisvaughn/gearmand/devel into lp:gearmand/1.0

Proposed by Chris Vaughn
Status: Merged
Merge reported by: Brian Aker
Merged at revision: not available
Proposed branch: lp:~chrisvaughn/gearmand/devel
Merge into: lp:gearmand/1.0
Diff against target: 339 lines (+175/-26)
10 files modified
.bzrignore (+1/-0)
libgearman-server/plugins.cc (+6/-4)
libgearman-server/plugins/queue/postgres/include.am (+3/-1)
libgearman-server/plugins/queue/postgres/queue.cc (+6/-10)
libtest/has.cc (+11/-1)
libtest/has.hpp (+3/-1)
m4/have_libpq.m4 (+6/-2)
tests/ports.h (+2/-1)
tests/postgres.am (+15/-6)
tests/postgres_test.cc (+122/-0)
To merge this branch: bzr merge lp:~chrisvaughn/gearmand/devel
Reviewer Review Type Date Requested Status
Gearman-developers Pending
Review via email: mp+91571@code.launchpad.net

Description of the change

This branch resolves bug https://bugs.launchpad.net/gearmand/+bug/927006 as well as adds basic testing for Postgres queues.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-01-09 16:27:14 +0000
3+++ .bzrignore 2012-02-05 05:46:18 +0000
4@@ -86,6 +86,7 @@
5 tests/cpp_test
6 tests/cycle
7 tests/drizzle_test
8+tests/postgres_test
9 tests/gearadmin
10 tests/gearman.pi*
11 tests/gearman.sql
12
13=== modified file 'libgearman-server/plugins.cc'
14--- libgearman-server/plugins.cc 2011-11-29 05:21:54 +0000
15+++ libgearman-server/plugins.cc 2012-02-05 05:46:18 +0000
16@@ -1,5 +1,5 @@
17 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
18- *
19+ *
20 * Gearmand client and server library.
21 *
22 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
23@@ -63,9 +63,11 @@
24 queue::initialize_sqlite();
25 }
26
27-#ifdef HAVE_LIBPQ
28- queue::initialize_postgres();
29-#endif
30+ if (HAVE_LIBPQ)
31+ {
32+ queue::initialize_postgres();
33+ }
34+
35
36 #ifdef HAVE_LIBHIREDIS
37 queue::initialize_redis();
38
39=== modified file 'libgearman-server/plugins/queue/postgres/include.am'
40--- libgearman-server/plugins/queue/postgres/include.am 2011-08-16 21:55:47 +0000
41+++ libgearman-server/plugins/queue/postgres/include.am 2012-02-05 05:46:18 +0000
42@@ -12,7 +12,9 @@
43 noinst_HEADERS+= libgearman-server/plugins/queue/postgres/queue.h
44
45 if HAVE_LIBPQ
46+
47 libgearman_server_libgearman_server_la_SOURCES+= libgearman-server/plugins/queue/postgres/queue.cc
48-libgearman_server_libgearman_server_la_LIBADD+= $(LTLIBPQ)
49+libgearman_server_libgearman_server_la_LIBADD+= $(POSTGRESQL_LDFLAGS)
50+
51 endif
52
53
54=== modified file 'libgearman-server/plugins/queue/postgres/queue.cc'
55--- libgearman-server/plugins/queue/postgres/queue.cc 2011-06-22 04:02:56 +0000
56+++ libgearman-server/plugins/queue/postgres/queue.cc 2012-02-05 05:46:18 +0000
57@@ -17,13 +17,9 @@
58 #include <libgearman-server/plugins/queue/postgres/queue.h>
59 #include <libgearman-server/plugins/queue/base.h>
60
61-#if defined(HAVE_LIBPQ_FE_H)
62-# include <libpq-fe.h>
63-# include <pg_config_manual.h>
64-#else
65-# include <postgresql/libpq-fe.h>
66-# include <postgresql/pg_config_manual.h>
67-#endif
68+#include <postgresql/libpq-fe.h>
69+#include <postgresql/pg_config_manual.h>
70+
71
72 /**
73 * @addtogroup plugins::queue::Postgresatic Static libpq Queue Storage Definitions
74@@ -194,7 +190,7 @@
75 result= PQexec(queue->con, queue->create().c_str());
76 if (result == NULL || PQresultStatus(result) != PGRES_COMMAND_OK)
77 {
78- gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM,
79+ gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM,
80 "PQexec:%s", PQerrorMessage(queue->con));
81 PQclear(result);
82 gearman_server_set_queue(server, NULL, NULL, NULL, NULL, NULL);
83@@ -243,7 +239,7 @@
84 (char *)data,
85 (char *)when };
86
87- int param_lengths[]= {
88+ int param_lengths[]= {
89 (int)strlen(buffer),
90 (int)unique_size,
91 (int)function_name_size,
92@@ -254,7 +250,7 @@
93
94 gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, "libpq add: %.*s", (uint32_t)unique_size, (char *)unique);
95
96- PGresult *result= PQexecParams(queue->con, queue->insert().c_str(),
97+ PGresult *result= PQexecParams(queue->con, queue->insert().c_str(),
98 gearmand_array_size(param_lengths),
99 NULL, param_values, param_lengths, param_formats, 0);
100 if (result == NULL || PQresultStatus(result) != PGRES_COMMAND_OK)
101
102=== modified file 'libtest/has.cc'
103--- libtest/has.cc 2011-11-07 07:07:01 +0000
104+++ libtest/has.cc 2012-02-05 05:46:18 +0000
105@@ -1,5 +1,5 @@
106 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
107- *
108+ *
109 * libtest
110 *
111 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
112@@ -41,3 +41,13 @@
113
114 return false;
115 }
116+
117+bool has_postgres_support(void)
118+{
119+ if (HAVE_LIBPQ)
120+ {
121+ return true;
122+ }
123+
124+ return false;
125+}
126
127=== modified file 'libtest/has.hpp'
128--- libtest/has.hpp 2011-11-07 07:07:01 +0000
129+++ libtest/has.hpp 2012-02-05 05:46:18 +0000
130@@ -1,5 +1,5 @@
131 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
132- *
133+ *
134 * libtest
135 *
136 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
137@@ -24,3 +24,5 @@
138 bool has_memcached_support(void);
139
140 bool has_drizzle_support(void);
141+
142+bool has_postgres_support(void);
143
144=== modified file 'm4/have_libpq.m4'
145--- m4/have_libpq.m4 2012-01-18 06:28:31 +0000
146+++ m4/have_libpq.m4 2012-02-05 05:46:18 +0000
147@@ -3,13 +3,17 @@
148 AC_DEFUN([_SEARCH_LIBPQ],[
149 AC_REQUIRE([AX_LIB_POSTGRESQL])
150
151- AS_IF([test "x$found_postgresql" = "xyes"],[ ],
152+ AS_IF([test "x$found_postgresql" = "xyes"],
153+ [
154+ AC_DEFINE([HAVE_LIBPQ], [ 1 ], [Enable libpq support])
155+ ],
156 [
157 AC_DEFINE([HAVE_POSTGRESQL], [0], [If libpq is available])
158+ AC_DEFINE([HAVE_LIBPQ], [ 0 ], [Enable libpq support])
159 ac_cv_libpq="no"
160 ])
161
162- AM_CONDITIONAL(HAVE_LIBPQ, [test "x$ac_cv_lib_pq_main" = "xyes"])
163+ AM_CONDITIONAL(HAVE_LIBPQ, [test "x$ac_cv_libpq" = "xyes"])
164 ])
165
166 AC_DEFUN([AX_HAVE_LIBPQ],[
167
168=== modified file 'tests/ports.h'
169--- tests/ports.h 2012-01-09 16:27:14 +0000
170+++ tests/ports.h 2012-02-05 05:46:18 +0000
171@@ -1,5 +1,5 @@
172 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
173- *
174+ *
175 * Gearmand client and server library.
176 *
177 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
178@@ -55,4 +55,5 @@
179 #define EPHEMERAL_PORT GEARMAN_BASE_TEST_PORT +14
180 #define REDIS_PORT GEARMAN_BASE_TEST_PORT +15
181 #define HTTPD_PORT GEARMAN_BASE_TEST_PORT +16
182+#define POSTGRES_TEST_PORT GEARMAN_BASE_TEST_PORT +17
183 #define GEARMAN_MAX_TEST_PORT HTTPD_PORT
184
185=== modified file 'tests/postgres.am'
186--- tests/postgres.am 2012-01-09 16:27:14 +0000
187+++ tests/postgres.am 2012-02-05 05:46:18 +0000
188@@ -10,9 +10,18 @@
189 # All paths should be given relative to the root
190 #
191
192-test-postgres: tests-postgres-args
193-
194-tests-postgres-args: gearmand/gearmand
195-if HAVE_LIBPQ
196- @gearmand/gearmand --check-args --libpq-conninfo="foo" --libpq-table="gearmand"
197-endif
198+test-postgres: tests/postgres_test
199+ @tests/postgres_test
200+
201+gdb-postgres: tests/postgres_test
202+ @$(GDB_COMMAND) tests/postgres_test
203+
204+tests_postgres_test_SOURCES= \
205+ tests/basic.cc \
206+ tests/postgres_test.cc
207+tests_postgres_test_CXXFLAGS=
208+tests_postgres_test_DEPENDENCIES= ${CLIENT_LDADD} gearmand/gearmand
209+tests_postgres_test_LDADD= ${CLIENT_LDADD}
210+
211+check_PROGRAMS += tests/postgres_test
212+noinst_PROGRAMS += tests/postgres_test
213
214=== added file 'tests/postgres_test.cc'
215--- tests/postgres_test.cc 1970-01-01 00:00:00 +0000
216+++ tests/postgres_test.cc 2012-02-05 05:46:18 +0000
217@@ -0,0 +1,122 @@
218+/* Gearman server and library
219+ * Copyright (C) 2008 Brian Aker, Eric Day
220+ * All rights reserved.
221+ *
222+ * Use and distribution licensed under the BSD license. See
223+ * the COPYING file in the parent directory for full text.
224+ */
225+
226+#include <config.h>
227+#include <libtest/test.hpp>
228+
229+using namespace libtest;
230+
231+#include <cassert>
232+#include <cstdio>
233+#include <cstdlib>
234+#include <cstring>
235+#include <unistd.h>
236+
237+#include <libgearman/gearman.h>
238+
239+#include <tests/basic.h>
240+#include <tests/context.h>
241+
242+#include <tests/ports.h>
243+
244+#ifndef __INTEL_COMPILER
245+#pragma GCC diagnostic ignored "-Wold-style-cast"
246+#endif
247+
248+static test_return_t gearmand_basic_option_test(void *)
249+{
250+ const char *args[]= { "--check-args",
251+ "--queue-type=Postgres",
252+ "--libpq-conninfo=\"host=localhost port=5432 user=root dbname=gearman\"",
253+ "--libpq-table=gearman",
254+ 0 };
255+
256+ test_compare(EXIT_SUCCESS, exec_cmdline(gearmand_binary(), args, true));
257+
258+ return TEST_SUCCESS;
259+}
260+
261+static test_return_t collection_init(void *object)
262+{
263+ const char *argv[]= { "test_gearmand",
264+ "--queue-type=Postgres",
265+ "--libpq-conninfo=\"host=localhost port=5432 user=root dbname=gearman\"",
266+ "--libpq-table=gearman",
267+ 0 };
268+
269+ Context *test= (Context *)object;
270+ assert(test);
271+
272+ test_truth(test->initialize(4, argv));
273+
274+ return TEST_SUCCESS;
275+}
276+
277+static test_return_t collection_cleanup(void *object)
278+{
279+ Context *test= (Context *)object;
280+ test->reset();
281+
282+ return TEST_SUCCESS;
283+}
284+
285+
286+static void *world_create(server_startup_st& servers, test_return_t& error)
287+{
288+ if (has_postgres_support() == false)
289+ {
290+ error= TEST_SKIPPED;
291+ return NULL;
292+ }
293+
294+ Context *test= new Context(POSTGRES_TEST_PORT, servers);
295+ if (not test)
296+ {
297+ error= TEST_MEMORY_ALLOCATION_FAILURE;
298+ return NULL;
299+ }
300+
301+ return test;
302+}
303+
304+static bool world_destroy(void *object)
305+{
306+ Context *test= (Context *)object;
307+
308+ delete test;
309+
310+ return TEST_SUCCESS;
311+}
312+
313+test_st gearmand_basic_option_tests[] ={
314+ {"all options", 0, gearmand_basic_option_test },
315+ {0, 0, 0}
316+};
317+
318+test_st tests[] ={
319+ {"gearman_client_echo()", 0, client_echo_test },
320+ {"gearman_client_echo() fail", 0, client_echo_fail_test },
321+ {"gearman_worker_echo()", 0, worker_echo_test },
322+ {"clean", 0, queue_clean },
323+ {"add", 0, queue_add },
324+ {"worker", 0, queue_worker },
325+ {0, 0, 0}
326+};
327+
328+collection_st collection[] ={
329+ {"gearmand options", 0, 0, gearmand_basic_option_tests},
330+ {"postgres queue", collection_init, collection_cleanup, tests},
331+ {0, 0, 0, 0}
332+};
333+
334+void get_world(Framework *world)
335+{
336+ world->collections= collection;
337+ world->_create= world_create;
338+ world->_destroy= world_destroy;
339+}

Subscribers

People subscribed via source and target branches