From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/test/drb/drbtest.rb | 368 ++++++++++++++++++++++++++++++++++ jni/ruby/test/drb/ignore_test_drb.rb | 13 ++ jni/ruby/test/drb/test_acl.rb | 197 ++++++++++++++++++ jni/ruby/test/drb/test_drb.rb | 357 +++++++++++++++++++++++++++++++++ jni/ruby/test/drb/test_drbssl.rb | 76 +++++++ jni/ruby/test/drb/test_drbunix.rb | 59 ++++++ jni/ruby/test/drb/ut_array.rb | 16 ++ jni/ruby/test/drb/ut_array_drbssl.rb | 40 ++++ jni/ruby/test/drb/ut_array_drbunix.rb | 16 ++ jni/ruby/test/drb/ut_drb.rb | 167 +++++++++++++++ jni/ruby/test/drb/ut_drb_drbssl.rb | 41 ++++ jni/ruby/test/drb/ut_drb_drbunix.rb | 17 ++ jni/ruby/test/drb/ut_eq.rb | 36 ++++ jni/ruby/test/drb/ut_eval.rb | 36 ++++ jni/ruby/test/drb/ut_large.rb | 43 ++++ jni/ruby/test/drb/ut_port.rb | 15 ++ jni/ruby/test/drb/ut_safe1.rb | 16 ++ jni/ruby/test/drb/ut_timerholder.rb | 53 +++++ 18 files changed, 1566 insertions(+) create mode 100644 jni/ruby/test/drb/drbtest.rb create mode 100644 jni/ruby/test/drb/ignore_test_drb.rb create mode 100644 jni/ruby/test/drb/test_acl.rb create mode 100644 jni/ruby/test/drb/test_drb.rb create mode 100644 jni/ruby/test/drb/test_drbssl.rb create mode 100644 jni/ruby/test/drb/test_drbunix.rb create mode 100644 jni/ruby/test/drb/ut_array.rb create mode 100644 jni/ruby/test/drb/ut_array_drbssl.rb create mode 100644 jni/ruby/test/drb/ut_array_drbunix.rb create mode 100644 jni/ruby/test/drb/ut_drb.rb create mode 100644 jni/ruby/test/drb/ut_drb_drbssl.rb create mode 100644 jni/ruby/test/drb/ut_drb_drbunix.rb create mode 100644 jni/ruby/test/drb/ut_eq.rb create mode 100644 jni/ruby/test/drb/ut_eval.rb create mode 100644 jni/ruby/test/drb/ut_large.rb create mode 100644 jni/ruby/test/drb/ut_port.rb create mode 100644 jni/ruby/test/drb/ut_safe1.rb create mode 100644 jni/ruby/test/drb/ut_timerholder.rb (limited to 'jni/ruby/test/drb') diff --git a/jni/ruby/test/drb/drbtest.rb b/jni/ruby/test/drb/drbtest.rb new file mode 100644 index 0000000..aac705c --- /dev/null +++ b/jni/ruby/test/drb/drbtest.rb @@ -0,0 +1,368 @@ +require 'test/unit' +require 'drb/drb' +require 'drb/extservm' +require 'timeout' +require 'shellwords' + +module DRbTests + +class DRbService + @@manager = DRb::ExtServManager.new + @@ruby = Shellwords.escape(EnvUtil.rubybin) + @@ruby += " -d" if $DEBUG + def self.add_service_command(nm) + dir = File.dirname(File.expand_path(__FILE__)) + DRb::ExtServManager.command[nm] = [@@ruby, "#{dir}/#{nm}"] + end + + %w(ut_drb.rb ut_array.rb ut_port.rb ut_large.rb ut_safe1.rb ut_eval.rb ut_eq.rb).each do |nm| + add_service_command(nm) + end + @server = @@server = DRb::DRbServer.new('druby://localhost:0', @@manager, {}) + @@manager.uri = @@server.uri + def self.manager + @@manager + end + def self.server + @server || @@server + end + def self.ext_service(name) + timeout(100, RuntimeError) do + manager.service(name) + end + end + def self.finish + @server.instance_variable_get(:@grp).list.each {|th| th.join } + end +end + +class Onecky + include DRbUndumped + def initialize(n) + @num = n + end + + def to_i + @num.to_i + end + + def sleep(n) + Kernel.sleep(n) + to_i + end +end + +class FailOnecky < Onecky + class OneckyError < RuntimeError; end + def to_i + raise(OneckyError, @num.to_s) + end +end + +class XArray < Array + def initialize(ary) + ary.each do |x| + self.push(x) + end + end +end + +module DRbBase + def setup_service(service_name) + @service_name = service_name + @ext = DRbService.ext_service(@service_name) + @there = @ext.front + end + + def teardown + @ext.stop_service if defined?(@ext) && @ext + DRbService.manager.unregist(@service_name) + while (@there&&@there.to_s rescue nil) + # nop + end + signal = /mswin|mingw/ =~ RUBY_PLATFORM ? :KILL : :TERM + Thread.list.each {|th| + if th.respond_to?(:pid) && th[:drb_service] == @service_name + 10.times do + begin + Process.kill signal, th.pid + break + rescue Errno::ESRCH + break + rescue Errno::EPERM # on Windows + sleep 0.1 + retry + end + end + th.join + end + } + end +end + +module DRbCore + include DRbBase + + def test_00_DRbObject + ro = DRbObject.new(nil, 'druby://localhost:12345') + assert_equal('druby://localhost:12345', ro.__drburi) + assert_equal(nil, ro.__drbref) + + ro = DRbObject.new_with_uri('druby://localhost:12345') + assert_equal('druby://localhost:12345', ro.__drburi) + assert_equal(nil, ro.__drbref) + + ro = DRbObject.new_with_uri('druby://localhost:12345?foobar') + assert_equal('druby://localhost:12345', ro.__drburi) + assert_equal(DRb::DRbURIOption.new('foobar'), ro.__drbref) + end + + def test_01 + assert_equal("hello", @there.hello) + onecky = Onecky.new('3') + assert_equal(6, @there.sample(onecky, 1, 2)) + ary = @there.to_a + assert_kind_of(DRb::DRbObject, ary) + + assert(@there.respond_to?(:to_a, true)) + assert(@there.respond_to?(:eval, true)) + assert(! @there.respond_to?(:eval, false)) + assert(! @there.respond_to?(:eval)) + end + + def test_01_02_loop + onecky = Onecky.new('3') + 50.times do + assert_equal(6, @there.sample(onecky, 1, 2)) + ary = @there.to_a + assert_kind_of(DRb::DRbObject, ary) + end + end + + def test_02_unknown + obj = @there.unknown_class + assert_kind_of(DRb::DRbUnknown, obj) + assert_equal('DRbTests::Unknown2', obj.name) + + obj = @there.unknown_module + assert_kind_of(DRb::DRbUnknown, obj) + assert_equal('DRbTests::DRbEx::', obj.name) + + assert_raise(DRb::DRbUnknownError) do + @there.unknown_error + end + + onecky = FailOnecky.new('3') + + assert_raise(FailOnecky::OneckyError) do + @there.sample(onecky, 1, 2) + end + end + + def test_03 + assert_equal(8, @there.sum(1, 1, 1, 1, 1, 1, 1, 1)) + assert_raise(DRb::DRbConnError) do + @there.sum(1, 1, 1, 1, 1, 1, 1, 1, 1) + end + assert_raise(DRb::DRbConnError) do + @there.sum('1' * 4096) + end + end + + def test_04 + assert_respond_to(@there, 'sum') + assert(!(@there.respond_to? "foobar")) + end + + def test_05_eq + a = @there.to_a[0] + b = @there.to_a[0] + assert(a.object_id != b.object_id) + assert(a == b) + assert_equal(a, b) + assert(a == @there) + assert_equal(a.hash, b.hash) + assert_equal(a.hash, @there.hash) + assert(a.eql?(b)) + assert(a.eql?(@there)) + end + + def test_06_timeout + ten = Onecky.new(10) + assert_raise(Timeout::Error) do + @there.do_timeout(ten) + end + assert_raise(Timeout::Error) do + @there.do_timeout(ten) + end + end + + def test_07_public_private_protected_missing + assert_nothing_raised() { + begin + @there.method_missing(:eval, 'nil') + rescue NoMethodError + assert_match(/^private method \`eval\'/, $!.message) + end + } + assert_nothing_raised() { + begin + @there.call_private_method + rescue NoMethodError + assert_equal(NoMethodError, $!.class) + assert_match(/^private method \`call_private_method\'/, $!.message) + end + } + assert_nothing_raised() { + begin + @there.call_protected_method + rescue NoMethodError + assert_equal(NoMethodError, $!.class) + assert_match(/^protected method \`call_protected_method\'/, $!.message) + end + } + assert_nothing_raised() { + begin + @there.method_missing(:undefined_method_test) + rescue NoMethodError + assert_equal(NoMethodError, $!.class) + assert_match(/^undefined method \`undefined_method_test\'/, $!.message) + end + } + assert_raise(DRb::DRbConnError) do + @there.method_missing(:__send__, :to_s) + end + assert_equal(true, @there.missing) + end + + def test_08_here + ro = DRbObject.new(nil, DRb.uri) + assert_kind_of(String, ro.to_s) + + ro = DRbObject.new_with_uri(DRb.uri) + assert_kind_of(String, ro.to_s) + end + + def uri_concat_option(uri, opt) + "#{uri}?#{opt}" + end + + def test_09_option + uri = uri_concat_option(@there.__drburi, "foo") + ro = DRbObject.new_with_uri(uri) + assert_equal(ro.__drburi, @there.__drburi) + assert_equal(3, ro.size) + + uri = uri_concat_option(@there.__drburi, "") + ro = DRbObject.new_with_uri(uri) + assert_equal(ro.__drburi, @there.__drburi) + assert_equal(DRb::DRbURIOption.new(''), ro.__drbref) + + uri = uri_concat_option(@there.__drburi, "hello?world") + ro = DRbObject.new_with_uri(uri) + assert_equal(DRb::DRbURIOption.new('hello?world'), ro.__drbref) + + uri = uri_concat_option(@there.__drburi, "?hello?world") + ro = DRbObject.new_with_uri(uri) + assert_equal(DRb::DRbURIOption.new('?hello?world'), ro.__drbref) + end + + def test_10_yield + @there.simple_hash.each do |k, v| + assert_kind_of(String, k) + assert_kind_of(Symbol, v) + end + end + + def test_10_yield_undumped + @there.xarray2_hash.each do |k, v| + assert_kind_of(String, k) + assert_kind_of(DRbObject, v) + end + end + + def test_11_remote_no_method_error + assert_raise(DRb::DRbRemoteError) do + @there.remote_no_method_error + end + begin + @there.remote_no_method_error + rescue + error = $! + assert_match(/^undefined method .*\(NoMethodError\)/, error.message) + assert_equal('NoMethodError', error.reason) + end + end +end + +module DRbAry + include DRbBase + + def test_01 + assert_kind_of(DRb::DRbObject, @there) + end + + def test_02_collect + ary = @there.collect do |x| x + x end + assert_kind_of(Array, ary) + assert_equal([2, 4, 'IIIIII', 8, 'fivefive', 12], ary) + end + + def test_03_redo + ary = [] + count = 0 + @there.each do |x| + count += 1 + ary.push x + redo if count == 3 + end + assert_equal([1, 2, 'III', 'III', 4, 'five', 6], ary) + end + + # retry in block is not supported on ruby 1.9 + #def test_04_retry + # retried = false + # ary = [] + # @there.each do |x| + # ary.push x + # if x == 4 && !retried + # retried = true + # retry + # end + # end + # assert_equal([1, 2, 'III', 4, 1, 2, 'III', 4, 'five', 6], ary) + #end + + def test_05_break + ary = [] + @there.each do |x| + ary.push x + break if x == 4 + end + assert_equal([1, 2, 'III', 4], ary) + end + + def test_06_next + ary = [] + @there.each do |x| + next if String === x + ary.push x + end + assert_equal([1, 2, 4, 6], ary) + end + + class_eval < " unless it + it + end + + DRb.start_service('druby://localhost:0', [1, 2, 'III', 4, "five", 6]) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end + diff --git a/jni/ruby/test/drb/ut_array_drbssl.rb b/jni/ruby/test/drb/ut_array_drbssl.rb new file mode 100644 index 0000000..fa9afa6 --- /dev/null +++ b/jni/ruby/test/drb/ut_array_drbssl.rb @@ -0,0 +1,40 @@ +require 'drb/drb' +require 'drb/extserv' +require 'drb/ssl' + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + module DRbTests + + TEST_KEY_DH1024 = OpenSSL::PKey::DH.new <<-_end_of_pem_ +-----BEGIN DH PARAMETERS----- +MIGHAoGBAKnKQ8MNK6nYZzLrrcuTsLxuiJGXoOO5gT+tljOTbHBuiktdMTITzIY0 +pFxIvjG05D7HoBZQfrR0c92NGWPkAiCkhQKB8JCbPVzwNLDy6DZ0pmofDKrEsYHG +AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC +-----END DH PARAMETERS----- + _end_of_pem_ + + TEST_KEY_DH1024.priv_key = OpenSSL::BN.new("48561834C67E65FFD2A9B47F41E5E78FDC95C387428FDB1E4B0188B64D1643C3A8D3455B945B7E8C4D166010C7C2CE23BFB9BEF43D0348FE7FA5284B0225E7FE1537546D114E3D8A4411B9B9351AB451E1A358F50ED61B1F00DA29336EEBBD649980AC86D76AF8BBB065298C2052672EEF3EF13AB47A15275FC2836F3AC74CEA", 16) + + end + + config = Hash.new + config[:SSLTmpDhCallback] = proc { DRbTests::TEST_KEY_DH1024 } + config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER + config[:SSLVerifyCallback] = lambda{|ok,x509_store| + true + } + config[:SSLCertName] = + [ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ] + + DRb.start_service('drbssl://localhost:0', [1, 2, 'III', 4, "five", 6], config) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end + diff --git a/jni/ruby/test/drb/ut_array_drbunix.rb b/jni/ruby/test/drb/ut_array_drbunix.rb new file mode 100644 index 0000000..dd39790 --- /dev/null +++ b/jni/ruby/test/drb/ut_array_drbunix.rb @@ -0,0 +1,16 @@ +require 'drb/drb' +require 'drb/extserv' + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + DRb.start_service('drbunix:', [1, 2, 'III', 4, "five", 6]) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end + diff --git a/jni/ruby/test/drb/ut_drb.rb b/jni/ruby/test/drb/ut_drb.rb new file mode 100644 index 0000000..c2a5f62 --- /dev/null +++ b/jni/ruby/test/drb/ut_drb.rb @@ -0,0 +1,167 @@ +require 'drb/drb' +require 'drb/extserv' +require 'timeout' + +module DRbTests + +class XArray < Array + def initialize(ary) + ary.each do |x| + self.push(x) + end + end +end + +class XArray2 < XArray + include DRbUndumped +end + +class Unknown2 + def initialize + @foo = 'unknown2' + end +end + +class DRbEx + include DRbUndumped + + class FooBar + def initialize + @foo = 'bar' + end + end + + class UError < RuntimeError; end + + def initialize + @xary2_hash = nil + @hash = nil + @hello = 'hello' + end + attr_reader :hello + + def sample(a, b, c) + a.to_i + b.to_i + c.to_i + end + + def sum(*a) + s = 0 + a.each do |e| + s += e.to_i + end + s + end + + def do_timeout(n) + timeout(0.1) do + n.sleep(2) + end + end + + def unknown_module + FooBar.new + end + + def unknown_class + Unknown2.new + end + + def unknown_error + raise UError + end + + def remote_no_method_error + invoke_no_method(self) + end + + def test_yield + yield + yield([]) + yield(*[]) + end + + def echo_yield(*arg) + yield(*arg) + nil + end + + def echo_yield_0 + yield + nil + end + + def echo_yield_1(one) + yield(one) + nil + end + + def echo_yield_2(one, two) + yield(one, two) + nil + end + + def xarray_each + xary = [XArray.new([0])] + xary.each do |x| + yield(x) + end + nil + end + + def xarray2_hash + unless @xary2_hash + @xary2_hash = { "a" => XArray2.new([0]), "b" => XArray2.new([1]) } + end + DRbObject.new(@xary2_hash) + end + + def simple_hash + unless @hash + @hash = { 'a'=>:a, 'b'=>:b } + end + DRbObject.new(@hash) + end + + def [](key) + key.to_s + end + + def to_a + [self] + end + + def method_missing(msg, *a, &b) + if msg == :missing + return true + else + super(msg, *a, &b) + end + end + + private + def call_private_method + true + end + + protected + def call_protected_method + true + end +end + +end + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + DRb::DRbServer.default_argc_limit(8) + DRb::DRbServer.default_load_limit(4096) + DRb.start_service('druby://localhost:0', DRbTests::DRbEx.new) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end diff --git a/jni/ruby/test/drb/ut_drb_drbssl.rb b/jni/ruby/test/drb/ut_drb_drbssl.rb new file mode 100644 index 0000000..b6d1c12 --- /dev/null +++ b/jni/ruby/test/drb/ut_drb_drbssl.rb @@ -0,0 +1,41 @@ +require_relative "ut_drb" +require 'drb/ssl' + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + module DRbTests + + TEST_KEY_DH1024 = OpenSSL::PKey::DH.new <<-_end_of_pem_ +-----BEGIN DH PARAMETERS----- +MIGHAoGBAKnKQ8MNK6nYZzLrrcuTsLxuiJGXoOO5gT+tljOTbHBuiktdMTITzIY0 +pFxIvjG05D7HoBZQfrR0c92NGWPkAiCkhQKB8JCbPVzwNLDy6DZ0pmofDKrEsYHG +AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC +-----END DH PARAMETERS----- + _end_of_pem_ + + TEST_KEY_DH1024.priv_key = OpenSSL::BN.new("48561834C67E65FFD2A9B47F41E5E78FDC95C387428FDB1E4B0188B64D1643C3A8D3455B945B7E8C4D166010C7C2CE23BFB9BEF43D0348FE7FA5284B0225E7FE1537546D114E3D8A4411B9B9351AB451E1A358F50ED61B1F00DA29336EEBBD649980AC86D76AF8BBB065298C2052672EEF3EF13AB47A15275FC2836F3AC74CEA", 16) + + end + + config = Hash.new + config[:SSLTmpDhCallback] = proc { DRbTests::TEST_KEY_DH1024 } + config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER + config[:SSLVerifyCallback] = lambda{|ok,x509_store| + true + } + config[:SSLCertName] = + [ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ] + + DRb::DRbServer.default_argc_limit(8) + DRb::DRbServer.default_load_limit(4096) + DRb.start_service('drbssl://localhost:0', DRbTests::DRbEx.new, config) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end + diff --git a/jni/ruby/test/drb/ut_drb_drbunix.rb b/jni/ruby/test/drb/ut_drb_drbunix.rb new file mode 100644 index 0000000..c997d24 --- /dev/null +++ b/jni/ruby/test/drb/ut_drb_drbunix.rb @@ -0,0 +1,17 @@ +require "#{File.dirname(File.expand_path(__FILE__))}/ut_drb" + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + DRb::DRbServer.default_argc_limit(8) + DRb::DRbServer.default_load_limit(4096) + DRb.start_service('drbunix:', DRbTests::DRbEx.new) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end + diff --git a/jni/ruby/test/drb/ut_eq.rb b/jni/ruby/test/drb/ut_eq.rb new file mode 100644 index 0000000..cc86158 --- /dev/null +++ b/jni/ruby/test/drb/ut_eq.rb @@ -0,0 +1,36 @@ +require 'drb/drb' +require 'drb/extserv' + +module DRbTests + +class Foo + include DRbUndumped +end + +class Bar + include DRbUndumped + def initialize + @foo = Foo.new + end + attr_reader :foo + + def foo?(foo) + @foo == foo + end +end + +end + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + DRb.start_service('druby://localhost:0', DRbTests::Bar.new) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end + diff --git a/jni/ruby/test/drb/ut_eval.rb b/jni/ruby/test/drb/ut_eval.rb new file mode 100644 index 0000000..c456790 --- /dev/null +++ b/jni/ruby/test/drb/ut_eval.rb @@ -0,0 +1,36 @@ +require 'drb/drb' +require 'drb/extserv' + +module DRbTests + +class EvalAttack + def initialize + @four = DRb::DRbServer.new('druby://localhost:0', self, {:safe_level => 4}) + end + + def four + DRbObject.new_with_uri(@four.uri) + end + + def remote_class + DRbObject.new(self.class) + end +end + +end + + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + $SAFE = 1 + + DRb.start_service('druby://localhost:0', DRbTests::EvalAttack.new, {:safe_level => 2}) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end diff --git a/jni/ruby/test/drb/ut_large.rb b/jni/ruby/test/drb/ut_large.rb new file mode 100644 index 0000000..c2fbd3e --- /dev/null +++ b/jni/ruby/test/drb/ut_large.rb @@ -0,0 +1,43 @@ +require 'drb/drb' +require 'drb/extserv' +require 'timeout' + +module DRbTests + +class DRbLarge + include DRbUndumped + + def size(ary) + ary.size + end + + def sum(ary) + sum = 0 + ary.each do |e| + sum += e.to_i + end + sum + end + + def arg_test(*arg) + # nop + end +end + +end + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + DRb::DRbServer.default_argc_limit(3) + DRb::DRbServer.default_load_limit(100000) + DRb.start_service('druby://localhost:0', DRbTests::DRbLarge.new) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end + diff --git a/jni/ruby/test/drb/ut_port.rb b/jni/ruby/test/drb/ut_port.rb new file mode 100644 index 0000000..3009db5 --- /dev/null +++ b/jni/ruby/test/drb/ut_port.rb @@ -0,0 +1,15 @@ +require 'drb/drb' +require 'drb/extserv' + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + DRb.start_service('druby://:8473', [1, 2, 'III', 4, "five", 6]) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end diff --git a/jni/ruby/test/drb/ut_safe1.rb b/jni/ruby/test/drb/ut_safe1.rb new file mode 100644 index 0000000..43eb367 --- /dev/null +++ b/jni/ruby/test/drb/ut_safe1.rb @@ -0,0 +1,16 @@ +require 'drb/drb' +require 'drb/extserv' + +if __FILE__ == $0 + def ARGV.shift + it = super() + raise "usage: #{$0} " unless it + it + end + + DRb.start_service('druby://localhost:0', [1, 2, 'III', 4, "five", 6], + {:safe_level => 1}) + es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) + DRb.thread.join + es.stop_service if es.alive? +end diff --git a/jni/ruby/test/drb/ut_timerholder.rb b/jni/ruby/test/drb/ut_timerholder.rb new file mode 100644 index 0000000..6c62ea7 --- /dev/null +++ b/jni/ruby/test/drb/ut_timerholder.rb @@ -0,0 +1,53 @@ +require 'runit/testcase' +require 'runit/cui/testrunner' +require 'timerholder' + +module DRbTests + +class TimerHolderTest < RUNIT::TestCase + def do_test(timeout, keeper_sleep = nil) + holder = TimerHolder.new(timeout) + holder.keeper_sleep = keeper_sleep if keeper_sleep + key = holder.add(self) + sleep(timeout * 0.5) + assert_equal(holder.peek(key), self) + holder.delete(key) + assert(!holder.include?(key)) + key = holder.add(self) + sleep(timeout+0.5) + assert_equal(holder.fetch(key), nil) + key = holder.add(self) + assert_equal(holder.fetch(key), self) + holder.store(key, true) + assert_equal(holder.fetch(key), true) + assert_equal(holder.include?(key), true) + sleep(timeout+0.5) + assert_exception(TimerHolder::InvalidIndexError) do + holder.store(key, 1) + end + assert_equal(holder.include?(key), false) + key = holder.add(self) + sleep(timeout * 0.5) + assert(holder.include?(key)) + holder.extend(key, timeout) + sleep(timeout * 0.5) + assert(holder.include?(key)) + sleep(timeout * 0.6) + assert(!holder.include?(key)) + holder.delete(key) + end + + def test_00 + do_test(0.5) + end + + def test_01 + do_test(1, 0.5) + end +end + +end + +if __FILE__ == $0 + RUNIT::CUI::TestRunner.run(DRbTests::TimerHolderTest.suite) +end -- cgit v1.2.3-70-g09d2