postgres_test.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011 Data Differential, http://datadifferential.com/
  6. * Copyright (C) 2008 Brian Aker, Eric Day
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are
  11. * met:
  12. *
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * * Redistributions in binary form must reproduce the above
  17. * copyright notice, this list of conditions and the following disclaimer
  18. * in the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * * The names of its contributors may not be used to endorse or
  22. * promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. */
  38. #include "gear_config.h"
  39. #include <libtest/test.hpp>
  40. using namespace libtest;
  41. #include <cstdio>
  42. #include <cstdlib>
  43. #include <cstring>
  44. #include <unistd.h>
  45. #include <libgearman/gearman.h>
  46. #include <tests/basic.h>
  47. #include <tests/context.h>
  48. #ifndef __INTEL_COMPILER
  49. #pragma GCC diagnostic ignored "-Wold-style-cast"
  50. #endif
  51. static test_return_t gearmand_basic_option_test(void *)
  52. {
  53. const char *args[]= { "--check-args",
  54. "--queue-type=Postgres",
  55. "--libpq-conninfo", "host=localhost dbname=gearman",
  56. "--libpq-table=gearman",
  57. 0 };
  58. ASSERT_EQ(EXIT_SUCCESS, exec_cmdline(gearmand_binary(), args, true));
  59. return TEST_SUCCESS;
  60. }
  61. static test_return_t collection_init(void *object)
  62. {
  63. const char *argv[]= {
  64. "--queue-type=Postgres",
  65. "--libpq-conninfo", "host=localhost dbname=gearman",
  66. "--libpq-table=gearman",
  67. 0 };
  68. Context *test= (Context *)object;
  69. fatal_assert(test);
  70. ASSERT_TRUE(test->initialize(argv));
  71. return TEST_SUCCESS;
  72. }
  73. static test_return_t collection_cleanup(void *object)
  74. {
  75. Context *test= (Context *)object;
  76. test->reset();
  77. return TEST_SUCCESS;
  78. }
  79. static void *world_create(server_startup_st& servers, test_return_t&)
  80. {
  81. SKIP_IF(HAVE_UUID_UUID_H != 1);
  82. SKIP_IF(has_postgres_support() == false);
  83. return new Context(servers);
  84. }
  85. static bool world_destroy(void *object)
  86. {
  87. Context *test= (Context *)object;
  88. delete test;
  89. return TEST_SUCCESS;
  90. }
  91. test_st gearmand_basic_option_tests[] ={
  92. {"all options", 0, gearmand_basic_option_test },
  93. {0, 0, 0}
  94. };
  95. test_st tests[] ={
  96. {"gearman_client_echo()", 0, client_echo_test },
  97. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  98. {"gearman_worker_echo()", 0, worker_echo_test },
  99. {"clean", 0, queue_clean },
  100. {"add", 0, queue_add },
  101. {"worker", 0, queue_worker },
  102. {0, 0, 0}
  103. };
  104. collection_st collection[] ={
  105. {"gearmand options", 0, 0, gearmand_basic_option_tests},
  106. {"postgres queue", collection_init, collection_cleanup, tests},
  107. {0, 0, 0, 0}
  108. };
  109. void get_world(libtest::Framework *world)
  110. {
  111. world->collections(collection);
  112. world->create(world_create);
  113. world->destroy(world_destroy);
  114. }