Search in sources :

Example 21 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method cancelledAndDone_durable.

@Test()
public void cancelledAndDone_durable() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(3);
    Object key = generateKeyOwnedBy(instances[1]);
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    latch.trySetCount(1);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("latch"), key, 0, 1, SECONDS);
    latch.await(10, SECONDS);
    assertFalse(future.isCancelled());
    assertFalse(future.isDone());
    future.cancel(false);
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
    instances[1].getLifecycleService().shutdown();
    assertTrue(future.isCancelled());
    assertTrue(future.isDone());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method handlerTaskAndSchedulerNames_withRunnable.

@Test
public void handlerTaskAndSchedulerNames_withRunnable() throws ExecutionException, InterruptedException {
    int delay = 0;
    String schedulerName = "s";
    String taskName = "TestRunnable";
    HazelcastInstance[] instances = createClusterWithCount(2);
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    latch.trySetCount(1);
    IScheduledExecutorService executorService = instances[0].getScheduledExecutorService(schedulerName);
    IScheduledFuture future = executorService.schedule(named(taskName, new ICountdownLatchRunnableTask("latch")), delay, SECONDS);
    latch.await(10, SECONDS);
    ScheduledTaskHandler handler = future.getHandler();
    assertEquals(schedulerName, handler.getSchedulerName());
    assertEquals(taskName, handler.getTaskName());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method getErroneous_durable.

@Test
public void getErroneous_durable() throws InterruptedException, ExecutionException {
    int delay = 2;
    String taskName = "Test";
    String completionLatchName = "completionLatch";
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
    ICountDownLatch latch = instances[1].getCountDownLatch(completionLatchName);
    latch.trySetCount(1);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
    latch.await(10, SECONDS);
    instances[1].getLifecycleService().shutdown();
    Thread.sleep(2000);
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) RootCauseMatcher(com.hazelcast.util.RootCauseMatcher) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_withNotPeriodicRunable.

@Test
public void scheduleOnKeyOwner_withNotPeriodicRunable() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[0]);
    IScheduledExecutorService s = getScheduledExecutor(instances, "s");
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    latch.trySetCount(1);
    s.scheduleOnKeyOwner(new ICountdownLatchRunnableTask("latch"), key, 2, SECONDS).get();
    assertEquals(0, latch.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method scheduleOnMemberWithRepetition.

@Test
public void scheduleOnMemberWithRepetition() throws InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(4);
    IScheduledExecutorService s = getScheduledExecutor(instances, "s");
    ICountDownLatch latch = instances[0].getCountDownLatch("latch");
    latch.trySetCount(4);
    Map<Member, IScheduledFuture<?>> futures = s.scheduleOnAllMembersAtFixedRate(new ICountdownLatchRunnableTask("latch"), 0, 3, SECONDS);
    latch.await(10, SECONDS);
    assertEquals(0, latch.getCount());
    assertEquals(4, futures.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ICountDownLatch (com.hazelcast.core.ICountDownLatch)37 ParallelTest (com.hazelcast.test.annotation.ParallelTest)37 Test (org.junit.Test)37 HazelcastInstance (com.hazelcast.core.HazelcastInstance)35 QuickTest (com.hazelcast.test.annotation.QuickTest)27 SlowTest (com.hazelcast.test.annotation.SlowTest)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 TestThread (com.hazelcast.test.TestThread)3 IAtomicLong (com.hazelcast.core.IAtomicLong)2 RootCauseMatcher (com.hazelcast.util.RootCauseMatcher)2 CountDownLatchService (com.hazelcast.concurrent.countdownlatch.CountDownLatchService)1 Config (com.hazelcast.config.Config)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 Member (com.hazelcast.core.Member)1 DistributedObjectDestroyedException (com.hazelcast.spi.exception.DistributedObjectDestroyedException)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1