Package com.hazelcast.core

Examples of com.hazelcast.core.ISemaphore


        assertEquals(semaphore.availablePermits(), 0);
    }

    @Test(timeout = 30000)
    public void testTryAcquireMultiple_whenArgumentNegative() {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
        int negativePermits = -5;
        semaphore.init(0);
        try {
            semaphore.tryAcquire(negativePermits);
            fail();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
        assertEquals(0, semaphore.availablePermits());
    }
View Full Code Here


        assertEquals(0, semaphore.availablePermits());
    }

    @Test(timeout = 30000)
    public void testTryAcquire_whenNotEnoughPermits() throws InterruptedException {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
        int numberOfPermits = 10;
        semaphore.init(numberOfPermits);
        semaphore.acquire(10);
        boolean result = semaphore.tryAcquire(1);

        assertFalse(result);
        assertEquals(0, semaphore.availablePermits());
    }
View Full Code Here

        assertEquals(0, semaphore.availablePermits());
    }

    @Test(timeout = 30000)
    public void testInit_whenNotIntialized() {
        ISemaphore semaphore = hz.getSemaphore(randomString());

        boolean result = semaphore.init(2);

        assertTrue(result);
        assertEquals(2, semaphore.availablePermits());
    }
View Full Code Here

        assertEquals(2, semaphore.availablePermits());
    }

    @Test(timeout = 30000)
    public void testInit_whenAlreadyIntialized() {
        ISemaphore semaphore = hz.getSemaphore(randomString());
        semaphore.init(2);

        boolean result = semaphore.init(4);

        assertFalse(result);
        assertEquals(2, semaphore.availablePermits());
    }
View Full Code Here

    @Test
    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

    @Test
    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

        String mapKey = "key@" + partitionKey;
        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;
        for (Future<Boolean> f : futures.values()) {
            count += f.get() ? 1 : 0;
View Full Code Here

        assertEquals(0, semaphore.availablePermits());
    }

    @Test
    public void testTryAcquire_whenAvailable() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(1);
        assertTrue(semaphore.tryAcquire());
    }
View Full Code Here

        assertTrue(semaphore.tryAcquire());
    }

    @Test
    public void testTryAcquire_whenUnAvailable() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(0);
        assertFalse(semaphore.tryAcquire());
    }
View Full Code Here

        assertFalse(semaphore.tryAcquire());
    }

    @Test
    public void testTryAcquire_whenAvailableWithTimeOut() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(1);
        assertTrue(semaphore.tryAcquire(1, TimeUnit.MILLISECONDS));
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.ISemaphore

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.