summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--combox/events.py11
-rw-r--r--tests/events_test.py58
2 files changed, 66 insertions, 3 deletions
diff --git a/combox/events.py b/combox/events.py
index 609ed8e..bc6fe8b 100644
--- a/combox/events.py
+++ b/combox/events.py
@@ -373,6 +373,11 @@ class NodeDirMonitor(LoggingEventHandler):
# means, file was modified on another computer (also
# running combox). so, reconstruct the file and put it
# in the combox directory.
- decrypt_and_glue(file_cb_path, self.config)
- # update db.
- self.silo.update(file_cb_path)
+ with self.lock:
+ self.silo.node_set('file_modified', file_cb_path)
+ num = self.silo.node_get('file_modified', file_cb_path)
+ if num == self.num_nodes:
+ decrypt_and_glue(file_cb_path, self.config)
+ # update db.
+ self.silo.update(file_cb_path)
+ self.silo.node_rem('file_modified', file_cb_path)
diff --git a/tests/events_test.py b/tests/events_test.py
index a0001b5..ae626b8 100644
--- a/tests/events_test.py
+++ b/tests/events_test.py
@@ -303,6 +303,64 @@ class TestEvents(object):
observers[i].join()
+ def test_NDM_onmodified(self):
+ """Testing on_modified method in NodeDirMonitor"""
+ nodes = get_nodedirs(self.config)
+ num_nodes = len(get_nodedirs(self.config))
+
+ nmonitors = []
+ observers = []
+
+ # create an observer for each node directory and make it
+ # monitor them.
+ for node in nodes:
+ nmonitor = NodeDirMonitor(self.config, self.silo_lock,
+ self.nodem_lock)
+ observer = Observer()
+ observer.schedule(nmonitor, node, recursive=True)
+ observer.start()
+
+ nmonitors.append(nmonitor)
+ observers.append(observer)
+
+ # Test - shard modification
+ self.lorem_file = path.join(self.FILES_DIR, 'lorem.txt')
+ lorem_content = read_file(self.lorem_file)
+ self.lorem_file_copy = "%s.copy" % self.lorem_file
+
+ copyfile(self.lorem_file, self.lorem_file_copy)
+ split_and_encrypt(self.lorem_file_copy, self.config,
+ lorem_content)
+
+ self.silo.update(self.lorem_file_copy)
+ shardedp(self.lorem_file_copy)
+
+ self.silo.reload()
+ lorem_file_copy_hash = self.silo.db.get(self.lorem_file_copy)
+
+ self.ipsum_file = path.join(self.FILES_DIR, 'ipsum.txt')
+ ipsum_content = read_file(self.ipsum_file)
+ lorem_copy_content = "%s\n%s" % (lorem_content, ipsum_content)
+
+ split_and_encrypt(self.lorem_file_copy, self.config,
+ lorem_copy_content)
+ time.sleep(1)
+ assert lorem_copy_content == read_file(self.lorem_file_copy)
+
+ ## check if the lorem_file_copy's info is updated in silo
+ self.silo.reload()
+ assert lorem_file_copy_hash != self.silo.db.get(self.lorem_file_copy)
+ assert_equal(None, self.silo.node_get('file_modified',
+ self.lorem_file_copy))
+
+ self.purge_list.append(self.lorem_file_copy)
+
+ # stop the zarking observers.
+ for i in range(num_nodes):
+ observers[i].stop()
+ observers[i].join()
+
+
def untest_NDM(self):
"""
Tests the NodeDirMonitor class.