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

add get_smallest_folder method and test

parent 5ae2efd6
import unittest
import random
from xtreemfs_client import osd
class TestOsd(unittest.TestCase):
def test_get_smallest_folder(self):
test_folders = [("folder_1", 1), ("folder_2", 2), ("folder_3", 3), ("folder_4", 4)]
for i in range(0, 10):
test_osd = osd.OSD("osd_uuid")
random.shuffle(test_folders)
for folder_id, folder_size in test_folders:
test_osd.add_folder(folder_id, folder_size)
self.assertEqual(("folder_1", 1), test_osd.get_smallest_folder())
......@@ -31,6 +31,15 @@ class OSD(object):
def contains_folder(self, folder_id):
return folder_id in self.folders
def get_smallest_folder(self):
smallest_id = None
smallest_size = 0
for id, size in self.folders.items():
if smallest_id is None or size < smallest_size:
smallest_id, smallest_size = id, size
return smallest_id, smallest_size
def __str__(self):
return "osd: '" + self.uuid \
+ "' totalFolderSize: " + str(self.total_folder_size) \
......
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