Search in sources :

Example 31 with OperationServiceImpl

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());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) MultipleEntryWithPredicateOperation(com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) Data(com.hazelcast.internal.serialization.Data) MultipleEntryWithPredicateOperation(com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) MapConfig(com.hazelcast.config.MapConfig) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) HashSet(java.util.HashSet) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with OperationServiceImpl

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);
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) AssertTask(com.hazelcast.test.AssertTask) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with OperationServiceImpl

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));
}
Also used : OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with OperationServiceImpl

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);
    }
}
Also used : AssertTask(com.hazelcast.test.AssertTask) IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) ExecutionException(java.util.concurrent.ExecutionException) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 35 with OperationServiceImpl

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);
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Aggregations

OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)70 Test (org.junit.Test)29 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 QuickTest (com.hazelcast.test.annotation.QuickTest)25 Address (com.hazelcast.cluster.Address)22 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 Operation (com.hazelcast.spi.impl.operationservice.Operation)12 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)11 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)10 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)10 Config (com.hazelcast.config.Config)9 ExecutionException (java.util.concurrent.ExecutionException)9 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)8 AssertTask (com.hazelcast.test.AssertTask)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Member (com.hazelcast.cluster.Member)5 Data (com.hazelcast.internal.serialization.Data)5 MapService (com.hazelcast.map.impl.MapService)5 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)5