memcached_test.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #if defined(NDEBUG)
  10. # undef NDEBUG
  11. #endif
  12. #include <cassert>
  13. #include <cstdio>
  14. #include <cstdlib>
  15. #include <cstring>
  16. #include <unistd.h>
  17. #include <libgearman/gearman.h>
  18. #include <libtest/test.h>
  19. #include <libtest/server.h>
  20. #include <tests/basic.h>
  21. #include <tests/context.h>
  22. #define WORKER_TEST_PORT 32123
  23. void *world_create(test_return_t *error);
  24. test_return_t world_destroy(void *object);
  25. #ifndef __INTEL_COMPILER
  26. #pragma GCC diagnostic ignored "-Wold-style-cast"
  27. #endif
  28. // prototype
  29. test_return_t collection_init(void *object);
  30. test_return_t collection_cleanup(void *object);
  31. test_return_t collection_init(void *object)
  32. {
  33. const char *argv[3]= { "test_gearmand", "--libmemcached-servers=localhost:12555", "--queue-type=libmemcached" };
  34. Context *test= (Context *)object;
  35. assert(test);
  36. test_truth(test->initialize(3, argv));
  37. return TEST_SUCCESS;
  38. }
  39. test_return_t collection_cleanup(void *object)
  40. {
  41. Context *test= (Context *)object;
  42. test->reset();
  43. return TEST_SUCCESS;
  44. }
  45. void *world_create(test_return_t *error)
  46. {
  47. Context *test= new Context(WORKER_TEST_PORT);
  48. if (not test)
  49. {
  50. *error= TEST_MEMORY_ALLOCATION_FAILURE;
  51. return NULL;
  52. }
  53. *error= TEST_SUCCESS;
  54. return test;
  55. }
  56. test_return_t world_destroy(void *object)
  57. {
  58. Context *test= (Context *)object;
  59. delete test;
  60. return TEST_SUCCESS;
  61. }
  62. test_st tests[] ={
  63. {"gearman_client_echo()", 0, client_echo_test },
  64. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  65. {"gearman_worker_echo()", 0, worker_echo_test },
  66. {"clean", 0, queue_clean },
  67. {"add", 0, queue_add },
  68. {"worker", 0, queue_worker },
  69. {0, 0, 0}
  70. };
  71. collection_st collection[] ={
  72. #ifdef HAVE_LIBMEMCACHED
  73. {"memcached queue", collection_init, collection_cleanup, tests},
  74. #endif
  75. {0, 0, 0, 0}
  76. };
  77. void get_world(world_st *world)
  78. {
  79. world->collections= collection;
  80. world->create= world_create;
  81. world->destroy= world_destroy;
  82. }