From 7a5b42b184b8017ebe66e2cdbfb4920a41172ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 26 Jan 2012 16:50:33 +0100 Subject: [PATCH] Bug #1086: Core tests for cache bug --- src/group/test/GroupPoolTest.cc | 65 +++++++++++++++++++++ src/host/test/HostPoolTest.cc | 65 +++++++++++++++++++++ src/image/test/ImagePoolTest.cc | 64 +++++++++++++++++++++ src/um/test/UserPoolTest.cc | 62 ++++++++++++++++++++ src/vm_template/test/VMTemplatePoolTest.cc | 66 +++++++++++++++++++++ src/vnm/test/VirtualNetworkPoolTest.cc | 67 ++++++++++++++++++++++ 6 files changed, 389 insertions(+) diff --git a/src/group/test/GroupPoolTest.cc b/src/group/test/GroupPoolTest.cc index 2624bb4a73..a96a1c7d56 100644 --- a/src/group/test/GroupPoolTest.cc +++ b/src/group/test/GroupPoolTest.cc @@ -67,6 +67,8 @@ class GroupPoolTest : public PoolTest CPPUNIT_TEST (duplicates); CPPUNIT_TEST (dump); + CPPUNIT_TEST (name_index); + CPPUNIT_TEST_SUITE_END (); protected: @@ -222,6 +224,69 @@ public: CPPUNIT_ASSERT( oss.str() == group_xml_dump ); } + + /* ********************************************************************* */ + + void name_index() + { + Group *group_oid, *group_name; + int oid_0; + int uid_0; + string name_0; + + oid_0 = allocate(0); + + CPPUNIT_ASSERT(oid_0 != -1); + + // --------------------------------- + // Get by oid + group_oid = gpool->get(oid_0, true); + CPPUNIT_ASSERT(group_oid != 0); + + name_0 = group_oid->get_name(); + uid_0 = group_oid->get_uid(); + + group_oid->unlock(); + + // Get by name and check it is the same object + group_name = gpool->get(name_0, true); + CPPUNIT_ASSERT(group_name != 0); + group_name->unlock(); + + CPPUNIT_ASSERT(group_oid == group_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + gpool->clean(); + + // Get by oid + group_oid = gpool->get(oid_0, true); + CPPUNIT_ASSERT(group_oid != 0); + group_oid->unlock(); + + // Get by name and check it is the same object + group_name = gpool->get(name_0, true); + CPPUNIT_ASSERT(group_name != 0); + group_name->unlock(); + + CPPUNIT_ASSERT(group_oid == group_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + gpool->clean(); + + // Get by name + group_name = gpool->get(name_0, true); + CPPUNIT_ASSERT(group_name != 0); + group_name->unlock(); + + // Get by oid and check it is the same object + group_oid = gpool->get(oid_0, true); + CPPUNIT_ASSERT(group_oid != 0); + group_oid->unlock(); + + CPPUNIT_ASSERT(group_oid == group_name); + } }; /* ************************************************************************* */ diff --git a/src/host/test/HostPoolTest.cc b/src/host/test/HostPoolTest.cc index 044d154d63..dbc4a0b419 100644 --- a/src/host/test/HostPoolTest.cc +++ b/src/host/test/HostPoolTest.cc @@ -139,6 +139,7 @@ class HostPoolTest : public PoolTest CPPUNIT_TEST (discover); CPPUNIT_TEST (duplicates); CPPUNIT_TEST (update_info); + CPPUNIT_TEST (name_index); // CPPUNIT_TEST (scale_test); @@ -492,6 +493,70 @@ public: CPPUNIT_ASSERT( host != 0 ); CPPUNIT_ASSERT( host->to_xml(str) == host0_updated ); } + + /* ********************************************************************* */ + + void name_index() + { + HostPool * hp = static_cast(pool); + Host *host_oid, *host_name; + int oid_0; + int uid_0; + string name_0; + + oid_0 = allocate(0); + + CPPUNIT_ASSERT(oid_0 != -1); + + // --------------------------------- + // Get by oid + host_oid = hp->get(oid_0, true); + CPPUNIT_ASSERT(host_oid != 0); + + name_0 = host_oid->get_name(); + uid_0 = host_oid->get_uid(); + + host_oid->unlock(); + + // Get by name and check it is the same object + host_name = hp->get(name_0, true); + CPPUNIT_ASSERT(host_name != 0); + host_name->unlock(); + + CPPUNIT_ASSERT(host_oid == host_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + hp->clean(); + + // Get by oid + host_oid = hp->get(oid_0, true); + CPPUNIT_ASSERT(host_oid != 0); + host_oid->unlock(); + + // Get by name and check it is the same object + host_name = hp->get(name_0, true); + CPPUNIT_ASSERT(host_name != 0); + host_name->unlock(); + + CPPUNIT_ASSERT(host_oid == host_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + hp->clean(); + + // Get by name + host_name = hp->get(name_0, true); + CPPUNIT_ASSERT(host_name != 0); + host_name->unlock(); + + // Get by oid and check it is the same object + host_oid = hp->get(oid_0, true); + CPPUNIT_ASSERT(host_oid != 0); + host_oid->unlock(); + + CPPUNIT_ASSERT(host_oid == host_name); + } }; diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index feb835aea9..818454324b 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -150,6 +150,8 @@ class ImagePoolTest : public PoolTest CPPUNIT_TEST ( dump_where ); CPPUNIT_TEST ( get_using_name ); CPPUNIT_TEST ( wrong_get_name ); + CPPUNIT_TEST ( name_index ); + CPPUNIT_TEST_SUITE_END (); protected: @@ -962,6 +964,68 @@ public: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + + void name_index() + { + Image *img_oid, *img_name; + int oid_0; + int uid_0; + string name_0; + + oid_0 = allocate(0); + + CPPUNIT_ASSERT(oid_0 != -1); + + + // --------------------------------- + // Get by oid + img_oid = ipool->get(oid_0, true); + CPPUNIT_ASSERT(img_oid != 0); + + name_0 = img_oid->get_name(); + uid_0 = img_oid->get_uid(); + + img_oid->unlock(); + + // Get by name and check it is the same object + img_name = ipool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(img_name != 0); + img_name->unlock(); + + CPPUNIT_ASSERT(img_oid == img_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + ipool->clean(); + + // Get by oid + img_oid = ipool->get(oid_0, true); + CPPUNIT_ASSERT(img_oid != 0); + img_oid->unlock(); + + // Get by name and check it is the same object + img_name = ipool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(img_name != 0); + img_name->unlock(); + + CPPUNIT_ASSERT(img_oid == img_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + ipool->clean(); + + // Get by name + img_name = ipool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(img_name != 0); + img_name->unlock(); + + // Get by oid and check it is the same object + img_oid = ipool->get(oid_0, true); + CPPUNIT_ASSERT(img_oid != 0); + img_oid->unlock(); + + CPPUNIT_ASSERT(img_oid == img_name); + } }; /* ************************************************************************* */ diff --git a/src/um/test/UserPoolTest.cc b/src/um/test/UserPoolTest.cc index 9ae1b6f78b..fd111fcd4a 100644 --- a/src/um/test/UserPoolTest.cc +++ b/src/um/test/UserPoolTest.cc @@ -77,6 +77,7 @@ class UserPoolTest : public PoolTest CPPUNIT_TEST (duplicates); //CPPUNIT_TEST (dump); CPPUNIT_TEST (dump_where); + CPPUNIT_TEST (name_index); CPPUNIT_TEST_SUITE_END (); @@ -374,6 +375,67 @@ public: CPPUNIT_ASSERT( oss.str() == dump_where_result ); } + + void name_index() + { + User *user_oid, *user_name; + int oid_0; + int uid_0; + string name_0; + + oid_0 = allocate(0); + + CPPUNIT_ASSERT(oid_0 != -1); + + // --------------------------------- + // Get by oid + user_oid = upool->get(oid_0, true); + CPPUNIT_ASSERT(user_oid != 0); + + name_0 = user_oid->get_name(); + uid_0 = user_oid->get_uid(); + + user_oid->unlock(); + + // Get by name and check it is the same object + user_name = upool->get(name_0, true); + CPPUNIT_ASSERT(user_name != 0); + user_name->unlock(); + + CPPUNIT_ASSERT(user_oid == user_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + upool->clean(); + + // Get by oid + user_oid = upool->get(oid_0, true); + CPPUNIT_ASSERT(user_oid != 0); + user_oid->unlock(); + + // Get by name and check it is the same object + user_name = upool->get(name_0, true); + CPPUNIT_ASSERT(user_name != 0); + user_name->unlock(); + + CPPUNIT_ASSERT(user_oid == user_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + upool->clean(); + + // Get by name + user_name = upool->get(name_0, true); + CPPUNIT_ASSERT(user_name != 0); + user_name->unlock(); + + // Get by oid and check it is the same object + user_oid = upool->get(oid_0, true); + CPPUNIT_ASSERT(user_oid != 0); + user_oid->unlock(); + + CPPUNIT_ASSERT(user_oid == user_name); + } }; /* ************************************************************************* */ diff --git a/src/vm_template/test/VMTemplatePoolTest.cc b/src/vm_template/test/VMTemplatePoolTest.cc index 5e5c074b9d..dc6febbd7b 100644 --- a/src/vm_template/test/VMTemplatePoolTest.cc +++ b/src/vm_template/test/VMTemplatePoolTest.cc @@ -110,6 +110,7 @@ class VMTemplatePoolTest : public PoolTest CPPUNIT_TEST ( duplicates ); CPPUNIT_TEST ( dump ); CPPUNIT_TEST ( dump_where ); + CPPUNIT_TEST ( name_index ); CPPUNIT_TEST_SUITE_END (); @@ -447,6 +448,71 @@ public: CPPUNIT_ASSERT( result == xml_dump_where ); } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void name_index() + { + VMTemplatePool *tpool = static_cast(pool); + VMTemplate *vnet_oid, *vnet_name; + int oid_0; + int uid_0; + string name_0; + + oid_0 = allocate(0); + + CPPUNIT_ASSERT(oid_0 != -1); + + + // --------------------------------- + // Get by oid + vnet_oid = tpool->get(oid_0, true); + CPPUNIT_ASSERT(vnet_oid != 0); + + name_0 = vnet_oid->get_name(); + uid_0 = vnet_oid->get_uid(); + + vnet_oid->unlock(); + + // Get by name and check it is the same object + vnet_name = tpool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(vnet_name != 0); + vnet_name->unlock(); + + CPPUNIT_ASSERT(vnet_oid == vnet_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + tpool->clean(); + + // Get by oid + vnet_oid = tpool->get(oid_0, true); + CPPUNIT_ASSERT(vnet_oid != 0); + vnet_oid->unlock(); + + // Get by name and check it is the same object + vnet_name = tpool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(vnet_name != 0); + vnet_name->unlock(); + + CPPUNIT_ASSERT(vnet_oid == vnet_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + tpool->clean(); + + // Get by name + vnet_name = tpool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(vnet_name != 0); + vnet_name->unlock(); + + // Get by oid and check it is the same object + vnet_oid = tpool->get(oid_0, true); + CPPUNIT_ASSERT(vnet_oid != 0); + vnet_oid->unlock(); + + CPPUNIT_ASSERT(vnet_oid == vnet_name); + } /* ********************************************************************* */ }; diff --git a/src/vnm/test/VirtualNetworkPoolTest.cc b/src/vnm/test/VirtualNetworkPoolTest.cc index a88378a321..7f5f97f83c 100644 --- a/src/vnm/test/VirtualNetworkPoolTest.cc +++ b/src/vnm/test/VirtualNetworkPoolTest.cc @@ -180,6 +180,8 @@ class VirtualNetworkPoolTest : public PoolTest CPPUNIT_TEST (range_definition); + CPPUNIT_TEST (name_index); + CPPUNIT_TEST_SUITE_END (); protected: @@ -1690,6 +1692,71 @@ public: vnpool->drop(vnet, err); } } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void name_index() + { + VirtualNetwork *vnet_oid, *vnet_name; + int oid_0; + int uid_0; + string name_0; + + oid_0 = allocate(0); + + CPPUNIT_ASSERT(oid_0 != -1); + + + // --------------------------------- + // Get by oid + vnet_oid = vnpool->get(oid_0, true); + CPPUNIT_ASSERT(vnet_oid != 0); + + name_0 = vnet_oid->get_name(); + uid_0 = vnet_oid->get_uid(); + + vnet_oid->unlock(); + + // Get by name and check it is the same object + vnet_name = vnpool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(vnet_name != 0); + vnet_name->unlock(); + + CPPUNIT_ASSERT(vnet_oid == vnet_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + vnpool->clean(); + + // Get by oid + vnet_oid = vnpool->get(oid_0, true); + CPPUNIT_ASSERT(vnet_oid != 0); + vnet_oid->unlock(); + + // Get by name and check it is the same object + vnet_name = vnpool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(vnet_name != 0); + vnet_name->unlock(); + + CPPUNIT_ASSERT(vnet_oid == vnet_name); + + // --------------------------------- + // Clean the cache, forcing the pool to read the objects from the DB + vnpool->clean(); + + // Get by name + vnet_name = vnpool->get(name_0, uid_0, true); + CPPUNIT_ASSERT(vnet_name != 0); + vnet_name->unlock(); + + // Get by oid and check it is the same object + vnet_oid = vnpool->get(oid_0, true); + CPPUNIT_ASSERT(vnet_oid != 0); + vnet_oid->unlock(); + + CPPUNIT_ASSERT(vnet_oid == vnet_name); + } }; /* ************************************************************************* */