summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-03-31 20:28:42 -0400
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-03-31 20:28:42 -0400
commit370e6ecf0fc5a493878fe4e0171254b632d72471 (patch)
tree137a5005ee5159cd7f54484153826d7fa094ca5c
parentd26dfc87e40dfb34481edbed75e0200931e9a815 (diff)
new methods in combox.silo.ComboxSilo -- node_get, node_set. noddicts.
These methods will be used to manage the dictionaries in the db related to the zarking shards. modified: combox/silo.py modified: tests/silo_test.py
-rw-r--r--combox/silo.py39
-rw-r--r--tests/silo_test.py110
2 files changed, 149 insertions, 0 deletions
diff --git a/combox/silo.py b/combox/silo.py
index 4f5b746..55345c9 100644
--- a/combox/silo.py
+++ b/combox/silo.py
@@ -124,3 +124,42 @@ class ComboxSilo(object):
return False
else:
return True
+
+
+ def nodedicts(self):
+ """
+ Returns a list containing the dicts related the the node directories.
+ """
+ return self.node_dicts
+
+
+ def node_set(self, type_, file_):
+ """
+ Update information about the shard of `file_'.
+
+ type_: 'shard_created', 'shard_modified', 'shard_moved', 'shard_deleted'
+ file_: path of the file_ in combox directory.
+ """
+
+ with self.lock:
+ try:
+ num = self.db.dget(type_, file_)
+ num += 1
+ except KeyError, e:
+ # means file_ is not already there, so:
+ num = 1
+ self.db.dadd(type_, (file_, num))
+
+
+ def node_get(self, type_, file_):
+ """
+ Returns a number denoting the number of node directories in which the file_'s shard was created/modified/moved/deleted.
+
+ type_: 'shard_created', 'shard_modified', 'shard_moved', 'shard_deleted'
+ file_: path of the file_ in combox directory.
+ """
+ try:
+ return self.db.dget(type_, file_)
+ except KeyError, e:
+ # file_ info not there under type_ dict.
+ return None
diff --git a/tests/silo_test.py b/tests/silo_test.py
index 1a290b4..9c4fc8f 100644
--- a/tests/silo_test.py
+++ b/tests/silo_test.py
@@ -24,6 +24,8 @@ from os import path, remove
from combox.silo import ComboxSilo
from combox.file import read_file, write_file, hash_file
+from nose.tools import *
+
from tests.utils import get_config, rm_nodedirs, rm_configdir
class TestSilo(object):
@@ -93,6 +95,114 @@ class TestSilo(object):
assert not csilo.exists(self.LOREM_IPSUM)
+ def test_csilo_node_dicts(self):
+ """Tests ComboxSilo class, if the dictinaries need for housekeeping
+ node directories are created.
+
+ """
+ silo = ComboxSilo(self.config)
+ keys = silo.db.db.keys()
+
+ node_dicts = ['shard_created', 'shard_modified', 'shard_moved',
+ 'shard_deleted']
+ for ndict in node_dicts:
+ assert ndict in keys
+
+
+ def test_csilo_nodset_create(self):
+ """Tests node_set method, in ComboxSilo class, when type is 'shard_created'.
+ """
+
+ silo = ComboxSilo(self.config)
+ silo.node_set('shard_created', self.LOREM)
+ silo.node_set('shard_created', self.LOREM)
+ silo.node_set('shard_created', self.LOREM)
+
+ silo.node_set('shard_created', self.IPSUM)
+ silo.node_set('shard_created', self.IPSUM)
+ silo.node_set('shard_created', self.IPSUM)
+ silo.node_set('shard_created', self.IPSUM)
+
+ dict_shard_created = silo.db.get('shard_created')
+ assert_equal(3, dict_shard_created[self.LOREM])
+ assert_equal(4, dict_shard_created[self.IPSUM])
+
+
+ def test_csilo_nodset_modified(self):
+ """Tests node_set method, in ComboxSilo class, when type is 'shard_modified'.
+ """
+
+ silo = ComboxSilo(self.config)
+ silo.node_set('shard_modified', self.LOREM)
+ silo.node_set('shard_modified', self.LOREM)
+ silo.node_set('shard_modified', self.LOREM)
+
+ silo.node_set('shard_modified', self.IPSUM)
+ silo.node_set('shard_modified', self.IPSUM)
+ silo.node_set('shard_modified', self.IPSUM)
+ silo.node_set('shard_modified', self.IPSUM)
+
+ dict_shard_modified = silo.db.get('shard_modified')
+ assert_equal(3, dict_shard_modified[self.LOREM])
+ assert_equal(4, dict_shard_modified[self.IPSUM])
+
+
+ def test_csilo_nodset_moved(self):
+ """Tests node_set method, in ComboxSilo class, when type is 'shard_moved'.
+ """
+
+ silo = ComboxSilo(self.config)
+ silo.node_set('shard_moved', self.LOREM)
+ silo.node_set('shard_moved', self.LOREM)
+ silo.node_set('shard_moved', self.LOREM)
+
+ silo.node_set('shard_moved', self.IPSUM)
+ silo.node_set('shard_moved', self.IPSUM)
+ silo.node_set('shard_moved', self.IPSUM)
+ silo.node_set('shard_moved', self.IPSUM)
+
+ dict_shard_moved = silo.db.get('shard_moved')
+ assert_equal(3, dict_shard_moved[self.LOREM])
+ assert_equal(4, dict_shard_moved[self.IPSUM])
+
+
+ def test_csilo_nodset_shard_deleted(self):
+ """Tests node_set method in ComboxSilo class, when type is 'shard_deleted'.
+ """
+
+ silo = ComboxSilo(self.config)
+ silo.node_set('shard_deleted', self.LOREM)
+ silo.node_set('shard_deleted', self.LOREM)
+ silo.node_set('shard_deleted', self.LOREM)
+
+ silo.node_set('shard_deleted', self.IPSUM)
+ silo.node_set('shard_deleted', self.IPSUM)
+ silo.node_set('shard_deleted', self.IPSUM)
+ silo.node_set('shard_deleted', self.IPSUM)
+
+ dict_shard_deleted = silo.db.get('shard_deleted')
+ assert_equal(3, dict_shard_deleted[self.LOREM])
+ assert_equal(4, dict_shard_deleted[self.IPSUM])
+
+
+ def test_csilo_nodeget(self):
+ """Tests node_get method in ComboxSilo class
+ """
+ silo = ComboxSilo(self.config)
+ assert_equal(None, silo.node_get('shard_created', self.LOREM))
+
+ silo.node_set('shard_created', self.LOREM)
+ silo.node_set('shard_created', self.LOREM)
+ assert_equal(2, silo.node_get('shard_created', self.LOREM))
+
+
+ def teardown(self):
+ """Cleans up things after each test in this class"""
+
+ silo = ComboxSilo(self.config)
+ silo.db.deldb()
+
+
@classmethod
def teardown_class(self):
"""Purge the mess created by this test"""