Search in sources :

Example 31 with IExecutorService

use of com.hazelcast.core.IExecutorService 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 32 with IExecutorService

use of com.hazelcast.core.IExecutorService 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 33 with IExecutorService

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

the class ExecutorServiceTest method testSubmitToKeyOwnerCallable.

@Test
public void testSubmitToKeyOwnerCallable() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(NODE_COUNT);
    HazelcastInstance[] instances = factory.newInstances(new Config());
    List<Future> futures = new ArrayList<Future>();
    for (int i = 0; i < NODE_COUNT; i++) {
        HazelcastInstance instance = instances[i];
        IExecutorService service = instance.getExecutorService("testSubmitToKeyOwnerCallable");
        Member localMember = instance.getCluster().getLocalMember();
        int key = findNextKeyForMember(instance, localMember);
        Future future = service.submitToKeyOwner(new MemberUUIDCheckCallable(localMember.getUuid()), key);
        futures.add(future);
    }
    for (Future future : futures) {
        assertTrue((Boolean) future.get(10, TimeUnit.SECONDS));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorConfig(com.hazelcast.config.ExecutorConfig) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 34 with IExecutorService

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

the class ConsoleApp method handleExecutorSimulate.

private void handleExecutorSimulate(String[] args) {
    String first = args[0];
    int threadCount = Integer.parseInt(first.substring(1, first.indexOf(".")));
    if (threadCount < 1 || threadCount > 16) {
        throw new RuntimeException("threadcount can't be smaller than 1 or larger than 16");
    }
    int taskCount = Integer.parseInt(args[1]);
    int durationSec = Integer.parseInt(args[2]);
    long startMs = System.currentTimeMillis();
    IExecutorService executor = hazelcast.getExecutorService(EXECUTOR_NAMESPACE + " " + threadCount);
    List<Future> futures = new LinkedList<Future>();
    List<Member> members = new LinkedList<Member>(hazelcast.getCluster().getMembers());
    int totalThreadCount = hazelcast.getCluster().getMembers().size() * threadCount;
    int latchId = 0;
    for (int i = 0; i < taskCount; i++) {
        Member member = members.get(i % members.size());
        if (taskCount % totalThreadCount == 0) {
            latchId = taskCount / totalThreadCount;
            hazelcast.getCountDownLatch("latch" + latchId).trySetCount(totalThreadCount);
        }
        Future f = executor.submitToMember(new SimulateLoadTask(durationSec, i + 1, "latch" + latchId), member);
        futures.add(f);
    }
    for (Future f : futures) {
        try {
            f.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
    long durationMs = System.currentTimeMillis() - startMs;
    println(format("Executed %s tasks in %s ms", taskCount, durationMs));
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) LinkedList(java.util.LinkedList) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member)

Example 35 with IExecutorService

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

the class ClientConsoleApp method executeOnMembers.

private void executeOnMembers(String[] args) {
    // executeOnMembers <echo-string>
    try {
        IExecutorService executorService = hazelcast.getExecutorService("default");
        Echo task = new Echo(args[1]);
        Map<Member, Future<String>> results = executorService.submitToAllMembers(task);
        for (Future f : results.values()) {
            println(f.get());
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : Echo(com.hazelcast.console.Echo) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member)

Aggregations

IExecutorService (com.hazelcast.core.IExecutorService)152 QuickTest (com.hazelcast.test.annotation.QuickTest)138 Test (org.junit.Test)138 ParallelTest (com.hazelcast.test.annotation.ParallelTest)137 HazelcastInstance (com.hazelcast.core.HazelcastInstance)66 Member (com.hazelcast.core.Member)57 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)46 Future (java.util.concurrent.Future)36 IMap (com.hazelcast.core.IMap)32 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)28 CountDownLatch (java.util.concurrent.CountDownLatch)28 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)25 ExecutorConfig (com.hazelcast.config.ExecutorConfig)20 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)20 Config (com.hazelcast.config.Config)19 ExecutionException (java.util.concurrent.ExecutionException)18 AppendCallable (com.hazelcast.client.executor.tasks.AppendCallable)16 AssertTask (com.hazelcast.test.AssertTask)16 ICompletableFuture (com.hazelcast.core.ICompletableFuture)13 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)11