Package com.hazelcast.core

Examples of com.hazelcast.core.ILock.tryLock()


    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


    @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

    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

    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

                sleepSeconds(1);
                lock.unlock();
            }
        }).start();
        latch.await();
        assertTrue(lock.tryLock(3, TimeUnit.SECONDS));

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

    }
View Full Code Here

    @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);
    }

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

    @Test(expected = IllegalMonitorStateException.class)
View Full Code Here

        for (int i = 0; i < tryCount; i++) {
            final HazelcastInstance instance = Hazelcast.newHazelcastInstance();
            final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

            final ILock lock = client.getLock("lock");
            assertTrue(lock.tryLock(1, TimeUnit.MINUTES));
            client.getLifecycleService().terminate(); //with client is dead, lock should be released.
            instance.getLifecycleService().terminate();
        }
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.