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());
}
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);
}
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");
}
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();
}
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();
}
Aggregations