checkQueryAgainstRowSet(query, expected_rows);
}
-GenericLeaseMgrTest::testLeaseLimits() {
+void
+GenericLeaseMgrTest::testLeaseLimits4() {
std::string text;
ElementPtr user_context;
"client-classes": [ { "name": "foo", "address-limit": 0 } ] } } })");
ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context));
EXPECT_EQ(text, "address limit 0 for client class \"foo\", current lease count 0");
- ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
- EXPECT_EQ(text, "address limit 0 for client class \"foo\", current lease count 0");
user_context = Element::fromJSON(R"({ "ISC": { "limits": {
"subnet": { "id": 1, "address-limit": 0 } } } })");
ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context));
EXPECT_EQ(text, "address limit 0 for subnet ID 1, current lease count 0");
- ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
- EXPECT_EQ(text, "address limit 0 for subnet ID 1, current lease count 0");
// -- A limit of 1 with no leases should allow a lease. --
"client-classes": [ { "name": "foo", "address-limit": 1 } ] } } })");
ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context));
EXPECT_EQ(text, "");
- ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
- EXPECT_EQ(text, "");
user_context = Element::fromJSON(R"({ "ISC": { "limits": {
"subnet": { "id": 1, "address-limit": 1 } } } })");
ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context));
EXPECT_EQ(text, "");
- ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
- EXPECT_EQ(text, "");
// -- A limit of 1 with 1 current lease should deny further leases. --
makeLease4("192.0.1.1", 1, Lease::STATE_DEFAULT, Element::fromJSON(
R"({ "ISC": { "client-classes": [ "foo" ] } })"));
+ user_context = Element::fromJSON(R"({ "ISC": { "limits": {
+ "client-classes": [ { "name": "foo", "address-limit": 1 } ] } } })");
+ ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context));
+ EXPECT_EQ(text, "address limit 1 for client class \"foo\", current lease count 1");
+
+ user_context = Element::fromJSON(R"({ "ISC": { "limits": {
+ "subnet": { "id": 1, "address-limit": 1 } } } })");
+ ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context));
+ EXPECT_EQ(text, "address limit 1 for subnet ID 1, current lease count 1");
+}
+
+void
+GenericLeaseMgrTest::testLeaseLimits6() {
+ std::string text;
+ ElementPtr user_context;
+
+ // -- A limit of 0 always denies a lease. --
+
+ user_context = Element::fromJSON(R"({ "ISC": { "limits": {
+ "client-classes": [ { "name": "foo", "address-limit": 0 } ] } } })");
+ EXPECT_EQ(text, "address limit 0 for client class \"foo\", current lease count 0");
+ ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
+
+ user_context = Element::fromJSON(R"({ "ISC": { "limits": {
+ "subnet": { "id": 1, "address-limit": 0 } } } })");
+ ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
+ EXPECT_EQ(text, "address limit 0 for subnet ID 1, current lease count 0");
+
+ // -- A limit of 1 with no leases should allow a lease. --
+
+ user_context = Element::fromJSON(R"({ "ISC": { "limits": {
+ "client-classes": [ { "name": "foo", "address-limit": 1 } ] } } })");
+ ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
+ EXPECT_EQ(text, "");
+
+ user_context = Element::fromJSON(R"({ "ISC": { "limits": {
+ "subnet": { "id": 1, "address-limit": 1 } } } })");
+ ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
+ EXPECT_EQ(text, "");
+
+ // -- A limit of 1 with 1 current lease should deny further leases. --
makeLease6(Lease::TYPE_NA, "2001:db8::", 0, 1, Lease::STATE_DEFAULT, Element::fromJSON(
R"({ "ISC": { "client-classes": [ "foo" ] } })"));
user_context = Element::fromJSON(R"({ "ISC": { "limits": {
"client-classes": [ { "name": "foo", "address-limit": 1 } ] } } })");
- ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context));
- EXPECT_EQ(text, "address limit 1 for client class \"foo\", current lease count 1");
ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
EXPECT_EQ(text, "address limit 1 for client class \"foo\", current lease count 1");
user_context = Element::fromJSON(R"({ "ISC": { "limits": {
"subnet": { "id": 1, "address-limit": 1 } } } })");
- ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context));
- EXPECT_EQ(text, "address limit 1 for subnet ID 1, current lease count 1");
ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context));
EXPECT_EQ(text, "address limit 1 for subnet ID 1, current lease count 1");
}
}
+// Verifies that isJsonSupported() returns true for Memfile.
+TEST_F(MemfileLeaseMgrTest, isJsonSupported4) {
+ startBackend(V4);
+ bool json_supported;
+ ASSERT_NO_THROW_LOG(json_supported = LeaseMgrFactory::instance().isJsonSupported());
+ ASSERT_TRUE(json_supported);
+}
+
+// Verifies that isJsonSupported() returns true for Memfile.
+TEST_F(MemfileLeaseMgrTest, isJsonSupported6) {
+ startBackend(V6);
+ bool json_supported;
+ ASSERT_NO_THROW_LOG(json_supported = LeaseMgrFactory::instance().isJsonSupported());
+ ASSERT_TRUE(json_supported);
+}
+
// Verifies that v4 class lease counts are correctly adjusted
// when leases have class lists.
TEST_F(MemfileLeaseMgrTest, classLeaseCount4) {
testClassLeaseCount6(Lease::TYPE_PD);
}
+// brief Checks that a null user context allows allocation.
+// DISABLED_ until Memfile_LeaseMgr implements checkLimits4().
+TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimitsNull4) {
+ startBackend(V4);
+ std::string text;
+ ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(nullptr));
+ EXPECT_TRUE(text.empty());
+}
+
+// brief Checks that a null user context allows allocation.
+// DISABLED_ until Memfile_LeaseMgr implements checkLimits6().
+TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimitsNull6) {
+ startBackend(V6);
+ std::string text;
+ ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(nullptr));
+ EXPECT_TRUE(text.empty());
+}
+
+// Checks a few V4 lease limit checking scenarios.
+// Disabbled until Memfile_LeaseMgr implements checkLimits4() function.
+TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimits4) {
+ startBackend(V4);
+ testLeaseLimits4();
+}
+
+// Checks a few V4 lease limit checking scenarios.
+// Disabbled until Memfile_LeaseMgr implements checkLimits4() function.
+TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimits6) {
+ startBackend(V6);
+ testLeaseLimits6();
+}
+
// Verifies that v4 class lease counts can be recounted.
TEST_F(MemfileLeaseMgrTest, classLeaseRecount4) {
startBackend(V4);
// Bake all the leases.
for ( auto recipe : recipes ) {
- Lease4Ptr lease = makeLease4(recipe.address_, 777, recipe.state_, false);
ElementPtr ctx = makeContextWithClasses(recipe.classes_);
- lease->setContext(makeContextWithClasses(recipe.classes_));
- ASSERT_NO_THROW_LOG(memfile_mgr->addLease(lease));
+ ASSERT_TRUE(makeLease4(recipe.address_, 777, recipe.state_, ctx));
}
// Verify counts are as expected.
// Bake all the leases.
for ( auto recipe : recipes ) {
- Lease6Ptr lease = makeLease6(recipe.ltype_, recipe.address_, recipe.prefix_len_, 777, recipe.state_, false);
ElementPtr ctx = makeContextWithClasses(recipe.classes_);
- lease->setContext(makeContextWithClasses(recipe.classes_));
- ASSERT_NO_THROW_LOG(memfile_mgr->addLease(lease));
+ ASSERT_TRUE(makeLease6(recipe.ltype_, recipe.address_, recipe.prefix_len_, 777, recipe.state_, ctx));
}
// Verify counts are as expected.
"enabled in the database." << std::endl;
}
+// Verifies that v4 class lease counts are correctly adjusted
+// when leases have class lists.
+// Disabled until MySqlLeaseMgr implements LeaseMgr::getClassLeaseCount()
+TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount4) {
+ testClassLeaseCount4();
+}
+
+// Verifies that v6 IA_NA class lease counts are correctly adjusted
+// when leases have class lists.
+// Disabled until MySqlLeaseMgr implements LeaseMgr::getClassLeaseCount()
+TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount6_NA) {
+ testClassLeaseCount6(Lease::TYPE_NA);
+}
+
+// Verifies that v6 IA_PD class lease counts are correctly adjusted
+// when leases have class lists.
+// Disabled until MySqlLeaseMgr implements LeaseMgr::getClassLeaseCount()
+TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount6_PD) {
+ testClassLeaseCount6(Lease::TYPE_PD);
+}
+
/// @brief Checks that a null user context allows allocation.
TEST_F(MySqlLeaseMgrTest, checkLimitsNull) {
std::string text;
}
// The rest of the checks are only for databases with JSON support.
- testLeaseLimits();
+ testLeaseLimits4();
+ testLeaseLimits6();
}
} // namespace