redis.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2013 Data Differential, http://datadifferential.com/
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are
  10. * met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following disclaimer
  17. * in the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * The names of its contributors may not be used to endorse or
  21. * promote products derived from this software without specific prior
  22. * written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. */
  37. #include "gear_config.h"
  38. #include <libtest/test.hpp>
  39. using namespace libtest;
  40. #include <cassert>
  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. #define WORKER_FUNCTION "hiredis_queue_test"
  49. #ifndef __INTEL_COMPILER
  50. #pragma GCC diagnostic ignored "-Wold-style-cast"
  51. #endif
  52. static test_return_t gearmand_basic_option_test(void *)
  53. {
  54. const char *args[]= { "--check-args",
  55. "--redis-server=localhost",
  56. "--redis-port=6379",
  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. SKIP_IF(true);
  64. Context *test= (Context *)object;
  65. assert(test);
  66. const char *argv[]= { "--queue-type=redis", 0 };
  67. test->initialize(argv);
  68. return TEST_SUCCESS;
  69. }
  70. static test_return_t collection_init_with_prefix(void *object)
  71. {
  72. SKIP_IF(true);
  73. Context *test= (Context *)object;
  74. assert(test);
  75. const char *argv[]= { "--queue-type=redis", "--redis-prefix=_prefix_", 0 };
  76. test->initialize(argv);
  77. return TEST_SUCCESS;
  78. }
  79. static test_return_t collection_cleanup(void *object)
  80. {
  81. Context *test= (Context *)object;
  82. test->reset();
  83. return TEST_SUCCESS;
  84. }
  85. #pragma GCC diagnostic push
  86. #pragma GCC diagnostic ignored "-Wunreachable-code"
  87. static bool test_for_HAVE_HIREDIS()
  88. {
  89. if (HAVE_HIREDIS)
  90. {
  91. return true;
  92. }
  93. return false;
  94. }
  95. #pragma GCC diagnostic pop
  96. static void *world_create(server_startup_st& servers, test_return_t&)
  97. {
  98. SKIP_IF(test_for_HAVE_HIREDIS() == false);
  99. return new Context(servers);
  100. }
  101. static bool world_destroy(void *object)
  102. {
  103. SKIP_IF(HAVE_UUID_UUID_H != 1);
  104. Context *test= (Context *)object;
  105. delete test;
  106. return TEST_SUCCESS;
  107. }
  108. test_st gearmand_basic_option_tests[] ={
  109. {"all options", 0, gearmand_basic_option_test },
  110. {0, 0, 0}
  111. };
  112. test_st tests[] ={
  113. {"gearman_client_echo()", 0, client_echo_test },
  114. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  115. {"gearman_worker_echo()", 0, worker_echo_test },
  116. {"clean", 0, queue_clean },
  117. {"add", 0, queue_add },
  118. {"worker", 0, queue_worker },
  119. {0, 0, 0}
  120. };
  121. test_st regressions[] ={
  122. {"lp:734663", 0, lp_734663 },
  123. {0, 0, 0}
  124. };
  125. collection_st collection[] ={
  126. {"gearmand redis options", 0, 0, gearmand_basic_option_tests},
  127. {"redis queue", collection_init, collection_cleanup, tests},
  128. {"redis queue with prefix", collection_init_with_prefix, collection_cleanup, tests},
  129. {"regressions", collection_init, collection_cleanup, regressions},
  130. {0, 0, 0, 0}
  131. };
  132. void get_world(libtest::Framework *world)
  133. {
  134. world->collections(collection);
  135. world->create(world_create);
  136. world->destroy(world_destroy);
  137. }