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
=== modified file '.bzrignore'
--- .bzrignore 2012-01-09 16:27:14 +0000
+++ .bzrignore 2012-02-05 05:46:18 +0000
@@ -86,6 +86,7 @@
86tests/cpp_test86tests/cpp_test
87tests/cycle87tests/cycle
88tests/drizzle_test88tests/drizzle_test
89tests/postgres_test
89tests/gearadmin90tests/gearadmin
90tests/gearman.pi*91tests/gearman.pi*
91tests/gearman.sql92tests/gearman.sql
9293
=== modified file 'libgearman-server/plugins.cc'
--- libgearman-server/plugins.cc 2011-11-29 05:21:54 +0000
+++ libgearman-server/plugins.cc 2012-02-05 05:46:18 +0000
@@ -1,5 +1,5 @@
1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 * 2 *
3 * Gearmand client and server library.3 * Gearmand client and server library.
4 *4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
@@ -63,9 +63,11 @@
63 queue::initialize_sqlite();63 queue::initialize_sqlite();
64 }64 }
6565
66#ifdef HAVE_LIBPQ66 if (HAVE_LIBPQ)
67 queue::initialize_postgres();67 {
68#endif68 queue::initialize_postgres();
69 }
70
6971
70#ifdef HAVE_LIBHIREDIS72#ifdef HAVE_LIBHIREDIS
71 queue::initialize_redis();73 queue::initialize_redis();
7274
=== modified file 'libgearman-server/plugins/queue/postgres/include.am'
--- libgearman-server/plugins/queue/postgres/include.am 2011-08-16 21:55:47 +0000
+++ libgearman-server/plugins/queue/postgres/include.am 2012-02-05 05:46:18 +0000
@@ -12,7 +12,9 @@
12noinst_HEADERS+= libgearman-server/plugins/queue/postgres/queue.h12noinst_HEADERS+= libgearman-server/plugins/queue/postgres/queue.h
1313
14if HAVE_LIBPQ14if HAVE_LIBPQ
15
15libgearman_server_libgearman_server_la_SOURCES+= libgearman-server/plugins/queue/postgres/queue.cc16libgearman_server_libgearman_server_la_SOURCES+= libgearman-server/plugins/queue/postgres/queue.cc
16libgearman_server_libgearman_server_la_LIBADD+= $(LTLIBPQ)17libgearman_server_libgearman_server_la_LIBADD+= $(POSTGRESQL_LDFLAGS)
18
17endif19endif
1820
1921
=== modified file 'libgearman-server/plugins/queue/postgres/queue.cc'
--- libgearman-server/plugins/queue/postgres/queue.cc 2011-06-22 04:02:56 +0000
+++ libgearman-server/plugins/queue/postgres/queue.cc 2012-02-05 05:46:18 +0000
@@ -17,13 +17,9 @@
17#include <libgearman-server/plugins/queue/postgres/queue.h>17#include <libgearman-server/plugins/queue/postgres/queue.h>
18#include <libgearman-server/plugins/queue/base.h>18#include <libgearman-server/plugins/queue/base.h>
1919
20#if defined(HAVE_LIBPQ_FE_H)20#include <postgresql/libpq-fe.h>
21# include <libpq-fe.h>21#include <postgresql/pg_config_manual.h>
22# include <pg_config_manual.h>22
23#else
24# include <postgresql/libpq-fe.h>
25# include <postgresql/pg_config_manual.h>
26#endif
2723
28/**24/**
29 * @addtogroup plugins::queue::Postgresatic Static libpq Queue Storage Definitions25 * @addtogroup plugins::queue::Postgresatic Static libpq Queue Storage Definitions
@@ -194,7 +190,7 @@
194 result= PQexec(queue->con, queue->create().c_str());190 result= PQexec(queue->con, queue->create().c_str());
195 if (result == NULL || PQresultStatus(result) != PGRES_COMMAND_OK)191 if (result == NULL || PQresultStatus(result) != PGRES_COMMAND_OK)
196 {192 {
197 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, 193 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM,
198 "PQexec:%s", PQerrorMessage(queue->con));194 "PQexec:%s", PQerrorMessage(queue->con));
199 PQclear(result);195 PQclear(result);
200 gearman_server_set_queue(server, NULL, NULL, NULL, NULL, NULL);196 gearman_server_set_queue(server, NULL, NULL, NULL, NULL, NULL);
@@ -243,7 +239,7 @@
243 (char *)data,239 (char *)data,
244 (char *)when };240 (char *)when };
245241
246 int param_lengths[]= { 242 int param_lengths[]= {
247 (int)strlen(buffer),243 (int)strlen(buffer),
248 (int)unique_size,244 (int)unique_size,
249 (int)function_name_size,245 (int)function_name_size,
@@ -254,7 +250,7 @@
254250
255 gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, "libpq add: %.*s", (uint32_t)unique_size, (char *)unique);251 gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, "libpq add: %.*s", (uint32_t)unique_size, (char *)unique);
256252
257 PGresult *result= PQexecParams(queue->con, queue->insert().c_str(), 253 PGresult *result= PQexecParams(queue->con, queue->insert().c_str(),
258 gearmand_array_size(param_lengths),254 gearmand_array_size(param_lengths),
259 NULL, param_values, param_lengths, param_formats, 0);255 NULL, param_values, param_lengths, param_formats, 0);
260 if (result == NULL || PQresultStatus(result) != PGRES_COMMAND_OK)256 if (result == NULL || PQresultStatus(result) != PGRES_COMMAND_OK)
261257
=== modified file 'libtest/has.cc'
--- libtest/has.cc 2011-11-07 07:07:01 +0000
+++ libtest/has.cc 2012-02-05 05:46:18 +0000
@@ -1,5 +1,5 @@
1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 * 2 *
3 * libtest3 * libtest
4 *4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
@@ -41,3 +41,13 @@
4141
42 return false;42 return false;
43}43}
44
45bool has_postgres_support(void)
46{
47 if (HAVE_LIBPQ)
48 {
49 return true;
50 }
51
52 return false;
53}
4454
=== modified file 'libtest/has.hpp'
--- libtest/has.hpp 2011-11-07 07:07:01 +0000
+++ libtest/has.hpp 2012-02-05 05:46:18 +0000
@@ -1,5 +1,5 @@
1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 * 2 *
3 * libtest3 * libtest
4 *4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
@@ -24,3 +24,5 @@
24bool has_memcached_support(void);24bool has_memcached_support(void);
2525
26bool has_drizzle_support(void);26bool has_drizzle_support(void);
27
28bool has_postgres_support(void);
2729
=== modified file 'm4/have_libpq.m4'
--- m4/have_libpq.m4 2012-01-18 06:28:31 +0000
+++ m4/have_libpq.m4 2012-02-05 05:46:18 +0000
@@ -3,13 +3,17 @@
3AC_DEFUN([_SEARCH_LIBPQ],[3AC_DEFUN([_SEARCH_LIBPQ],[
4 AC_REQUIRE([AX_LIB_POSTGRESQL])4 AC_REQUIRE([AX_LIB_POSTGRESQL])
55
6 AS_IF([test "x$found_postgresql" = "xyes"],[ ],6 AS_IF([test "x$found_postgresql" = "xyes"],
7 [
8 AC_DEFINE([HAVE_LIBPQ], [ 1 ], [Enable libpq support])
9 ],
7 [10 [
8 AC_DEFINE([HAVE_POSTGRESQL], [0], [If libpq is available])11 AC_DEFINE([HAVE_POSTGRESQL], [0], [If libpq is available])
12 AC_DEFINE([HAVE_LIBPQ], [ 0 ], [Enable libpq support])
9 ac_cv_libpq="no"13 ac_cv_libpq="no"
10 ])14 ])
1115
12 AM_CONDITIONAL(HAVE_LIBPQ, [test "x$ac_cv_lib_pq_main" = "xyes"])16 AM_CONDITIONAL(HAVE_LIBPQ, [test "x$ac_cv_libpq" = "xyes"])
13 ])17 ])
1418
15AC_DEFUN([AX_HAVE_LIBPQ],[19AC_DEFUN([AX_HAVE_LIBPQ],[
1620
=== modified file 'tests/ports.h'
--- tests/ports.h 2012-01-09 16:27:14 +0000
+++ tests/ports.h 2012-02-05 05:46:18 +0000
@@ -1,5 +1,5 @@
1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 * 2 *
3 * Gearmand client and server library.3 * Gearmand client and server library.
4 *4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
@@ -55,4 +55,5 @@
55#define EPHEMERAL_PORT GEARMAN_BASE_TEST_PORT +1455#define EPHEMERAL_PORT GEARMAN_BASE_TEST_PORT +14
56#define REDIS_PORT GEARMAN_BASE_TEST_PORT +1556#define REDIS_PORT GEARMAN_BASE_TEST_PORT +15
57#define HTTPD_PORT GEARMAN_BASE_TEST_PORT +1657#define HTTPD_PORT GEARMAN_BASE_TEST_PORT +16
58#define POSTGRES_TEST_PORT GEARMAN_BASE_TEST_PORT +17
58#define GEARMAN_MAX_TEST_PORT HTTPD_PORT59#define GEARMAN_MAX_TEST_PORT HTTPD_PORT
5960
=== modified file 'tests/postgres.am'
--- tests/postgres.am 2012-01-09 16:27:14 +0000
+++ tests/postgres.am 2012-02-05 05:46:18 +0000
@@ -10,9 +10,18 @@
10# All paths should be given relative to the root10# All paths should be given relative to the root
11#11#
1212
13test-postgres: tests-postgres-args13test-postgres: tests/postgres_test
1414 @tests/postgres_test
15tests-postgres-args: gearmand/gearmand15
16if HAVE_LIBPQ16gdb-postgres: tests/postgres_test
17 @gearmand/gearmand --check-args --libpq-conninfo="foo" --libpq-table="gearmand"17 @$(GDB_COMMAND) tests/postgres_test
18endif18
19tests_postgres_test_SOURCES= \
20 tests/basic.cc \
21 tests/postgres_test.cc
22tests_postgres_test_CXXFLAGS=
23tests_postgres_test_DEPENDENCIES= ${CLIENT_LDADD} gearmand/gearmand
24tests_postgres_test_LDADD= ${CLIENT_LDADD}
25
26check_PROGRAMS += tests/postgres_test
27noinst_PROGRAMS += tests/postgres_test
1928
=== added file 'tests/postgres_test.cc'
--- tests/postgres_test.cc 1970-01-01 00:00:00 +0000
+++ tests/postgres_test.cc 2012-02-05 05:46:18 +0000
@@ -0,0 +1,122 @@
1/* Gearman server and library
2 * Copyright (C) 2008 Brian Aker, Eric Day
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 */
8
9#include <config.h>
10#include <libtest/test.hpp>
11
12using namespace libtest;
13
14#include <cassert>
15#include <cstdio>
16#include <cstdlib>
17#include <cstring>
18#include <unistd.h>
19
20#include <libgearman/gearman.h>
21
22#include <tests/basic.h>
23#include <tests/context.h>
24
25#include <tests/ports.h>
26
27#ifndef __INTEL_COMPILER
28#pragma GCC diagnostic ignored "-Wold-style-cast"
29#endif
30
31static test_return_t gearmand_basic_option_test(void *)
32{
33 const char *args[]= { "--check-args",
34 "--queue-type=Postgres",
35 "--libpq-conninfo=\"host=localhost port=5432 user=root dbname=gearman\"",
36 "--libpq-table=gearman",
37 0 };
38
39 test_compare(EXIT_SUCCESS, exec_cmdline(gearmand_binary(), args, true));
40
41 return TEST_SUCCESS;
42}
43
44static test_return_t collection_init(void *object)
45{
46 const char *argv[]= { "test_gearmand",
47 "--queue-type=Postgres",
48 "--libpq-conninfo=\"host=localhost port=5432 user=root dbname=gearman\"",
49 "--libpq-table=gearman",
50 0 };
51
52 Context *test= (Context *)object;
53 assert(test);
54
55 test_truth(test->initialize(4, argv));
56
57 return TEST_SUCCESS;
58}
59
60static test_return_t collection_cleanup(void *object)
61{
62 Context *test= (Context *)object;
63 test->reset();
64
65 return TEST_SUCCESS;
66}
67
68
69static void *world_create(server_startup_st& servers, test_return_t& error)
70{
71 if (has_postgres_support() == false)
72 {
73 error= TEST_SKIPPED;
74 return NULL;
75 }
76
77 Context *test= new Context(POSTGRES_TEST_PORT, servers);
78 if (not test)
79 {
80 error= TEST_MEMORY_ALLOCATION_FAILURE;
81 return NULL;
82 }
83
84 return test;
85}
86
87static bool world_destroy(void *object)
88{
89 Context *test= (Context *)object;
90
91 delete test;
92
93 return TEST_SUCCESS;
94}
95
96test_st gearmand_basic_option_tests[] ={
97 {"all options", 0, gearmand_basic_option_test },
98 {0, 0, 0}
99};
100
101test_st tests[] ={
102 {"gearman_client_echo()", 0, client_echo_test },
103 {"gearman_client_echo() fail", 0, client_echo_fail_test },
104 {"gearman_worker_echo()", 0, worker_echo_test },
105 {"clean", 0, queue_clean },
106 {"add", 0, queue_add },
107 {"worker", 0, queue_worker },
108 {0, 0, 0}
109};
110
111collection_st collection[] ={
112 {"gearmand options", 0, 0, gearmand_basic_option_tests},
113 {"postgres queue", collection_init, collection_cleanup, tests},
114 {0, 0, 0, 0}
115};
116
117void get_world(Framework *world)
118{
119 world->collections= collection;
120 world->_create= world_create;
121 world->_destroy= world_destroy;
122}

Subscribers

People subscribed via source and target branches