Search in sources :

Example 11 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class DurableExecutorServiceTest method testSubmitToKeyOwnerRunnable.

@Test
public void testSubmitToKeyOwnerRunnable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances();
    final AtomicInteger nullResponseCount = new AtomicInteger(0);
    final CountDownLatch responseLatch = new CountDownLatch(NODE_COUNT);
    ExecutionCallback callback = new ExecutionCallback() {

        public void onResponse(Object response) {
            if (response == null) {
                nullResponseCount.incrementAndGet();
            }
            responseLatch.countDown();
        }

        public void onFailure(Throwable t) {
        }
    };
    for (int i = 0; i < NODE_COUNT; i++) {
        HazelcastInstance instance = instances[i];
        DurableExecutorService service = instance.getDurableExecutorService("testSubmitToKeyOwnerRunnable");
        Member localMember = instance.getCluster().getLocalMember();
        String uuid = localMember.getUuid();
        Runnable runnable = new IncrementAtomicLongIfMemberUUIDNotMatchRunnable(uuid, "testSubmitToKeyOwnerRunnable");
        int key = findNextKeyForMember(instance, localMember);
        service.submitToKeyOwner(runnable, key).andThen(callback);
    }
    assertOpenEventually(responseLatch);
    assertEquals(0, instances[0].getAtomicLong("testSubmitToKeyOwnerRunnable").get());
    assertEquals(NODE_COUNT, nullResponseCount.get());
}
Also used : ICountDownLatch(com.hazelcast.core.ICountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class SingleNodeTest method executionCallback_notifiedOnFailure.

@Test
public void executionCallback_notifiedOnFailure() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    FailingTestTask task = new FailingTestTask();
    ExecutionCallback<String> executionCallback = new ExecutionCallback<String>() {

        public void onResponse(String response) {
        }

        public void onFailure(Throwable t) {
            latch.countDown();
        }
    };
    executor.submit(task, executionCallback);
    assertOpenEventually(latch);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class ExecutorServiceTest method testSubmitToKeyOwnerRunnable.

@Test
public void testSubmitToKeyOwnerRunnable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(new Config());
    final AtomicInteger nullResponseCount = new AtomicInteger(0);
    final CountDownLatch responseLatch = new CountDownLatch(NODE_COUNT);
    ExecutionCallback callback = new ExecutionCallback() {

        public void onResponse(Object response) {
            if (response == null) {
                nullResponseCount.incrementAndGet();
            }
            responseLatch.countDown();
        }

        public void onFailure(Throwable t) {
        }
    };
    for (int i = 0; i < NODE_COUNT; i++) {
        HazelcastInstance instance = instances[i];
        IExecutorService service = instance.getExecutorService("testSubmitToKeyOwnerRunnable");
        Member localMember = instance.getCluster().getLocalMember();
        int key = findNextKeyForMember(instance, localMember);
        service.submitToKeyOwner(new IncrementAtomicLongIfMemberUUIDNotMatchRunnable(localMember.getUuid(), "testSubmitToKeyOwnerRunnable"), key, callback);
    }
    assertOpenEventually(responseLatch);
    assertEquals(0, instances[0].getAtomicLong("testSubmitToKeyOwnerRunnable").get());
    assertEquals(NODE_COUNT, nullResponseCount.get());
}
Also used : ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) ExecutionCallback(com.hazelcast.core.ExecutionCallback) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class ExecutorServiceTest method testSubmitToMemberRunnable.

@Test
public void testSubmitToMemberRunnable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(new Config());
    final AtomicInteger nullResponseCount = new AtomicInteger(0);
    final CountDownLatch responseLatch = new CountDownLatch(NODE_COUNT);
    ExecutionCallback callback = new ExecutionCallback() {

        public void onResponse(Object response) {
            if (response == null) {
                nullResponseCount.incrementAndGet();
            }
            responseLatch.countDown();
        }

        public void onFailure(Throwable t) {
        }
    };
    for (int i = 0; i < NODE_COUNT; i++) {
        HazelcastInstance instance = instances[i];
        IExecutorService service = instance.getExecutorService("testSubmitToMemberRunnable");
        Member localMember = instance.getCluster().getLocalMember();
        service.submitToMember(new IncrementAtomicLongIfMemberUUIDNotMatchRunnable(localMember.getUuid(), "testSubmitToMemberRunnable"), localMember, callback);
    }
    assertOpenEventually(responseLatch);
    assertEquals(0, instances[0].getAtomicLong("testSubmitToMemberRunnable").get());
    assertEquals(NODE_COUNT, nullResponseCount.get());
}
Also used : ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) ExecutionCallback(com.hazelcast.core.ExecutionCallback) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.

the class DurableSingleNodeTest method executionCallback_notifiedOnFailure.

@Test
public void executionCallback_notifiedOnFailure() {
    final CountDownLatch latch = new CountDownLatch(1);
    FailingTestTask task = new FailingTestTask();
    ExecutionCallback<String> executionCallback = new ExecutionCallback<String>() {

        public void onResponse(String response) {
        }

        public void onFailure(Throwable t) {
            latch.countDown();
        }
    };
    executor.submit(task).andThen(executionCallback);
    assertOpenEventually(latch);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ExecutionCallback (com.hazelcast.core.ExecutionCallback)44 QuickTest (com.hazelcast.test.annotation.QuickTest)39 Test (org.junit.Test)39 ParallelTest (com.hazelcast.test.annotation.ParallelTest)37 CountDownLatch (java.util.concurrent.CountDownLatch)24 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)11 IMap (com.hazelcast.core.IMap)10 IExecutorService (com.hazelcast.core.IExecutorService)9 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)9 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)8 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 Member (com.hazelcast.core.Member)7 AssertTask (com.hazelcast.test.AssertTask)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 MemberLeftException (com.hazelcast.core.MemberLeftException)4 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Config (com.hazelcast.config.Config)3 DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)3