use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class OperationServiceImpl_timeoutTest method testOperationTimeoutForLongRunningRemoteOperation.
@Test
public void testOperationTimeoutForLongRunningRemoteOperation() throws Exception {
int callTimeoutMillis = 3000;
Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeoutMillis);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
// invoke on the "remote" member
Address remoteAddress = getNode(hz2).getThisAddress();
OperationService operationService = getNode(hz1).getNodeEngine().getOperationService();
ICompletableFuture<Boolean> future = operationService.invokeOnTarget(null, new SleepingOperation(callTimeoutMillis * 5), remoteAddress);
// wait more than operation timeout
sleepAtLeastMillis(callTimeoutMillis * 3);
assertTrue(future.get());
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class OperationServiceImpl_timeoutTest method testOperationTimeout.
private void testOperationTimeout(int memberCount, boolean async) {
assertTrue(memberCount > 0);
Config config = new Config();
config.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "3000");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(memberCount);
HazelcastInstance[] instances = factory.newInstances(config);
warmUpPartitions(instances);
final HazelcastInstance hz = instances[memberCount - 1];
Node node = TestUtil.getNode(hz);
NodeEngine nodeEngine = node.nodeEngine;
OperationService operationService = nodeEngine.getOperationService();
int partitionId = (int) (Math.random() * node.getPartitionService().getPartitionCount());
InternalCompletableFuture<Object> future = operationService.invokeOnPartition(null, new TimedOutBackupAwareOperation(), partitionId);
final CountDownLatch latch = new CountDownLatch(1);
if (async) {
future.andThen(new ExecutionCallback<Object>() {
@Override
public void onResponse(Object response) {
}
@Override
public void onFailure(Throwable t) {
if (t instanceof OperationTimeoutException) {
latch.countDown();
}
}
});
} else {
try {
future.join();
fail("Should throw OperationTimeoutException!");
} catch (OperationTimeoutException ignored) {
latch.countDown();
}
}
assertOpenEventually("Should throw OperationTimeoutException", latch);
for (HazelcastInstance instance : instances) {
OperationServiceImpl_BasicTest.assertNoLitterInOpService(instance);
}
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class InvocationFuture_GetNewInstanceTest method invocationToRemoteMember.
@Test
public void invocationToRemoteMember() throws ExecutionException, InterruptedException {
Node localNode = getNode(local);
Data response = localNode.nodeEngine.toData(new DummyObject());
Operation op = new OperationWithResponse(response);
Address remoteAddress = getAddress(remote);
OperationService operationService = getOperationService(local);
Future future = operationService.createInvocationBuilder(null, op, remoteAddress).invoke();
Object instance1 = future.get();
Object instance2 = future.get();
assertNotNull(instance1);
assertNotNull(instance2);
assertTrue(instance1 instanceof DummyObject);
assertTrue(instance2 instanceof DummyObject);
assertNotSame(instance1, instance2);
assertNotSame(instance1, response);
assertNotSame(instance2, response);
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class InvocationFuture_GetNewInstanceTest method invocationToLocalMember.
@Test
public void invocationToLocalMember() throws ExecutionException, InterruptedException {
Node localNode = getNode(local);
Data response = localNode.nodeEngine.toData(new DummyObject());
Operation op = new OperationWithResponse(response);
OperationService service = getOperationService(local);
Future future = service.createInvocationBuilder(null, op, localNode.address).invoke();
Object instance1 = future.get();
Object instance2 = future.get();
assertNotNull(instance1);
assertNotNull(instance2);
assertTrue(instance1 instanceof DummyObject);
assertTrue(instance2 instanceof DummyObject);
assertNotSame(instance1, instance2);
assertNotSame(instance1, response);
assertNotSame(instance2, response);
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class Invocation_DetectHeartbeatTimeoutTest method whenCallTimeoutDisabled.
@Test
public void whenCallTimeoutDisabled() {
Config config = new Config();
config.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "1000");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance local = factory.newHazelcastInstance();
HazelcastInstance remote = factory.newHazelcastInstance();
OperationService opService = getOperationService(local);
Operation operation = new VoidOperation();
InvocationFuture future = (InvocationFuture) opService.createInvocationBuilder(null, operation, getPartitionId(remote)).setCallTimeout(Long.MAX_VALUE).invoke();
Invocation invocation = future.invocation;
assertEquals(Long.MAX_VALUE, invocation.op.getCallTimeout());
assertEquals(Long.MAX_VALUE, invocation.callTimeoutMillis);
assertEquals(NO_TIMEOUT__CALL_TIMEOUT_DISABLED, invocation.detectTimeout(SECONDS.toMillis(1)));
assertFalse(future.isDone());
}
Aggregations