drizzle_test.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #include "gear_config.h"
  9. #include <libtest/test.hpp>
  10. using namespace libtest;
  11. #include <cassert>
  12. #include <cstdio>
  13. #include <cstdlib>
  14. #include <cstring>
  15. #include <unistd.h>
  16. #include <libgearman/gearman.h>
  17. #include <tests/basic.h>
  18. #include <tests/context.h>
  19. #define WORKER_FUNCTION "drizzle_queue_test"
  20. #if defined(HAVE_LIBDRIZZLE) && HAVE_LIBDRIZZLE
  21. #include <libdrizzle-5.1/drizzle_client.h>
  22. #endif
  23. static in_port_t drizzled_port= 0;
  24. #ifndef __INTEL_COMPILER
  25. #pragma GCC diagnostic ignored "-Wold-style-cast"
  26. #endif
  27. static test_return_t gearmand_basic_option_test(void *)
  28. {
  29. const char *args[]= { "--check-args",
  30. "--libdrizzle-host=localhost",
  31. "--libdrizzle-port=90",
  32. "--libdrizzle-uds=tmp/foo.socket",
  33. "--libdrizzle-user=root",
  34. "--libdrizzle-password=test",
  35. "--libdrizzle-db=gearman",
  36. "--libdrizzle-table=gearman",
  37. "--libdrizzle-mysql",
  38. 0 };
  39. ASSERT_EQ(EXIT_SUCCESS, exec_cmdline(drizzled_binary(), args, true));
  40. return TEST_SUCCESS;
  41. }
  42. #pragma GCC diagnostic push
  43. #pragma GCC diagnostic ignored "-Wunreachable-code"
  44. static test_return_t collection_init(void *object)
  45. {
  46. Context *test= (Context *)object;
  47. assert(test);
  48. #if defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY
  49. drizzled_port= libtest::get_free_port();
  50. if (server_startup(test->_servers, "drizzled", drizzled_port, NULL) == false)
  51. {
  52. return TEST_SKIPPED;
  53. }
  54. #else
  55. drizzled_port= 0;
  56. #endif
  57. if (HAVE_LIBDRIZZLE)
  58. {
  59. if (libtest::ping_drizzled(drizzled_port) == false)
  60. {
  61. return TEST_FAILURE;
  62. }
  63. }
  64. char drizzled_server_string[1024];
  65. int length= snprintf(drizzled_server_string,
  66. sizeof(drizzled_server_string),
  67. "--libdrizzle-port=%d",
  68. int(drizzled_port));
  69. ASSERT_TRUE(length > 0);
  70. const char *argv[]= {
  71. drizzled_server_string,
  72. "--queue-type=libdrizzle",
  73. 0 };
  74. ASSERT_TRUE(test->initialize(argv));
  75. return TEST_SUCCESS;
  76. }
  77. #pragma GCC diagnostic pop
  78. static test_return_t collection_cleanup(void *object)
  79. {
  80. Context *test= (Context *)object;
  81. test->reset();
  82. return TEST_SUCCESS;
  83. }
  84. static void *world_create(server_startup_st& servers, test_return_t&)
  85. {
  86. SKIP_IF(HAVE_UUID_UUID_H != 1);
  87. SKIP_IF(has_drizzled() == false);
  88. return new Context(servers);
  89. }
  90. static bool world_destroy(void *object)
  91. {
  92. Context *test= (Context *)object;
  93. delete test;
  94. return TEST_SUCCESS;
  95. }
  96. test_st gearmand_basic_option_tests[] ={
  97. {"all options", 0, gearmand_basic_option_test },
  98. {0, 0, 0}
  99. };
  100. test_st tests[] ={
  101. {"gearman_client_echo()", 0, client_echo_test },
  102. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  103. {"gearman_worker_echo()", 0, worker_echo_test },
  104. {"clean", 0, queue_clean },
  105. {"add", 0, queue_add },
  106. {"worker", 0, queue_worker },
  107. {0, 0, 0}
  108. };
  109. test_st regressions[] ={
  110. {"lp:734663", 0, lp_734663 },
  111. {0, 0, 0}
  112. };
  113. collection_st collection[] ={
  114. {"drizzle queue", collection_init, collection_cleanup, tests},
  115. {"regressions", collection_init, collection_cleanup, regressions},
  116. {0, 0, 0, 0}
  117. };
  118. void get_world(libtest::Framework *world)
  119. {
  120. world->collections(collection);
  121. world->create(world_create);
  122. world->destroy(world_destroy);
  123. }