mysql_test.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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=MySQL",
  55. "--mysql-host=localhost",
  56. "--mysql-user=mysql",
  57. "--mysql-password=mysql",
  58. "--mysql-db=gearman",
  59. "--mysql-table=gearman",
  60. 0 };
  61. ASSERT_EQ(EXIT_SUCCESS, exec_cmdline(gearmand_binary(), args, true));
  62. return TEST_SUCCESS;
  63. }
  64. #pragma GCC diagnostic push
  65. #pragma GCC diagnostic ignored "-Wunreachable-code"
  66. static test_return_t collection_init(void *object)
  67. {
  68. return TEST_SKIPPED; // Just skip until YaTL has MySQL startup support
  69. const char *argv[]= {
  70. "--queue-type=MySQL",
  71. "--mysql-table=gearman",
  72. 0 };
  73. Context *test= (Context *)object;
  74. fatal_assert(test);
  75. ASSERT_TRUE(test->initialize(argv));
  76. return TEST_SUCCESS;
  77. }
  78. #pragma GCC diagnostic pop
  79. static test_return_t collection_cleanup(void *object)
  80. {
  81. Context *test= (Context *)object;
  82. test->reset();
  83. return TEST_SUCCESS;
  84. }
  85. static void *world_create(server_startup_st& servers, test_return_t&)
  86. {
  87. SKIP_IF(HAVE_UUID_UUID_H != 1);
  88. SKIP_IF(has_mysqld() == false);
  89. return new Context(servers);
  90. }
  91. static bool world_destroy(void *object)
  92. {
  93. Context *test= (Context *)object;
  94. delete test;
  95. return TEST_SUCCESS;
  96. }
  97. test_st gearmand_basic_option_tests[] ={
  98. {"all options", 0, gearmand_basic_option_test },
  99. {0, 0, 0}
  100. };
  101. test_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. collection_st collection[] ={
  111. {"gearmand options", 0, 0, gearmand_basic_option_tests},
  112. {"mysql queue", collection_init, collection_cleanup, tests},
  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. }