Package com.hazelcast.core

Examples of com.hazelcast.core.ISemaphore.release()


                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }.start();
        semaphore.release();

        assertTrueEventually(new AssertTask() {
            @Override
            public void run() throws Exception {
                assertEquals(0, semaphore.availablePermits());
View Full Code Here


        final ISemaphore semaphore = hz.getSemaphore(randomString());
        int numberOfPermits = 20;

        for (int i = 0; i < numberOfPermits; i += 5) {
            assertEquals(i, semaphore.availablePermits());
            semaphore.release(5);
        }
        assertEquals(semaphore.availablePermits(), numberOfPermits);
    }

    @Test(timeout = 30000)
View Full Code Here

    public void testMultipleRelease_whenNegative() throws InterruptedException {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
        semaphore.init(0);

        try {
            semaphore.release(-5);
            fail();

        } catch (IllegalArgumentException expected) {
        }
        assertEquals(0, semaphore.availablePermits());
View Full Code Here

        semaphore.acquire(numberOfPermits);
        CountDownLatch latch1 = new CountDownLatch(1);
        Thread thread1 = new BlockAcquireThread(semaphore, latch1);
        thread1.start();

        semaphore.release();
        assertOpenEventually(latch1);
    }

    @Test(timeout = 30000)
    public void testDrain() throws InterruptedException {
View Full Code Here

    public void testSemaphore() throws Exception {
        String partitionKey = "hazelcast";
        HazelcastInstance hz = getHazelcastInstance(partitionKey);

        ISemaphore semaphore = hz.getSemaphore("semaphore@" + partitionKey);
        semaphore.release();
        assertEquals("semaphore@" + partitionKey, semaphore.getName());
        assertEquals(partitionKey, semaphore.getPartitionKey());

        SemaphoreService service = getNodeEngine(hz).getService(SemaphoreService.SERVICE_NAME);
        assertTrue(service.containsSemaphore(semaphore.getName()));
View Full Code Here

    public void testObjectWithPartitionKeyAndTask() throws Exception {
        HazelcastInstance instance = instances[0];
        IExecutorService executorServices = instance.getExecutorService("executor");
        String partitionKey = "hazelcast";
        ISemaphore semaphore = instance.getSemaphore("foobar@" + partitionKey);
        semaphore.release();
        ContainsSemaphoreTask task = new ContainsSemaphoreTask(semaphore.getName());
        Future<Boolean> f = executorServices.submitToKeyOwner(task, semaphore.getPartitionKey());
        assertTrue(f.get());
    }
View Full Code Here

        IMap map = instance.getMap("map");

        map.put(mapKey, "foobar");

        ISemaphore semaphore = instance.getSemaphore("s@" + partitionKey);
        semaphore.release();

        ContainsSemaphoreAndMapEntryTask task = new ContainsSemaphoreAndMapEntryTask(semaphore.getName(), mapKey);
        Map<Member, Future<Boolean>> futures = executorServices.submitToAllMembers(task);

        int count = 0;
View Full Code Here

    @Test
    public void testTryAcquire_afterRelease() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(0);
        semaphore.release();
        assertTrue(semaphore.tryAcquire());
    }

    @Test
    public void testMulitReleaseTryAcquire() throws Exception {
View Full Code Here

    @Test
    public void testMulitReleaseTryAcquire() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(0);
        semaphore.release(5);
        assertTrue(semaphore.tryAcquire(5));
    }

    @Test
    public void testAcquire_Threaded() throws Exception {
View Full Code Here

                    e.printStackTrace();
                }
            }
        }.start();
        Thread.sleep(1000);
        semaphore.release(2);

        assertTrue(latch.await(5, TimeUnit.SECONDS));
        assertEquals(1, semaphore.availablePermits());
    }
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.