use of com.hazelcast.client.test.executor.tasks.CancellationAwareTask in project hazelcast by hazelcast.
the class ClientExecutorServiceCancelTest method testCancel_submitToKeyOwner.
private void testCancel_submitToKeyOwner(boolean smartRouting, boolean waitTaskStart) throws ExecutionException, InterruptedException, IOException {
HazelcastInstance client = createClient(smartRouting);
IExecutorService executorService = client.getExecutorService(randomString());
String key = generateKeyOwnedBy(server1);
Future<Boolean> future = executorService.submitToKeyOwner(new CancellationAwareTask(SLEEP_TIME), key);
if (waitTaskStart) {
awaitTaskStartAtMember(server1, 1);
}
boolean cancelled = future.cancel(true);
assertTrue(cancelled);
awaitTaskCancelAtMember(server1, 1);
future.get();
}
use of com.hazelcast.client.test.executor.tasks.CancellationAwareTask in project hazelcast by hazelcast.
the class ClientExecutorServiceCancelTest method testCancel_submitToKeyOwner_Should_Not_Block_Migration.
@Test(expected = CancellationException.class)
public void testCancel_submitToKeyOwner_Should_Not_Block_Migration() throws IOException, ExecutionException, InterruptedException {
server2.shutdown();
HazelcastInstance client = createClient(true);
warmUpPartitions(server1);
IExecutorService executorService = client.getExecutorService(randomString());
String key = ExecutorServiceTestSupport.generateKeyOwnedBy(server1);
final Future<Boolean> future = executorService.submitToKeyOwner(new CancellationAwareTask(SLEEP_TIME), key);
awaitTaskStartAtMember(server1, 1);
InternalPartitionServiceImpl internalPartitionService = (InternalPartitionServiceImpl) TestUtil.getNode(server1).getPartitionService();
final int partitionId = internalPartitionService.getPartitionId(key);
// Simulate partition thread blockage as if the partition is migrating
internalPartitionService.setMigrationInterceptor(new MigrationInterceptor() {
@Override
public void onMigrationCommit(MigrationInterceptor.MigrationParticipant participant, MigrationInfo migrationInfo) {
int migratingPartitionId = migrationInfo.getPartitionId();
if (migratingPartitionId == partitionId) {
spawn(() -> {
future.cancel(true);
});
// sleep enough so that the ExecutorServiceCancelOnPartitionMessageTask actually starts
// This test is time sensitive
sleepSeconds(3);
}
}
});
// Start the second member to initiate migration
server2 = hazelcastFactory.newHazelcastInstance();
waitAllForSafeState(server1, server2);
future.get();
}
use of com.hazelcast.client.test.executor.tasks.CancellationAwareTask in project hazelcast by hazelcast.
the class ClientExecutorServiceCancelTest method testCancel_submitToKeyOwner_Should_Be_Retried_While_Migrating.
@Test(expected = CancellationException.class)
public void testCancel_submitToKeyOwner_Should_Be_Retried_While_Migrating() throws IOException, ExecutionException, InterruptedException {
HazelcastInstance client = createClient(true);
IExecutorService executorService = client.getExecutorService(randomString());
String key = ExecutorServiceTestSupport.generateKeyOwnedBy(server1);
Future<Boolean> future = executorService.submitToKeyOwner(new CancellationAwareTask(SLEEP_TIME), key);
awaitTaskStartAtMember(server1, 1);
final InternalPartitionServiceImpl internalPartitionService = (InternalPartitionServiceImpl) TestUtil.getNode(server1).getPartitionService();
final int partitionId = internalPartitionService.getPartitionId(key);
// Simulate partition thread blockage as if the partition is migrating
internalPartitionService.getPartitionStateManager().trySetMigratingFlag(partitionId);
spawn(() -> {
sleepSeconds(2);
// Simulate migration completion
internalPartitionService.getPartitionStateManager().clearMigratingFlag(partitionId);
});
// The cancel operation should not be blocked due to the blocked partition thread
future.cancel(true);
future.get();
}
use of com.hazelcast.client.test.executor.tasks.CancellationAwareTask in project hazelcast by hazelcast.
the class ClientExecutorServiceTest method testCancellationAwareTask_whenTimeOut.
@Test(expected = TimeoutException.class)
public void testCancellationAwareTask_whenTimeOut() throws InterruptedException, ExecutionException, TimeoutException {
IExecutorService service = client.getExecutorService(randomString());
CancellationAwareTask task = new CancellationAwareTask(Long.MAX_VALUE);
Future future = service.submit(task);
future.get(1, TimeUnit.SECONDS);
}
use of com.hazelcast.client.test.executor.tasks.CancellationAwareTask in project hazelcast by hazelcast.
the class ClientExecutorServiceTest method testGetFutureAfterCancel.
@Test(expected = CancellationException.class)
public void testGetFutureAfterCancel() throws InterruptedException, ExecutionException {
IExecutorService service = client.getExecutorService(randomString());
CancellationAwareTask task = new CancellationAwareTask(Long.MAX_VALUE);
Future future = service.submit(task);
try {
future.get(1, TimeUnit.SECONDS);
} catch (TimeoutException ignored) {
}
future.cancel(true);
future.get();
}
Aggregations