use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class InvocationFuture_CancelTest method whenCancelled_thenCantCancelAgain.
@Test
public void whenCancelled_thenCantCancelAgain() {
// Given
InternalCompletableFuture future = invoke();
// When
future.cancel(true);
// Then
assertFalse(future.cancel(true));
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class Invocation_BlockingTest method sync_whenManyGettersAndLotsOfWaiting.
/**
* Tests if the future on a blocking operation can be shared by multiple threads. This tests fails in 3.6 because
* only 1 thread will be able to swap out CONTINUE_WAIT and all other threads will fail with an OperationTimeoutExcepyion
*/
@Test
public void sync_whenManyGettersAndLotsOfWaiting() throws Exception {
int callTimeout = 10000;
Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance local = factory.newHazelcastInstance(config);
HazelcastInstance remote = factory.newHazelcastInstance(config);
NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
String key = generateKeyOwnedBy(remote);
int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
// first we execute an operation that stall the partition
OperationServiceImpl opService = nodeEngine.getOperationService();
// first we are going to lock
int otherThreadId = 1;
LockOperation otherOp = new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), otherThreadId, -1, -1);
opService.createInvocationBuilder(null, otherOp, partitionId).setCallTimeout(callTimeout).invoke().join();
// then we are going to send the invocation and share the future by many threads
int thisThreadId = 2;
LockOperation thisOp = new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), thisThreadId, -1, -1);
final InternalCompletableFuture<Object> future = opService.createInvocationBuilder(null, thisOp, partitionId).setCallTimeout(callTimeout).invoke();
// now we are going to do a get on the future by a whole bunch of threads
final List<Future> futures = new LinkedList<Future>();
for (int k = 0; k < 10; k++) {
futures.add(spawn(new Callable() {
@Override
public Object call() throws Exception {
return future.join();
}
}));
}
// lets do a very long wait so that the heartbeat/retrying mechanism have kicked in.
// the lock remains locked; so the threads calling future.get remain blocked
sleepMillis(callTimeout * 5);
// unlocking the lock
UnlockOperation op = new UnlockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), otherThreadId);
opService.createInvocationBuilder(null, op, partitionId).setCallTimeout(callTimeout).invoke().join();
// now the futures should all unblock
for (Future f : futures) {
assertEquals(Boolean.TRUE, f.get());
}
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class InvocationFuture_IsDoneTest method isDone_whenObjectResponse.
@Test
public void isDone_whenObjectResponse() {
DummyOperation op = new DummyOperation("foobar");
InternalCompletableFuture future = operationService.invokeOnTarget(null, op, getAddress(local));
assertTrue(future.isDone());
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class Backup_CallerUuidTest method test.
@Test
public void test() {
InternalCompletableFuture f = getOperationService(hz).invokeOnPartition(new DummyUpdateOperation().setPartitionId(getPartitionId(hz)));
assertCompletesEventually(f);
assertEquals(CALLER_UUID.get(), hz.getCluster().getLocalMember().getUuid());
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class InvocationFuture_CancelTest method whenCancelled_thenGetThrowsCancelled.
@Test
public void whenCancelled_thenGetThrowsCancelled() throws Exception {
// Given
InternalCompletableFuture future = invoke();
// When
future.cancel(true);
// Then
exceptionRule.expect(CancellationException.class);
future.get();
}
Aggregations