1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Bug #1087: Core tests

(cherry picked from commit f10e852fe4c693c069026475e36ecd16b6b32d2a)
This commit is contained in:
Carlos Martín 2012-01-26 19:00:55 +01:00
parent a0d0bd1dbb
commit 03e9b52c55
3 changed files with 197 additions and 0 deletions

View File

@ -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);
}
};

View File

@ -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<VMTemplatePool*>(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);
}
/* ********************************************************************* */
};

View File

@ -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);
}
};