test_datasrc_clients_mgr.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <exceptions/exceptions.h>
  15. #include <auth/datasrc_config.h>
  16. #include "test_datasrc_clients_mgr.h"
  17. #include <cassert>
  18. namespace isc {
  19. namespace auth {
  20. namespace datasrc_clientmgr_internal {
  21. // Define static DataSrcClientsBuilder member variables.
  22. bool FakeDataSrcClientsBuilder::started = false;
  23. std::list<Command>* FakeDataSrcClientsBuilder::command_queue = NULL;
  24. std::list<FinishedCallback>* FakeDataSrcClientsBuilder::callback_queue = NULL;
  25. std::list<Command> FakeDataSrcClientsBuilder::command_queue_copy;
  26. std::list<FinishedCallback> FakeDataSrcClientsBuilder::callback_queue_copy;
  27. TestCondVar* FakeDataSrcClientsBuilder::cond = NULL;
  28. TestCondVar FakeDataSrcClientsBuilder::cond_copy;
  29. TestMutex* FakeDataSrcClientsBuilder::queue_mutex = NULL;
  30. isc::datasrc::ClientListMapPtr*
  31. FakeDataSrcClientsBuilder::clients_map = NULL;
  32. TestMutex* FakeDataSrcClientsBuilder::map_mutex = NULL;
  33. TestMutex FakeDataSrcClientsBuilder::queue_mutex_copy;
  34. bool FakeDataSrcClientsBuilder::thread_waited = false;
  35. FakeDataSrcClientsBuilder::ExceptionFromWait
  36. FakeDataSrcClientsBuilder::thread_throw_on_wait =
  37. FakeDataSrcClientsBuilder::NOTHROW;
  38. int FakeDataSrcClientsBuilder::wakeup_fd = -1;
  39. template<>
  40. void
  41. TestDataSrcClientsBuilder::doNoop() {
  42. ++queue_mutex_->noop_count;
  43. switch (queue_mutex_->throw_from_noop) {
  44. case TestMutex::NONE:
  45. break; // no throw
  46. case TestMutex::EXCLASS:
  47. isc_throw(Exception, "test exception");
  48. case TestMutex::INTEGER:
  49. throw 42;
  50. case TestMutex::INTERNAL:
  51. isc_throw(InternalCommandError, "internal error, should be ignored");
  52. }
  53. }
  54. } // namespace datasrc_clientmgr_internal
  55. template<>
  56. void
  57. TestDataSrcClientsMgrBase::cleanup() {
  58. using namespace datasrc_clientmgr_internal;
  59. // Make copy of some of the manager's member variables and reset the
  60. // corresponding pointers. The currently pointed objects are in the
  61. // manager object, which are going to be invalidated.
  62. FakeDataSrcClientsBuilder::command_queue_copy = command_queue_;
  63. FakeDataSrcClientsBuilder::command_queue =
  64. &FakeDataSrcClientsBuilder::command_queue_copy;
  65. FakeDataSrcClientsBuilder::queue_mutex_copy = queue_mutex_;
  66. FakeDataSrcClientsBuilder::queue_mutex =
  67. &FakeDataSrcClientsBuilder::queue_mutex_copy;
  68. FakeDataSrcClientsBuilder::cond_copy = cond_;
  69. FakeDataSrcClientsBuilder::cond =
  70. &FakeDataSrcClientsBuilder::cond_copy;
  71. FakeDataSrcClientsBuilder::callback_queue_copy =
  72. *FakeDataSrcClientsBuilder::callback_queue;
  73. FakeDataSrcClientsBuilder::callback_queue =
  74. &FakeDataSrcClientsBuilder::callback_queue_copy;
  75. }
  76. template<>
  77. void
  78. TestDataSrcClientsMgrBase::reconfigureHook() {
  79. using namespace datasrc_clientmgr_internal;
  80. // Simply replace the local map, ignoring bogus config value.
  81. assert(command_queue_.front().id == RECONFIGURE);
  82. try {
  83. clients_map_ = configureDataSource(command_queue_.front().params);
  84. } catch (...) {}
  85. }
  86. } // namespace auth
  87. } // namespace isc
  88. // Local Variables:
  89. // mode: c++
  90. // End: