Package com.hazelcast.core

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


        lock.lock();

        Runnable tryLockRunnable = new Runnable() {
            public void run() {
                if (lock.tryLock()) {
                    atomicInteger.incrementAndGet();
                }
            }
        };
View Full Code Here


        HazelcastInstance instance = createHazelcastInstance();
        final ILock lock = instance.getLock(randomString());

        assertFalse(lock.isLocked());

        assertTrue(lock.tryLock());
        lock.unlock();
        assertFalse(lock.isLocked());
    }

    @Test(timeout = 60000, expected = DistributedObjectDestroyedException.class)
View Full Code Here

        HazelcastInstance instance = createHazelcastInstance();

        ILock lock = instance.getLock(randomString());
        lock.lock();
        assertEquals(1, lock.getLockCount());
        assertTrue(lock.tryLock());
        assertEquals(2, lock.getLockCount());

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

        final ILock lock = instance1.getLock(key);
        lock.lock();
        assertTrue(lock.isLocked());
        assertTrue(lock.isLockedByCurrentThread());

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

        final AtomicBoolean result = new AtomicBoolean();
        final Thread thread = new Thread() {
View Full Code Here

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicBoolean interruptedFlag = new AtomicBoolean(false);

        final OpThread thread = new OpThread("Lock-Thread", latch, interruptedFlag) {
            protected void doOp() throws InterruptedException {
                assertTrue(lock.tryLock(1, TimeUnit.MINUTES));
            }
        };
        thread.start();

        Thread.sleep(5000);
View Full Code Here

        ILock lockA = clientA.getLock(name);
        lockA.lock();

        HazelcastInstance clientB = HazelcastClient.newHazelcastClient();
        ILock lockB = clientB.getLock(name);
        boolean lockObtained = lockB.tryLock();

        assertFalse("Lock obtained by 2 client ", lockObtained);
    }

}
View Full Code Here

        lock.lock();

        client1.getLifecycleService().terminate();

        lock = client2.getLock(keyOwnedByNode2);
        boolean lockObtained = lock.tryLock(120, TimeUnit.SECONDS);

        assertTrue("Lock was Not Obtained, lock should be released on client crash", lockObtained);
    }

    @Test
View Full Code Here

        lock.lock();

        node2.getLifecycleService().terminate();

        lock = client2.getLock(keyOwnedByNode2);
        boolean lockObtained = lock.tryLock();

        assertFalse("Lock was obtained by 2 different clients ", lockObtained);
    }
}
View Full Code Here

    @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

    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

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.