use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class EntryProcessorTest method multiple_entry_with_predicate_operation_returns_empty_response_when_map_is_empty.
@Test
public void multiple_entry_with_predicate_operation_returns_empty_response_when_map_is_empty() throws Exception {
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(MAP_NAME);
mapConfig.setInMemoryFormat(inMemoryFormat);
HazelcastInstance node = createHazelcastInstance(config);
NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(node);
OperationServiceImpl operationService = nodeEngineImpl.getOperationService();
int keyCount = 1000;
Set<Data> dataKeys = new HashSet<>();
for (int i = 0; i < keyCount; i++) {
dataKeys.add(nodeEngineImpl.toData(i));
}
Operation operation = new MultipleEntryWithPredicateOperation(MAP_NAME, dataKeys, new NoOpEntryProcessor<>(), Predicates.sql("this < " + keyCount));
OperationFactory operationFactory = new BinaryOperationFactory(operation, nodeEngineImpl);
Map<Integer, Object> partitionResponses = operationService.invokeOnAllPartitions(MapService.SERVICE_NAME, operationFactory);
for (Object response : partitionResponses.values()) {
assertEquals(0, ((MapEntries) response).size());
}
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class IndeterminateOperationStateExceptionTest method targetInvocation_shouldFailWithMemberLeftException_onTargetMemberLeave.
@Test(expected = MemberLeftException.class)
public void targetInvocation_shouldFailWithMemberLeftException_onTargetMemberLeave() throws Exception {
setup(true);
OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
Address target = getAddress(instance2);
InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new SilentOperation(), target).invoke();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertTrue(instance2.getUserContext().containsKey(SilentOperation.EXECUTION_STARTED));
}
});
spawn(new Runnable() {
@Override
public void run() {
instance2.getLifecycleService().terminate();
}
});
future.get(2, TimeUnit.MINUTES);
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class IndeterminateOperationStateExceptionTest method readOnlyPartitionInvocation_shouldSucceed_whenPartitionPrimaryLeaves.
@Test
public void readOnlyPartitionInvocation_shouldSucceed_whenPartitionPrimaryLeaves() throws InterruptedException, TimeoutException, ExecutionException {
setup(true);
dropOperationsBetween(instance2, instance1, SpiDataSerializerHook.F_ID, singletonList(SpiDataSerializerHook.NORMAL_RESPONSE));
int partitionId = getPartitionId(instance2);
OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
InternalCompletableFuture<Boolean> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new DummyReadOperation(), partitionId).invoke();
spawn(new Runnable() {
@Override
public void run() {
instance2.getLifecycleService().terminate();
}
});
boolean response = future.get(2, TimeUnit.MINUTES);
assertTrue(response);
assertEquals(getAddress(instance1), instance1.getUserContext().get(DummyReadOperation.LAST_INVOCATION_ADDRESS));
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class IndeterminateOperationStateExceptionTest method partitionInvocation_shouldFail_whenPartitionPrimaryLeaves.
@Test
public void partitionInvocation_shouldFail_whenPartitionPrimaryLeaves() throws InterruptedException, TimeoutException {
setup(true);
int partitionId = getPartitionId(instance2);
OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new SilentOperation(), partitionId).invoke();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertTrue(instance2.getUserContext().containsKey(SilentOperation.EXECUTION_STARTED));
}
});
spawn(new Runnable() {
@Override
public void run() {
instance2.getLifecycleService().terminate();
}
});
try {
future.get(2, TimeUnit.MINUTES);
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof IndeterminateOperationStateException);
}
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class TestTaskExecutorUtil method runOnPartitionThread.
/**
* Executes a {@link Callable} on a specific partition thread and returns
* a result.
* <p>
* This does <b>not</b> check if a given Hazelcast instance owns a specific
* partition.
*
* @param instance Hazelcast instance to be used for task execution
* @param task the task to be executed
* @param partitionId selects partition thread
* @param <T> type of the result
* @return result as returned by the callable
*/
public static <T> T runOnPartitionThread(HazelcastInstance instance, final Callable<T> task, final int partitionId) {
OperationServiceImpl operationService = getNodeEngineImpl(instance).getOperationService();
BlockingQueue<Object> resultQueue = new ArrayBlockingQueue<Object>(1);
operationService.execute(new PartitionSpecificRunnableWithResultQueue<T>(partitionId, task, resultQueue));
try {
Object result = resultQueue.poll(TIMEOUT_SECONDS, SECONDS);
if (result instanceof Throwable) {
sneakyThrow((Throwable) result);
}
// noinspection unchecked
return (T) unwrapNullIfNeeded(result);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted while waiting for result", e);
}
}
Aggregations