datasrc_clients_mgr_unittest.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 <cc/data.h>
  15. #include <auth/datasrc_clients_mgr.h>
  16. #include "test_datasrc_clients_mgr.h"
  17. #include <gtest/gtest.h>
  18. #include <boost/function.hpp>
  19. using namespace isc::auth;
  20. using namespace isc::auth::internal;
  21. namespace {
  22. TEST(DataSrcClientsMgrTest, start) {
  23. // When we create a manager, builder's run() method should be called.
  24. FakeDataSrcClientsBuilder::started = false;
  25. TestDataSrcClientsMgr mgr;
  26. EXPECT_TRUE(FakeDataSrcClientsBuilder::started);
  27. EXPECT_TRUE(FakeDataSrcClientsBuilder::command_queue->empty());
  28. }
  29. TEST(DataSrcClientsMgrTest, shutdown) {
  30. // Invoke shutdown on the manager.
  31. TestDataSrcClientsMgr mgr;
  32. EXPECT_TRUE(FakeDataSrcClientsBuilder::started);
  33. // Check pre-command conditions
  34. EXPECT_EQ(0, FakeDataSrcClientsBuilder::cond->signal_count);
  35. EXPECT_FALSE(FakeDataSrcClientsBuilder::thread_waited);
  36. mgr.shutdown();
  37. // The manager should have acquired the lock, put a SHUTDOWN command
  38. // to the queue, and should have signaled the builder.
  39. EXPECT_EQ(1, FakeDataSrcClientsBuilder::queue_mutex->lock_count);
  40. EXPECT_EQ(1, FakeDataSrcClientsBuilder::cond->signal_count);
  41. EXPECT_EQ(1, FakeDataSrcClientsBuilder::command_queue->size());
  42. const Command& cmd = FakeDataSrcClientsBuilder::command_queue->front();
  43. EXPECT_EQ(SHUTDOWN, cmd.first);
  44. EXPECT_FALSE(cmd.second);
  45. EXPECT_TRUE(FakeDataSrcClientsBuilder::thread_waited);
  46. }
  47. TEST(DataSrcClientsMgrTest, realThread) {
  48. // Using the non-test definition with a real thread. Just checking
  49. // no disruption happens.
  50. DataSrcClientsMgr mgr;
  51. mgr.shutdown();
  52. }
  53. } // unnamed namespace