memcached_test.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 <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. #include <tests/ports.h>
  20. #ifndef __INTEL_COMPILER
  21. #pragma GCC diagnostic ignored "-Wold-style-cast"
  22. #endif
  23. static bool test_for_HAVE_LIBMEMCACHED(test_return_t &error)
  24. {
  25. #ifdef test_for_HAVE_LIBMEMCACHED
  26. error= TEST_SUCCESS;
  27. return true;
  28. #else
  29. error= TEST_SKIPPED;
  30. return false;
  31. #endif
  32. }
  33. static test_return_t gearmand_basic_option_test(void *)
  34. {
  35. const char *args[]= { "--queue=libmemcached", "--libmemcached-servers=localhost:12555", "--check-args", 0 };
  36. test_success(exec_cmdline(GEARMAND_BINARY, args));
  37. return TEST_SUCCESS;
  38. }
  39. static test_return_t collection_init(void *object)
  40. {
  41. const char *argv[3]= { "test_gearmand", "--libmemcached-servers=localhost:12555", "--queue-type=libmemcached" };
  42. Context *test= (Context *)object;
  43. assert(test);
  44. test_truth(test->initialize(3, argv));
  45. return TEST_SUCCESS;
  46. }
  47. static test_return_t collection_cleanup(void *object)
  48. {
  49. Context *test= (Context *)object;
  50. test->reset();
  51. return TEST_SUCCESS;
  52. }
  53. static void *world_create(server_startup_st& servers, test_return_t& error)
  54. {
  55. if (not test_for_HAVE_LIBMEMCACHED(error))
  56. {
  57. return NULL;
  58. }
  59. if (not server_startup(servers, "memcached", 12555, 0, NULL))
  60. {
  61. error= TEST_FAILURE;
  62. return NULL;
  63. }
  64. Context *test= new Context(MEMCACHED_TEST_PORT, servers);
  65. if (not test)
  66. {
  67. error= TEST_MEMORY_ALLOCATION_FAILURE;
  68. return NULL;
  69. }
  70. return test;
  71. }
  72. static bool world_destroy(void *object)
  73. {
  74. Context *test= (Context *)object;
  75. delete test;
  76. return TEST_SUCCESS;
  77. }
  78. test_st gearmand_basic_option_tests[] ={
  79. {"--queue=libmemcached --libmemcached-servers=", 0, gearmand_basic_option_test },
  80. {0, 0, 0}
  81. };
  82. test_st tests[] ={
  83. {"gearman_client_echo()", 0, client_echo_test },
  84. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  85. {"gearman_worker_echo()", 0, worker_echo_test },
  86. {"clean", 0, queue_clean },
  87. {"add", 0, queue_add },
  88. {"worker", 0, queue_worker },
  89. {0, 0, 0}
  90. };
  91. collection_st collection[] ={
  92. {"gearmand options", 0, 0, gearmand_basic_option_tests},
  93. {"memcached queue", collection_init, collection_cleanup, tests},
  94. {0, 0, 0, 0}
  95. };
  96. void get_world(Framework *world)
  97. {
  98. world->collections= collection;
  99. world->_create= world_create;
  100. world->_destroy= world_destroy;
  101. }