Package com.hazelcast.core

Examples of com.hazelcast.core.ILock


    }

    @Test(timeout = 60000, expected = NullPointerException.class)
    public void testTryLockTimeout_whenNullTimeout() throws InterruptedException {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock("testTryLockTimeout_whenNullTimeout");
        lock.tryLock(1, null);
    }
View Full Code Here


    // ======================== unlock ==============================================

    @Test(expected = IllegalMonitorStateException.class)
    public void testUnlock_whenFree() {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock("testIllegalUnlock");
        lock.unlock();
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testUnlock_whenLockedBySelf() {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock(randomString());
        lock.lock();

        lock.unlock();

        assertFalse(lock.isLocked());
        assertEquals(0, lock.getLockCount());
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testUnlock_whenReentrantlyLockedBySelf() {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock("testUnlock_whenReentrantlyLockedBySelf");
        lock.lock();
        lock.lock();

        lock.unlock();

        assertTrue(lock.isLockedByCurrentThread());
        assertTrue(lock.isLocked());
        assertEquals(1, lock.getLockCount());
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testUnlock_whenPendingLockOfOtherThread() throws InterruptedException {
        HazelcastInstance instance = createHazelcastInstance();
        final ILock lock = instance.getLock(randomString());

        lock.lock();
        final CountDownLatch latch = new CountDownLatch(1);
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                latch.countDown();

            }
        });
        thread.start();

        lock.unlock();
        latch.await();

        assertTrue(lock.isLocked());
        assertFalse(lock.isLockedByCurrentThread());


    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testUnlock_whenLockedByOther() {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock(randomString());
        lockByOtherThread(lock);

        try {
            lock.unlock();
            fail();
        } catch (IllegalMonitorStateException expected) {
        }

        assertTrue(lock.isLocked());
        assertEquals(1, lock.getLockCount());
    }
View Full Code Here

    // ======================== force unlock ==============================================

    @Test(timeout = 60000)
    public void testForceUnlock_whenLockNotOwned() {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock(randomString());

        lock.forceUnlock();

        assertFalse(lock.isLocked());
        assertEquals(0, lock.getLockCount());
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testForceUnlock_whenOwnedByOtherThread() {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock(randomString());
        lock.lock();

        lock.forceUnlock();

        assertFalse(lock.isLocked());
        assertEquals(0, lock.getLockCount());
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testForceUnlock_whenAcquiredByCurrentThread() {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock(randomString());
        lock.lock();

        lock.forceUnlock();

        assertFalse(lock.isLocked());
        assertEquals(0, lock.getLockCount());
    }
View Full Code Here

    }

    @Test(timeout = 60000)
    public void testForceUnlock_whenAcquiredMultipleTimesByCurrentThread() {
        HazelcastInstance instance = createHazelcastInstance();
        ILock lock = instance.getLock(randomString());
        lock.lock();
        lock.lock();

        lock.forceUnlock();

        assertFalse(lock.isLocked());
        assertEquals(0, lock.getLockCount());
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.ILock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.