drizzle_test.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. static test_return_t collection_init(void *object)
  43. {
  44. Context *test= (Context *)object;
  45. assert(test);
  46. #if defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY
  47. drizzled_port= libtest::get_free_port();
  48. if (server_startup(test->_servers, "drizzled", drizzled_port, NULL) == false)
  49. {
  50. return TEST_SKIPPED;
  51. }
  52. #else
  53. drizzled_port= 0;
  54. #endif
  55. if (HAVE_LIBDRIZZLE)
  56. {
  57. if (libtest::ping_drizzled(drizzled_port) == false)
  58. {
  59. return TEST_FAILURE;
  60. }
  61. }
  62. char drizzled_server_string[1024];
  63. int length= snprintf(drizzled_server_string,
  64. sizeof(drizzled_server_string),
  65. "--libdrizzle-port=%d",
  66. int(drizzled_port));
  67. test_true(length > 0);
  68. const char *argv[]= {
  69. drizzled_server_string,
  70. "--queue-type=libdrizzle",
  71. 0 };
  72. test_truth(test->initialize(argv));
  73. return TEST_SUCCESS;
  74. }
  75. static test_return_t collection_cleanup(void *object)
  76. {
  77. Context *test= (Context *)object;
  78. test->reset();
  79. return TEST_SUCCESS;
  80. }
  81. static void *world_create(server_startup_st& servers, test_return_t&)
  82. {
  83. SKIP_IF(HAVE_UUID_UUID_H != 1);
  84. SKIP_IF(has_drizzled() == false);
  85. return new Context(default_port(), servers);
  86. }
  87. static bool world_destroy(void *object)
  88. {
  89. Context *test= (Context *)object;
  90. delete test;
  91. return TEST_SUCCESS;
  92. }
  93. test_st gearmand_basic_option_tests[] ={
  94. {"all options", 0, gearmand_basic_option_test },
  95. {0, 0, 0}
  96. };
  97. test_st tests[] ={
  98. {"gearman_client_echo()", 0, client_echo_test },
  99. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  100. {"gearman_worker_echo()", 0, worker_echo_test },
  101. {"clean", 0, queue_clean },
  102. {"add", 0, queue_add },
  103. {"worker", 0, queue_worker },
  104. {0, 0, 0}
  105. };
  106. test_st regressions[] ={
  107. {"lp:734663", 0, lp_734663 },
  108. {0, 0, 0}
  109. };
  110. collection_st collection[] ={
  111. {"drizzle queue", collection_init, collection_cleanup, tests},
  112. {"regressions", collection_init, collection_cleanup, regressions},
  113. {0, 0, 0, 0}
  114. };
  115. void get_world(libtest::Framework *world)
  116. {
  117. world->collections(collection);
  118. world->create(world_create);
  119. world->destroy(world_destroy);
  120. }