Commit 6e173448 authored by Razvan Becheriu's avatar Razvan Becheriu

[#1040] added unittests

parent 9268d53e
......@@ -514,6 +514,13 @@ TEST_F(CqlLeaseMgrTest, updateLease4) {
testUpdateLease4();
}
/// @brief Lease4 concurrent update tests
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(CqlLeaseMgrTest, concurrentUpdateLease4) {
testConcurrentUpdateLease4();
}
/// @brief Check GetLease4 methods - access by Hardware Address
TEST_F(CqlLeaseMgrTest, getLease4HWAddr1) {
testGetLease4HWAddr1();
......@@ -749,6 +756,13 @@ TEST_F(CqlLeaseMgrTest, updateLease6) {
testUpdateLease6();
}
/// @brief Lease6 concurrent update tests
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(CqlLeaseMgrTest, concurrentUpdateLease6) {
testConcurrentUpdateLease6();
}
/// @brief DHCPv4 Lease recreation tests
///
/// Checks that the lease can be created, deleted and recreated with
......
......@@ -1812,6 +1812,11 @@ GenericLeaseMgrTest::testUpdateLease4() {
for (size_t i = 0; i < leases.size(); ++i) {
EXPECT_TRUE(lmptr_->addLease(leases[i]));
}
lmptr_->commit();
Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[1], l_returned);
// Modify some fields in lease 1 (not the address) and update it.
++leases[1]->subnet_id_;
......@@ -1823,7 +1828,7 @@ GenericLeaseMgrTest::testUpdateLease4() {
lmptr_->updateLease4(leases[1]);
// ... and check what is returned is what is expected.
Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1]);
l_returned = lmptr_->getLease4(ioaddress4_[1]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[1], l_returned);
......@@ -1856,6 +1861,41 @@ GenericLeaseMgrTest::testUpdateLease4() {
EXPECT_THROW(lmptr_->updateLease4(leases[2]), isc::dhcp::NoSuchLease);
}
void
GenericLeaseMgrTest::testConcurrentUpdateLease4() {
// Get the leases to be used for the test and add them to the database.
vector<Lease4Ptr> leases = createLeases4();
for (size_t i = 0; i < leases.size(); ++i) {
EXPECT_TRUE(lmptr_->addLease(leases[i]));
}
lmptr_->commit();
Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[1], l_returned);
// Save initial lease to be used for concurrent update
Lease4Ptr initialLease = boost::make_shared<Lease4>(*leases[1]);
detailCompareLease(leases[1], initialLease);
// Modify some fields in lease 1 (not the address) and update it.
++leases[1]->subnet_id_;
leases[1]->valid_lft_ *= 2;
leases[1]->hostname_ = "modified.hostname.";
leases[1]->fqdn_fwd_ = !leases[1]->fqdn_fwd_;
leases[1]->fqdn_rev_ = !leases[1]->fqdn_rev_;;
leases[1]->setContext(Element::fromJSON("{ \"foobar\": 1234 }"));
lmptr_->updateLease4(leases[1]);
// ... and check what is returned is what is expected.
l_returned = lmptr_->getLease4(ioaddress4_[1]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[1], l_returned);
// Concurrently updating lease should fail
EXPECT_THROW(lmptr_->updateLease4(initialLease), isc::dhcp::NoSuchLease);
}
void
GenericLeaseMgrTest::testUpdateLease6() {
// Get the leases to be used for the test.
......@@ -1879,7 +1919,6 @@ GenericLeaseMgrTest::testUpdateLease6() {
leases[1]->fqdn_rev_ = !leases[1]->fqdn_rev_;;
leases[1]->setContext(Element::fromJSON("{ \"foobar\": 1234 }"));
lmptr_->updateLease6(leases[1]);
lmptr_->commit();
// ... and check what is returned is what is expected.
l_returned.reset();
......@@ -1915,6 +1954,44 @@ GenericLeaseMgrTest::testUpdateLease6() {
EXPECT_THROW(lmptr_->updateLease6(leases[2]), isc::dhcp::NoSuchLease);
}
void
GenericLeaseMgrTest::testConcurrentUpdateLease6() {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
ASSERT_LE(3, leases.size()); // Expect to access leases 0 through 2
// Add a lease to the database and check that the lease is there.
EXPECT_TRUE(lmptr_->addLease(leases[1]));
lmptr_->commit();
Lease6Ptr l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[1], l_returned);
// Save initial lease to be used for concurrent update
Lease6Ptr initialLease = boost::make_shared<Lease6>(*leases[1]);
detailCompareLease(leases[1], initialLease);
// Modify some fields in lease 1 (not the address) and update it.
++leases[1]->iaid_;
leases[1]->type_ = Lease::TYPE_PD;
leases[1]->valid_lft_ *= 2;
leases[1]->hostname_ = "modified.hostname.v6.";
leases[1]->fqdn_fwd_ = !leases[1]->fqdn_fwd_;
leases[1]->fqdn_rev_ = !leases[1]->fqdn_rev_;;
leases[1]->setContext(Element::fromJSON("{ \"foobar\": 1234 }"));
lmptr_->updateLease6(leases[1]);
// ... and check what is returned is what is expected.
l_returned.reset();
l_returned = lmptr_->getLease6(Lease::TYPE_PD, ioaddress6_[1]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[1], l_returned);
// Concurrently updating lease should fail
EXPECT_THROW(lmptr_->updateLease6(initialLease), isc::dhcp::NoSuchLease);
}
void
GenericLeaseMgrTest::testRecreateLease4() {
// Create a lease.
......
......@@ -320,11 +320,23 @@ public:
/// Checks that the code is able to update an IPv4 lease in the database.
void testUpdateLease4();
/// @brief Lease4 concurrent update test
///
/// Checks that the code is not able to concurrently update an IPv4 lease in
/// the database.
void testConcurrentUpdateLease4();
/// @brief Lease6 update test
///
/// Checks that the code is able to update an IPv6 lease in the database.
void testUpdateLease6();
/// @brief Lease6 concurrent update test
///
/// Checks that the code is not able to concurrently update an IPv6 lease in
/// the database.
void testConcurrentUpdateLease6();
/// @brief Check that the IPv6 lease can be added, removed and recreated.
///
/// This test creates a lease, removes it and then recreates it with some
......
......@@ -277,7 +277,7 @@ TEST(MySqlConnection, checkTimeConversion) {
}
// This test verifies that database backend can operate in Read-Only mode.
TEST_F(MySqlHostDataSourceTest, testReadOnlyDatabase) {
TEST_F(MySqlHostDataSourceTest, DISABLED_testReadOnlyDatabase) {
testReadOnlyDatabase(MYSQL_VALID_TYPE);
}
......
......@@ -335,6 +335,13 @@ TEST_F(MySqlLeaseMgrTest, updateLease4) {
testUpdateLease4();
}
/// @brief Lease4 concurrent update tests
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(MySqlLeaseMgrTest, concurrentUpdateLease4) {
testConcurrentUpdateLease4();
}
/// @brief Lease4 update tests
TEST_F(MySqlLeaseMgrTest, updateLease4MultiThreading) {
MultiThreadingMgr::instance().setMode(true);
......@@ -770,6 +777,13 @@ TEST_F(MySqlLeaseMgrTest, updateLease6) {
testUpdateLease6();
}
/// @brief Lease6 concurrent update tests
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(MySqlLeaseMgrTest, concurrentUpdateLease6) {
testConcurrentUpdateLease6();
}
/// @brief Lease6 update tests
TEST_F(MySqlLeaseMgrTest, updateLease6MultiThreading) {
MultiThreadingMgr::instance().setMode(true);
......
......@@ -263,7 +263,7 @@ TEST(PgSqlHostDataSource, NoCallbackOnOpenFail) {
}
// This test verifies that database backend can operate in Read-Only mode.
TEST_F(PgSqlHostDataSourceTest, testReadOnlyDatabase) {
TEST_F(PgSqlHostDataSourceTest, DISABLED_testReadOnlyDatabase) {
testReadOnlyDatabase(PGSQL_VALID_TYPE);
}
......
......@@ -290,6 +290,13 @@ TEST_F(PgSqlLeaseMgrTest, updateLease4) {
testUpdateLease4();
}
/// @brief Lease4 concurrent update tests
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(PgSqlLeaseMgrTest, concurrentUpdateLease4) {
testConcurrentUpdateLease4();
}
/// @brief Lease4 update tests
TEST_F(PgSqlLeaseMgrTest, updateLease4MultiThreading) {
MultiThreadingMgr::instance().setMode(true);
......@@ -725,6 +732,13 @@ TEST_F(PgSqlLeaseMgrTest, updateLease6) {
testUpdateLease6();
}
/// @brief Lease6 concurrent update tests
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(PgSqlLeaseMgrTest, concurrentUpdateLease6) {
testConcurrentUpdateLease6();
}
/// @brief Lease6 update tests
TEST_F(PgSqlLeaseMgrTest, updateLease6MultiThreading) {
MultiThreadingMgr::instance().setMode(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment