From 03e9b52c559ed5bc7083ab81101feb3e837bb081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 26 Jan 2012 19:00:55 +0100 Subject: [PATCH] Bug #1087: Core tests (cherry picked from commit f10e852fe4c693c069026475e36ecd16b6b32d2a) --- src/image/test/ImagePoolTest.cc | 65 +++++++++++++++++++++ src/vm_template/test/VMTemplatePoolTest.cc | 67 ++++++++++++++++++++++ src/vnm/test/VirtualNetworkPoolTest.cc | 65 +++++++++++++++++++++ 3 files changed, 197 insertions(+) diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index 8015f15cac..8427243e70 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -152,6 +152,7 @@ class ImagePoolTest : public PoolTest CPPUNIT_TEST ( get_using_name ); CPPUNIT_TEST ( wrong_get_name ); CPPUNIT_TEST ( name_index ); + CPPUNIT_TEST ( chown_name_index ); CPPUNIT_TEST_SUITE_END (); @@ -921,6 +922,70 @@ public: CPPUNIT_ASSERT(img_oid != 0); img_oid->unlock(); + CPPUNIT_ASSERT(img_oid == img_name); + } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void chown_name_index() + { + Image *img_oid, *img_name; + int oid; + int old_uid; + int new_uid = 3456; + string name; + + oid = allocate(0); + + CPPUNIT_ASSERT(oid != -1); + + + // --------------------------------- + // Get by oid + img_oid = ipool->get(oid, true); + CPPUNIT_ASSERT(img_oid != 0); + + name = img_oid->get_name(); + old_uid = img_oid->get_uid(); + + // Change owner and update cache index + img_oid->set_user(new_uid, "new_username"); + ipool->update(img_oid); + img_oid->unlock(); + + ipool->update_cache_index(name, old_uid, name, new_uid); + + // Get by name, new_uid and check it is the same object + img_name = ipool->get(name, new_uid, true); + CPPUNIT_ASSERT(img_name != 0); + img_name->unlock(); + + CPPUNIT_ASSERT(img_oid == img_name); + + // Get by name, old_uid and check it does not exist + img_name = ipool->get(name, old_uid, true); + CPPUNIT_ASSERT(img_name == 0); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + ipool->clean(); + + + // Get by name, old_uid and check it does not exist + img_name = ipool->get(name, old_uid, true); + CPPUNIT_ASSERT(img_name == 0); + + // Get by oid + img_oid = ipool->get(oid, true); + CPPUNIT_ASSERT(img_oid != 0); + img_oid->unlock(); + + // Get by name, new_uid and check it is the same object + img_name = ipool->get(name, new_uid, true); + CPPUNIT_ASSERT(img_name != 0); + img_name->unlock(); + CPPUNIT_ASSERT(img_oid == img_name); } }; diff --git a/src/vm_template/test/VMTemplatePoolTest.cc b/src/vm_template/test/VMTemplatePoolTest.cc index dc6febbd7b..e3c0259d8d 100644 --- a/src/vm_template/test/VMTemplatePoolTest.cc +++ b/src/vm_template/test/VMTemplatePoolTest.cc @@ -111,6 +111,7 @@ class VMTemplatePoolTest : public PoolTest CPPUNIT_TEST ( dump ); CPPUNIT_TEST ( dump_where ); CPPUNIT_TEST ( name_index ); + CPPUNIT_TEST ( chown_name_index ); CPPUNIT_TEST_SUITE_END (); @@ -513,6 +514,72 @@ public: CPPUNIT_ASSERT(vnet_oid == vnet_name); } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void chown_name_index() + { + VMTemplatePool *tpool = static_cast(pool); + VMTemplate *obj_oid, *obj_name; + int oid; + int old_uid; + int new_uid = 3456; + string name; + + oid = allocate(0); + + CPPUNIT_ASSERT(oid != -1); + + + // --------------------------------- + // Get by oid + obj_oid = tpool->get(oid, true); + CPPUNIT_ASSERT(obj_oid != 0); + + name = obj_oid->get_name(); + old_uid = obj_oid->get_uid(); + + // Change owner and update cache index + obj_oid->set_user(new_uid, "new_username"); + tpool->update(obj_oid); + obj_oid->unlock(); + + tpool->update_cache_index(name, old_uid, name, new_uid); + + // Get by name, new_uid and check it is the same object + obj_name = tpool->get(name, new_uid, true); + CPPUNIT_ASSERT(obj_name != 0); + obj_name->unlock(); + + CPPUNIT_ASSERT(obj_oid == obj_name); + + // Get by name, old_uid and check it does not exist + obj_name = tpool->get(name, old_uid, true); + CPPUNIT_ASSERT(obj_name == 0); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + tpool->clean(); + + + // Get by name, old_uid and check it does not exist + obj_name = tpool->get(name, old_uid, true); + CPPUNIT_ASSERT(obj_name == 0); + + // Get by oid + obj_oid = tpool->get(oid, true); + CPPUNIT_ASSERT(obj_oid != 0); + obj_oid->unlock(); + + // Get by name, new_uid and check it is the same object + obj_name = tpool->get(name, new_uid, true); + CPPUNIT_ASSERT(obj_name != 0); + obj_name->unlock(); + + CPPUNIT_ASSERT(obj_oid == obj_name); + } + /* ********************************************************************* */ }; diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index 7f5f97f83c..5e57f71373 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -181,6 +181,7 @@ class VirtualNetworkPoolTest : public PoolTest CPPUNIT_TEST (range_definition); CPPUNIT_TEST (name_index); + CPPUNIT_TEST (chown_name_index); CPPUNIT_TEST_SUITE_END (); @@ -1755,6 +1756,70 @@ public: CPPUNIT_ASSERT(vnet_oid != 0); vnet_oid->unlock(); + CPPUNIT_ASSERT(vnet_oid == vnet_name); + } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void chown_name_index() + { + VirtualNetwork *vnet_oid, *vnet_name; + int oid; + int old_uid; + int new_uid = 3456; + string name; + + oid = allocate(0); + + CPPUNIT_ASSERT(oid != -1); + + + // --------------------------------- + // Get by oid + vnet_oid = vnpool->get(oid, true); + CPPUNIT_ASSERT(vnet_oid != 0); + + name = vnet_oid->get_name(); + old_uid = vnet_oid->get_uid(); + + // Change owner and update cache index + vnet_oid->set_user(new_uid, "new_username"); + vnpool->update(vnet_oid); + vnet_oid->unlock(); + + vnpool->update_cache_index(name, old_uid, name, new_uid); + + // Get by name, new_uid and check it is the same object + vnet_name = vnpool->get(name, new_uid, true); + CPPUNIT_ASSERT(vnet_name != 0); + vnet_name->unlock(); + + CPPUNIT_ASSERT(vnet_oid == vnet_name); + + // Get by name, old_uid and check it does not exist + vnet_name = vnpool->get(name, old_uid, true); + CPPUNIT_ASSERT(vnet_name == 0); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + vnpool->clean(); + + + // Get by name, old_uid and check it does not exist + vnet_name = vnpool->get(name, old_uid, true); + CPPUNIT_ASSERT(vnet_name == 0); + + // Get by oid + vnet_oid = vnpool->get(oid, true); + CPPUNIT_ASSERT(vnet_oid != 0); + vnet_oid->unlock(); + + // Get by name, new_uid and check it is the same object + vnet_name = vnpool->get(name, new_uid, true); + CPPUNIT_ASSERT(vnet_name != 0); + vnet_name->unlock(); + CPPUNIT_ASSERT(vnet_oid == vnet_name); } };