2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2016-05-15 07:59:00 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require 'drb/timeridconv'
|
2003-10-20 11:24:00 -04:00
|
|
|
|
2014-05-31 23:07:58 -04:00
|
|
|
module DRbTests
|
|
|
|
|
2016-05-15 07:59:00 -04:00
|
|
|
class TimerIdConvTest < Test::Unit::TestCase
|
|
|
|
def test_usecase_01
|
|
|
|
keeping = 0.1
|
|
|
|
idconv = DRb::TimerIdConv.new(keeping)
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2016-05-15 07:59:00 -04:00
|
|
|
key = idconv.to_id(self)
|
|
|
|
assert_equal(key, self.__id__)
|
|
|
|
sleep(keeping)
|
|
|
|
assert_equal(idconv.to_id(false), false.__id__)
|
|
|
|
assert_equal(idconv.to_obj(key), self)
|
|
|
|
sleep(keeping)
|
|
|
|
|
|
|
|
assert_equal(idconv.to_obj(key), self)
|
|
|
|
sleep(keeping)
|
|
|
|
|
|
|
|
assert_equal(idconv.to_id(true), true.__id__)
|
|
|
|
sleep(keeping)
|
2003-10-20 11:24:00 -04:00
|
|
|
|
2016-05-15 07:59:00 -04:00
|
|
|
assert_raise do
|
2016-05-22 07:03:43 -04:00
|
|
|
assert_equal(idconv.to_obj(key), self)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise do
|
|
|
|
assert_equal(idconv.to_obj(false.__id__), false)
|
|
|
|
end
|
|
|
|
|
|
|
|
key = idconv.to_id(self)
|
|
|
|
assert_equal(key, self.__id__)
|
|
|
|
assert_equal(idconv.to_id(true), true.__id__)
|
|
|
|
sleep(keeping)
|
|
|
|
GC.start
|
|
|
|
sleep(keeping)
|
|
|
|
GC.start
|
|
|
|
assert_raise do
|
|
|
|
assert_equal(idconv.to_obj(key), self)
|
2016-05-15 07:59:00 -04:00
|
|
|
end
|
2016-05-22 07:03:43 -04:00
|
|
|
end
|
2016-05-15 07:59:00 -04:00
|
|
|
|
2016-05-22 07:03:43 -04:00
|
|
|
def test_usecase_02
|
|
|
|
keeping = 0.1
|
|
|
|
idconv = DRb::TimerIdConv.new(keeping)
|
|
|
|
|
|
|
|
key = idconv.to_id(self)
|
|
|
|
assert_equal(key, self.__id__)
|
|
|
|
sleep(keeping)
|
|
|
|
GC.start
|
|
|
|
sleep(keeping)
|
|
|
|
GC.start
|
|
|
|
assert_raise do
|
|
|
|
assert_equal(idconv.to_obj(key), self)
|
|
|
|
end
|
|
|
|
GC.start
|
|
|
|
|
|
|
|
key = idconv.to_id(self)
|
|
|
|
assert_equal(key, self.__id__)
|
|
|
|
sleep(keeping)
|
|
|
|
GC.start
|
|
|
|
sleep(keeping)
|
|
|
|
GC.start
|
2016-05-15 07:59:00 -04:00
|
|
|
assert_raise do
|
2016-05-22 07:03:43 -04:00
|
|
|
assert_equal(idconv.to_obj(key), self)
|
2016-05-15 07:59:00 -04:00
|
|
|
end
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-31 23:07:58 -04:00
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
2016-05-15 07:59:00 -04:00
|
|
|
|