Commit bd66e08f authored by Felix Seibert's avatar Felix Seibert
Browse files

add (failing) test for totally random osd assignment

parent 8a130903
import unittest
from xtreemfs_client import dataDistribution
from xtreemfs_client import osd
from xtreemfs_client import folder
osd_id_prefix = 'osd_'
folder_id_prefix = 'folder_'
osd_capacity_key = 'capacity'
class TestDataDistribution(unittest.TestCase):
def setUp(self):
osd_capacity = 100
capacity_key = 'capacity'
capacities = {}
for i in range(0, 2):
new_osd = osd.OSD('osd' + str(i))
capacities[new_osd.uuid] = {}
capacities[new_osd.uuid][capacity_key] = osd_capacity
def test_totally_random_distribution(self):
# generate some random distributions and check whether they are different
max_osd_total_folder_size = 0
felix_and_farouk_different = False
num_osds = 3
osd_capacity = 100
num_folders = 10
folder_size = 20
for i in range(0, 100):
distribution_felix = dataDistribution.DataDistribution()
distribution_felix.add_osd_list(create_test_osd_list(num_osds))
distribution_felix.add_folders(create_test_folder_list(num_folders, folder_size),
osd_information=create_osd_information(num_osds, osd_capacity),
random_osd_assignment=True,
ignore_osd_capacities=True)
distribution_farouk = dataDistribution.DataDistribution()
distribution_farouk.add_osd_list(create_test_osd_list(num_osds))
distribution_farouk.add_folders(create_test_folder_list(num_folders, folder_size),
osd_information=create_osd_information(num_osds, osd_capacity),
random_osd_assignment=True,
ignore_osd_capacities=True)
osds_felix = distribution_felix.get_osd_list()
osds_felix_total_folder_sizes = list(map(lambda x: x.total_folder_size, osds_felix))
osds_farouk = distribution_farouk.get_osd_list()
osds_farouk_total_folder_sizes = list(map(lambda x: x.total_folder_size, osds_farouk))
print('felix[0]: ' + str(osds_felix_total_folder_sizes[0]))
print('farouk[0]: ' + str(osds_farouk_total_folder_sizes[0]))
if osds_felix_total_folder_sizes[0] != osds_farouk_total_folder_sizes[0]:
felix_and_farouk_different = True
max_felix = max(osds_felix_total_folder_sizes)
max_farouk = max(osds_farouk_total_folder_sizes)
max_osd_total_folder_size = max(max_osd_total_folder_size, max_felix, max_farouk)
self.assertTrue(felix_and_farouk_different)
self.assertTrue(max_osd_total_folder_size > osd_capacity)
def test_value_error(self):
pass
def test_random_distribution_respecting_capacities(self):
pass
def test_round_robin_distribution(self):
pass
def test_lpt_distribution(self):
pass
def create_test_osd_list(num_osds):
test_osds = []
for i in range(0, num_osds):
new_osd = osd.OSD(osd_id_prefix + str(i))
test_osds.append(new_osd)
return test_osds
def create_test_folder_list(num_folders, folder_size):
test_folders = []
for i in range(0, num_folders):
new_folder = folder.Folder(folder_id_prefix + str(i), folder_size, None)
test_folders.append(new_folder)
return test_folders
def create_osd_information(num_osds, osd_capacity):
osd_information = {}
for i in range(0, num_osds):
osd_uuid = osd_id_prefix + str(i)
osd_information[osd_uuid] = {}
osd_information[osd_uuid][osd_capacity_key] = osd_capacity
return osd_information
Supports Markdown
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