Search in sources :

Example 11 with ICountDownLatch

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

the class CountDownLatchLongAwaitClientTest method when_awaitDurationIsLongerThanOperationTimeout_then_invocationFromClientWaits.

@Test
public void when_awaitDurationIsLongerThanOperationTimeout_then_invocationFromClientWaits() throws ExecutionException, InterruptedException {
    ICountDownLatch latch = client.getCPSubsystem().getCountDownLatch(proxyName);
    HazelcastInstance instance = getLeaderInstance(instances, groupId);
    latch.trySetCount(1);
    Future<Boolean> f = spawn(() -> latch.await(5, TimeUnit.MINUTES));
    assertTrueEventually(() -> {
        CountDownLatchService service = getNodeEngineImpl(instance).getService(CountDownLatchService.SERVICE_NAME);
        assertFalse(service.getLiveOperations(groupId).isEmpty());
    });
    assertTrueAllTheTime(() -> {
        CountDownLatchService service = getNodeEngineImpl(instance).getService(CountDownLatchService.SERVICE_NAME);
        assertFalse(service.getLiveOperations(groupId).isEmpty());
    }, callTimeoutSeconds + 5);
    latch.countDown();
    assertCompletesEventually(f);
    assertTrue(f.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatchService(com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with ICountDownLatch

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

the class DurableExecutorServiceTest method testExecuteOnKeyOwner.

@Test
public void testExecuteOnKeyOwner() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(smallInstanceConfig());
    HazelcastInstance instance2 = factory.newHazelcastInstance(smallInstanceConfig());
    String key = generateKeyOwnedBy(instance2);
    String instanceName = instance2.getName();
    ICountDownLatch latch = instance2.getCPSubsystem().getCountDownLatch(instanceName);
    latch.trySetCount(1);
    DurableExecutorService durableExecutorService = instance1.getDurableExecutorService(randomString());
    durableExecutorService.executeOnKeyOwner(new InstanceAsserterRunnable(instanceName), key);
    latch.await(30, TimeUnit.SECONDS);
}
Also used : DistributedDurableExecutorService(com.hazelcast.durableexecutor.impl.DistributedDurableExecutorService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with ICountDownLatch

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

the class HazelcastOSGiInstanceTest method getCountDownLatchCalledSuccessfullyOverOSGiInstance.

@Test
public void getCountDownLatchCalledSuccessfullyOverOSGiInstance() {
    ICountDownLatch mockCountDownLatch = mock(ICountDownLatch.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = createHazelcastOSGiInstance(mockHazelcastInstance);
    CPSubsystem cpSubsystem = mock(CPSubsystem.class);
    when(mockHazelcastInstance.getCPSubsystem()).thenReturn(cpSubsystem);
    when(cpSubsystem.getCountDownLatch("my-countdownlatch")).thenReturn(mockCountDownLatch);
    assertEquals(mockCountDownLatch, hazelcastOSGiInstance.getCPSubsystem().getCountDownLatch("my-countdownlatch"));
    verify(cpSubsystem).getCountDownLatch("my-countdownlatch");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CPSubsystem(com.hazelcast.cp.CPSubsystem) HazelcastOSGiTestUtil.createHazelcastOSGiInstance(com.hazelcast.osgi.impl.HazelcastOSGiTestUtil.createHazelcastOSGiInstance) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method getErroneous_durable.

@Test
public void getErroneous_durable() throws Exception {
    int delay = 2;
    String taskName = "Test";
    String completionLatchName = "completionLatch";
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    ICountDownLatch latch = instances[1].getCPSubsystem().getCountDownLatch(completionLatchName);
    latch.trySetCount(1);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
    assertOpenEventually(latch);
    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) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with ICountDownLatch

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

the class ScheduledExecutorServiceBasicTest method getErroneous.

@Test
public void getErroneous() throws Exception {
    int delay = 2;
    String taskName = "Test";
    String completionLatchName = "completionLatch";
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    ICountDownLatch latch = instances[1].getCPSubsystem().getCountDownLatch(completionLatchName);
    latch.trySetCount(1);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
    assertOpenEventually(latch);
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ICountDownLatch (com.hazelcast.cp.ICountDownLatch)32 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)31 Test (org.junit.Test)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)30 IScheduledExecutorService (com.hazelcast.scheduledexecutor.IScheduledExecutorService)27 QuickTest (com.hazelcast.test.annotation.QuickTest)21 IScheduledFuture (com.hazelcast.scheduledexecutor.IScheduledFuture)14 SlowTest (com.hazelcast.test.annotation.SlowTest)11 IAtomicLong (com.hazelcast.cp.IAtomicLong)3 ScheduledTaskHandler (com.hazelcast.scheduledexecutor.ScheduledTaskHandler)3 Member (com.hazelcast.cluster.Member)2 RootCauseMatcher (com.hazelcast.internal.util.RootCauseMatcher)2 ScheduledTaskStatistics (com.hazelcast.scheduledexecutor.ScheduledTaskStatistics)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 Address (com.hazelcast.cluster.Address)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 Config (com.hazelcast.config.Config)1 MapConfig (com.hazelcast.config.MapConfig)1 CPSubsystem (com.hazelcast.cp.CPSubsystem)1 CountDownLatchService (com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService)1