summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--lib/rinda/rinda.rb7
-rw-r--r--test/rinda/test_rinda.rb45
3 files changed, 32 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index b17dcecafd..cb35c52385 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Apr 21 23:04:42 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+
+ * lib/rinda/rinda.rb, test/rinda/test_rinda.rb: check Hash tuple size.
+
Wed Apr 21 20:05:00 2004 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb (URI::HTTP#proxy_open): set Host: field explicitly.
diff --git a/lib/rinda/rinda.rb b/lib/rinda/rinda.rb
index 0352a7be90..50fb84696a 100644
--- a/lib/rinda/rinda.rb
+++ b/lib/rinda/rinda.rb
@@ -69,18 +69,15 @@ module Rinda
private
def init_with_ary(ary)
- @tuple_size = ary.size
- @tuple = Array.new(@tuple_size)
+ @tuple = Array.new(ary.size)
@tuple.size.times do |i|
@tuple[i] = ary[i]
end
end
def init_with_hash(hash)
- @tuple_size = hash[:size]
@tuple = Hash.new
hash.each do |k, v|
- next if k == :size
raise InvalidHashTupleKey unless String === k
@tuple[k] = v
end
@@ -97,7 +94,7 @@ module Rinda
def match(tuple)
return false unless tuple.respond_to?(:size)
return false unless tuple.respond_to?(:fetch)
- return false if @tuple_size && (@tuple_size != tuple.size)
+ return false unless self.size == tuple.size
each do |k, v|
begin
it = tuple.fetch(k)
diff --git a/test/rinda/test_rinda.rb b/test/rinda/test_rinda.rb
index 684e44f4f1..28e455ef85 100644
--- a/test/rinda/test_rinda.rb
+++ b/test/rinda/test_rinda.rb
@@ -20,13 +20,13 @@ module TupleSpaceTestModule
assert_equal(3, tmpl[2])
assert(tmpl.match([1,2,3]))
assert(!tmpl.match([1,nil,3]))
-
+
tmpl = Rinda::Template.new([/^rinda/i, nil, :hello])
assert_equal(3, tmpl.size)
assert(tmpl.match(['Rinda', 2, :hello]))
assert(!tmpl.match(['Rinda', 2, Symbol]))
assert(!tmpl.match([1, 2, :hello]))
- assert(tmpl.match([/^rinda/i, nil, :hello]))
+ assert(tmpl.match([/^rinda/i, 2, :hello]))
tmpl = Rinda::Template.new([Symbol])
assert_equal(1, tmpl.size)
@@ -37,8 +37,8 @@ module TupleSpaceTestModule
tmpl = Rinda::Template.new({"message"=>String, "name"=>String})
assert_equal(2, tmpl.size)
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
- assert(tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
- assert(tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
+ assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
+ assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
assert_raises(Rinda::InvalidHashTupleKey) do
@@ -46,42 +46,49 @@ module TupleSpaceTestModule
end
tmpl = Rinda::Template.new({"name"=>String})
assert_equal(1, tmpl.size)
- assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
- assert(tmpl.match({"message"=>:symbol, "name"=>"Foo", "1"=>2}))
- assert(tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
+ assert(tmpl.match({"name"=>"Foo"}))
+ assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
+ assert(!tmpl.match({"message"=>:symbol, "name"=>"Foo", "1"=>2}))
+ assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
- tmpl = Rinda::Template.new({"message"=>String, "name"=>String, :size=>2})
+ tmpl = Rinda::Template.new({"message"=>String, "name"=>String})
assert_equal(2, tmpl.size)
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
- tmpl = Rinda::Template.new({"message"=>String, :size=>2})
+ tmpl = Rinda::Template.new({"message"=>String})
assert_equal(1, tmpl.size)
- assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
+ assert(tmpl.match({"message"=>"Hello"}))
+ assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
- assert(tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
+ assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
tmpl = Rinda::Template.new({"message"=>String, "name"=>nil})
assert_equal(2, tmpl.size)
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
- assert(tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
- assert(tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
- assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
-
- tmpl = Rinda::Template.new({:size=>2})
- assert_equal(0, tmpl.size)
- assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
- assert(tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
+ assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
assert_raises(Rinda::InvalidHashTupleKey) do
@ts.write({:message=>String, "name"=>String})
end
+
+ @ts.write([1, 2, 3])
+ assert_equal([1, 2, 3], @ts.take([1, 2, 3]))
+
+ @ts.write({'1'=>1, '2'=>2, '3'=>3})
+ assert_equal({'1'=>1, '2'=>2, '3'=>3}, @ts.take({'1'=>1, '2'=>2, '3'=>3}))
+
+ entry = @ts.write(['1'=>1, '2'=>2, '3'=>3])
+ assert_raises(Rinda::RequestExpiredError) do
+ assert_equal({'1'=>1, '2'=>2, '3'=>3}, @ts.read({'1'=>1}, 0))
+ end
+ entry.cancel
end
def test_00_DRbObject