// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
+#include <exceptions/exceptions.h>
+
#include <cc/data.h>
#include <auth/datasrc_clients_mgr.h>
#include <boost/function.hpp>
+using namespace isc::data;
using namespace isc::auth;
using namespace isc::auth::datasrc_clientmgr_internal;
EXPECT_TRUE(FakeDataSrcClientsBuilder::thread_waited);
}
+// Commonly used patter of checking member variables shared between the
+// manager and builder.
+void
+checkSharedMembers(size_t expected_queue_lock_count,
+ size_t expected_queue_unlock_count,
+ size_t expected_map_lock_count,
+ size_t expected_map_unlock_count,
+ size_t expected_cond_signal_count,
+ size_t expected_command_queue_size)
+{
+ EXPECT_EQ(expected_queue_lock_count,
+ FakeDataSrcClientsBuilder::queue_mutex->lock_count);
+ EXPECT_EQ(expected_queue_unlock_count,
+ FakeDataSrcClientsBuilder::queue_mutex->unlock_count);
+ EXPECT_EQ(expected_map_lock_count,
+ FakeDataSrcClientsBuilder::map_mutex->lock_count);
+ EXPECT_EQ(expected_map_unlock_count,
+ FakeDataSrcClientsBuilder::map_mutex->unlock_count);
+ EXPECT_EQ(expected_cond_signal_count,
+ FakeDataSrcClientsBuilder::cond->signal_count);
+ EXPECT_EQ(expected_command_queue_size,
+ FakeDataSrcClientsBuilder::command_queue->size());
+}
+
TEST(DataSrcClientsMgrTest, start) {
// When we create a manager, builder's run() method should be called.
FakeDataSrcClientsBuilder::started = false;
});
}
+TEST(DataSrcClientsMgrTest, reconfigure) {
+ TestDataSrcClientsMgr mgr;
+
+ // Check pre-command condition
+ checkSharedMembers(0, 0, 0, 0, 0, 0);
+
+ // A valid reconfigure argument
+ ConstElementPtr reconfigure_arg = Element::fromJSON(
+ "{" "\"IN\": [{\"type\": \"MasterFiles\", \"params\": {},"
+ " \"cache-enable\": true}]}");
+
+ // On reconfigure(), it just send the RECONFIGURE command to the builder
+ // thread with the given argument intact.
+ mgr.reconfigure(reconfigure_arg);
+
+ // The manager should have acquired the queue lock, send RECONFIGURE
+ // command with the arg, wake up the builder thread by signal. It doesn't
+ // touch or refer to the map, so it shouldn't acquire the map lock.
+ checkSharedMembers(1, 1, 0, 0, 1, 1);
+ const Command& cmd1 = FakeDataSrcClientsBuilder::command_queue->front();
+ EXPECT_EQ(RECONFIGURE, cmd1.first);
+ EXPECT_EQ(reconfigure_arg, cmd1.second);
+
+ // Non-null, but semantically invalid argument. The manager doesn't do
+ // this check, so it should result in the same effect.
+ FakeDataSrcClientsBuilder::command_queue->clear();
+ reconfigure_arg = isc::data::Element::create("{ \"foo\": \"bar\" }");
+ mgr.reconfigure(reconfigure_arg);
+ checkSharedMembers(2, 2, 0, 0, 2, 1);
+ const Command& cmd2 = FakeDataSrcClientsBuilder::command_queue->front();
+ EXPECT_EQ(RECONFIGURE, cmd2.first);
+ EXPECT_EQ(reconfigure_arg, cmd2.second);
+
+ // Passing NULL argument is immediately rejected
+ EXPECT_THROW(mgr.reconfigure(ConstElementPtr()), isc::InvalidParameter);
+ checkSharedMembers(2, 2, 0, 0, 2, 1); // no state change
+}
+
TEST(DataSrcClientsMgrTest, realThread) {
// Using the non-test definition with a real thread. Just checking
// no disruption happens.