Package com.hazelcast.core

Examples of com.hazelcast.core.ILock


    // ======================== lock ==================================================

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

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


    }

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

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

    }

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

        lock.lock();
        assertTrue(lock.isLocked());
        assertEquals(1, lock.getLockCount());
        assertTrue(lock.isLockedByCurrentThread());

        final CountDownLatch latch = new CountDownLatch(1);

        Thread t = new Thread() {
            public void run() {
                lock.lock();
                latch.countDown();
            }
        };

        t.start();
View Full Code Here

    // ======================== try lock ==============================================

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

        boolean result = lock.tryLock();

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

    }

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

        boolean result = lock.tryLock();

        assertTrue(result);
        assertTrue(lock.isLockedByCurrentThread());
        assertEquals(2, lock.getLockCount());
    }
View Full Code Here

    }

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

        boolean result = lock.tryLock();

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

    // ======================== try lock with timeout ==============================================

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

        boolean result = lock.tryLock(1, TimeUnit.SECONDS);

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

    }

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

        boolean result = lock.tryLock(1, TimeUnit.SECONDS);

        assertTrue(result);
        assertTrue(lock.isLockedByCurrentThread());
        assertEquals(2, lock.getLockCount());
    }
View Full Code Here

    }

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

        boolean result = lock.tryLock(1, TimeUnit.SECONDS);

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

    }

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

        final CountDownLatch latch = new CountDownLatch(1);
        new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                latch.countDown();
                sleepSeconds(1);
                lock.unlock();
            }
        }).start();
        latch.await();
        assertTrue(lock.tryLock(3, TimeUnit.SECONDS));

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

    }
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.