Sha256: e82f1628042b5fc364d1a7b3adf46d1ba42e78950e0ffa3c42cd3772c1a6275d

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

#
# Testing OpenWFE
#
# John Mettraux at openwfe.org
#

require 'test/unit'
require 'openwfe/worklist/storelocks'
require 'openwfe/participants/storeparticipants'


class MockItem
    attr_reader :fei
    def initialize (fei)
        @fei = fei
    end
    def flow_expression_id
        @fei
    end
end

class StoreLockTest < Test::Unit::TestCase

    #def setup
    #end

    #def teardown
    #end

    def test_0

        store = StoreWithLocks.new(HashParticipant)

        wi0 = MockItem.new("fei")

        store.store.push(wi0)

        wi1 = store.get_and_lock("locker_a", "fei")

        assert_not_nil wi1
        assert_equal wi0.object_id, wi1.object_id

        assert_raise RuntimeError do
            wi2 = store.get_and_lock("locker_b", "fei")
        end

        assert_equal store.get_locker("fei"), "locker_a"

        assert_raise RuntimeError do
            store.release "locker_b", "fei"
        end

        store.release "locker_a", "fei"

        assert_nil store.get_locker("fei")
    end

    def test_1

        store = StoreWithLocks.new(
            HashParticipant,
            nil,
            :lock_max_age => "100")

        wi0 = MockItem.new("fei")

        store.store.push(wi0)

        wi1 = store.get_and_lock("locker_a", "fei")

        assert_not_nil wi1

        sleep 1

        assert_nil store.get_locker("fei")
    end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruote-0.9.18 test/slock_test.rb