2015-12-16 08:07:31 +03:00
|
|
|
# frozen_string_literal: false
|
2016-05-15 14:59:00 +03:00
|
|
|
require 'test/unit'
|
|
|
|
require 'drb/timeridconv'
|
2003-10-20 19:24:00 +04:00
|
|
|
|
2014-06-01 07:07:58 +04:00
|
|
|
module DRbTests
|
|
|
|
|
2016-05-15 14:59:00 +03:00
|
|
|
class TimerIdConvTest < Test::Unit::TestCase
|
|
|
|
def test_usecase_01
|
|
|
|
keeping = 0.1
|
|
|
|
idconv = DRb::TimerIdConv.new(keeping)
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2016-05-15 14:59:00 +03: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 19:24:00 +04:00
|
|
|
|
2016-05-15 14:59:00 +03:00
|
|
|
assert_raise do
|
2016-05-22 14:03:43 +03: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 14:59:00 +03:00
|
|
|
end
|
2016-05-22 14:03:43 +03:00
|
|
|
end
|
2016-05-15 14:59:00 +03:00
|
|
|
|
2016-05-22 14:03:43 +03: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 14:59:00 +03:00
|
|
|
assert_raise do
|
2016-05-22 14:03:43 +03:00
|
|
|
assert_equal(idconv.to_obj(key), self)
|
2016-05-15 14:59:00 +03:00
|
|
|
end
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-01 07:07:58 +04:00
|
|
|
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
2016-05-15 14:59:00 +03:00
|
|
|
|