[Archipelago-submits] [186] trunk/archipelago: added working but incomplete sanitation officer and test

nobody at rubyforge.org nobody at rubyforge.org
Tue Jan 23 10:59:01 EST 2007


Revision: 186
Author:   zond
Date:     2007-01-23 10:59:00 -0500 (Tue, 23 Jan 2007)

Log Message:
-----------
added working but incomplete sanitation officer and test

Modified Paths:
--------------
    trunk/archipelago/lib/archipelago/dump.rb
    trunk/archipelago/lib/archipelago/sanitation.rb
    trunk/archipelago/tests/dump_test.rb

Added Paths:
-----------
    trunk/archipelago/tests/sanitation_test.rb

Modified: trunk/archipelago/lib/archipelago/dump.rb
===================================================================
--- trunk/archipelago/lib/archipelago/dump.rb	2007-01-23 14:57:30 UTC (rev 185)
+++ trunk/archipelago/lib/archipelago/dump.rb	2007-01-23 15:59:00 UTC (rev 186)
@@ -20,6 +20,7 @@
 require 'archipelago/disco'
 require 'archipelago/hashish'
 require 'archipelago/sanitation'
+require 'pathname'
 
 module Archipelago
 
@@ -65,7 +66,7 @@
         return db.duplicates(key)
       end
 
-      def delete(key, owner_id)
+      def delete!(key, owner_id)
         db = @dbs[owner_id] ||= @persistence_provider.get_dup_hashish(owner_id)
         db.delete(key)
         return nil

Modified: trunk/archipelago/lib/archipelago/sanitation.rb
===================================================================
--- trunk/archipelago/lib/archipelago/sanitation.rb	2007-01-23 14:57:30 UTC (rev 185)
+++ trunk/archipelago/lib/archipelago/sanitation.rb	2007-01-23 15:59:00 UTC (rev 186)
@@ -81,6 +81,15 @@
         end
       end
 
+      def delete!(key)
+        dumps = responsible_dumps(key, @minimum_nr_of_chunks)
+        owner_id = dumps.first[:service_id]
+        dumps.each do |dump|
+          dump[:service].delete!(key, 
+                                 owner_id)
+        end
+      end
+
       def [](key)
         dumps = responsible_dumps(key, @minimum_nr_of_chunks)
         owner_id = dumps.first[:service_id]
@@ -89,7 +98,7 @@
         decoded = false
         found_chunks = false
         while !decoded && dumps.size > 0
-          dumps.shift.fetch(key, owner_id).each do |chunk|
+          dumps.shift[:service].fetch(key, owner_id).each do |chunk|
             found_chunks = true
             decoded = decoded || rval.decode!(chunk)
           end
@@ -109,16 +118,16 @@
       end
 
       #
-      # Returns the +n+ services in our @dumps Hash that have keys
+      # Returns the +n+ services in our @sites Hash that have keys
       # greater than +key+.
       #
       # Will loop to the beginning if the number of elements run out.
       #
       def responsible_dumps(key, n)
-        raise NoRemoteDatabaseAvailableException.new(self) if @dumps.empty?
+        raise NoRemoteDatabaseAvailableException.new(self) if @sites.empty?
 
-        get_least_greater_than(@dumps, key, n).collect do |id|
-          @dumps[id]
+        get_least_greater_than(@sites, key, n).collect do |id|
+          @sites[id]
         end
       end
 

Modified: trunk/archipelago/tests/dump_test.rb
===================================================================
--- trunk/archipelago/tests/dump_test.rb	2007-01-23 14:57:30 UTC (rev 185)
+++ trunk/archipelago/tests/dump_test.rb	2007-01-23 15:59:00 UTC (rev 186)
@@ -24,8 +24,8 @@
                  @d.fetch("key2", "owner"))
     assert_equal(["value3"],
                  @d.fetch("key2", "owner2"))
-    @d.delete("key", "owner")
-    @d.delete("key2", "owner2")
+    @d.delete!("key", "owner")
+    @d.delete!("key2", "owner2")
     assert_equal([],
                  @d.fetch("key", "owner"))
     assert_equal([],

Added: trunk/archipelago/tests/sanitation_test.rb
===================================================================
--- trunk/archipelago/tests/sanitation_test.rb	                        (rev 0)
+++ trunk/archipelago/tests/sanitation_test.rb	2007-01-23 15:59:00 UTC (rev 186)
@@ -0,0 +1,29 @@
+
+require File.join(File.dirname(__FILE__), 'test_helper')
+
+class SanitationTest < Test::Unit::TestCase
+
+  def setup
+    DRb.start_service
+    @d = Archipelago::Dump::Site.new(:persistence_provider => Archipelago::Hashish::BerkeleyHashishProvider.new(Pathname.new(__FILE__).parent.join("site.db")))
+    @d.publish!
+    assert_within(10) do 
+      s = Archipelago::Sanitation::CLEANER.instance_eval do @sites end
+      s.keys == [@d.service_id]
+    end
+  end
+
+  def teardown
+    @d.stop!
+    @d.instance_eval do @persistence_provider.unlink! end
+    DRb.stop_service
+  end
+
+  def test_get_set
+    Archipelago::Sanitation::CLEANER["hej"] = "hoho"
+    assert_equal(Archipelago::Sanitation::CLEANER["hej"], "hoho")
+    Archipelago::Sanitation::CLEANER.delete!("hej")
+    assert_equal(Archipelago::Sanitation::CLEANER["hej"], nil)
+  end
+
+end




More information about the Archipelago-submits mailing list