start_worker.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are
  10. * met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following disclaimer
  17. * in the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * The names of its contributors may not be used to endorse or
  21. * promote products derived from this software without specific prior
  22. * written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. */
  37. #include <sys/types.h>
  38. #include <libgearman-1.0/gearman.h>
  39. #include <libtest/visibility.h>
  40. #include <boost/shared_ptr.hpp>
  41. #include "tests/workers/v2/called.h"
  42. #include "libgearman/worker.hpp"
  43. struct worker_handle_st
  44. {
  45. public:
  46. worker_handle_st();
  47. ~worker_handle_st();
  48. void set_shutdown();
  49. bool is_shutdown();
  50. bool shutdown();
  51. void kill();
  52. void set_worker_id(gearman_worker_st*);
  53. libtest::thread::Barrier* sync_point();
  54. void wait();
  55. bool check();
  56. volatile bool failed_startup;
  57. boost::shared_ptr<libtest::thread::Thread> _thread;
  58. void error(gearman_return_t)
  59. {
  60. _error_count++;
  61. }
  62. bool error()
  63. {
  64. return _error_count;
  65. }
  66. private:
  67. bool _shutdown;
  68. uint64_t _error_count;
  69. libtest::thread::Mutex _shutdown_lock;
  70. gearman_id_t _worker_id;
  71. libtest::thread::Barrier _sync_point;
  72. };
  73. struct worker_handles_st
  74. {
  75. worker_handles_st();
  76. ~worker_handles_st();
  77. // Warning, this will not clean up memory
  78. void kill_all();
  79. void reset();
  80. void push(worker_handle_st *arg);
  81. private:
  82. std::vector<worker_handle_st *> _workers;
  83. };
  84. #pragma once
  85. LIBTEST_API
  86. worker_handle_st *worker_run(const org::gearmand::libgearman::Worker&);
  87. LIBTEST_API
  88. struct worker_handle_st *test_worker_start(in_port_t port,
  89. const char *namespace_key,
  90. const char *function_name,
  91. const gearman_function_t &worker_fn,
  92. void *context,
  93. gearman_worker_options_t options,
  94. int timeout= 0);
  95. LIBTEST_API
  96. bool test_worker_stop(struct worker_handle_st *);