summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-08-25 23:15:22 -0400
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-08-25 23:15:22 -0400
commitcd2900ad565fd4e77c68607aabc819184f4ffc06 (patch)
tree71245a3fad1ab70bab0a81115482f9414a7dbcb4
parent61577b31f04249e58b37971683215fc46f5ecfb0 (diff)
added new function file.no_of_shards + tests.
modified: combox/file.py modified: tests/file_test.py
-rw-r--r--combox/file.py16
-rw-r--r--tests/file_test.py30
2 files changed, 46 insertions, 0 deletions
diff --git a/combox/file.py b/combox/file.py
index 81d15fe..a8e345b 100644
--- a/combox/file.py
+++ b/combox/file.py
@@ -420,3 +420,19 @@ def read_shards(directories, shard_basename):
shards.append(shard_content)
return shards
+
+
+def no_of_shards(cb_path, config):
+ """Returns the no. of shards that exists for `cb_path' in node directories.
+
+ cb_path: path to file in combox directory.
+ """
+
+ no_shards_there = 0
+ shard_paths = node_paths(cb_path, config, isfile=True)
+
+ for shard in shard_paths:
+ if path.isfile(shard):
+ no_shards_there += 1
+
+ return no_shards_there
diff --git a/tests/file_test.py b/tests/file_test.py
index d8a77ca..f3a153d 100644
--- a/tests/file_test.py
+++ b/tests/file_test.py
@@ -222,6 +222,36 @@ class TestFile(object):
self.purge_list.append(new_dir)
+ def test_noofshards(self):
+ """Tests the node_paths function."""
+ nodes = get_nodedirs(self.config)
+ node_iter = iter(nodes)
+ lorem = path.join(self.config['combox_dir'], 'lorem.txt')
+
+ # get the shards on the node directories
+ split_and_encrypt(lorem, self.config)
+
+ # no. of shards must be equal to no. of node directories.
+ assert_equal(no_of_shards(lorem, self.config),
+ len(nodes))
+
+ n_paths = node_paths(lorem, self.config, isfile=True)
+
+ # now remove first shard
+ rm_path(n_paths[0])
+ # no. of shards must be equal to one less than the no. of node
+ # directories.
+ assert_equal(no_of_shards(lorem, self.config),
+ len(nodes) - 1)
+
+ # now remove second shard
+ rm_path(n_paths[1])
+ # no. of shards must be equal to two less than the no. of node
+ # directories.
+ assert_equal(no_of_shards(lorem, self.config),
+ len(nodes) - 2)
+
+
def teardown(self):
"""Cleans up things after each test in this class."""
purge(self.purge_list)