Search in sources :

Example 61 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class DynamicMapConfigTest method executeOperation.

private void executeOperation(HazelcastInstance node, Operation op) {
    OperationServiceImpl operationService = getOperationService(node);
    Address address = getAddress(node);
    operationService.invokeOnTarget(MapService.SERVICE_NAME, op, address).join();
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 62 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class MapPutAllWrongTargetForPartitionTest method testPutAllPerMemberOperation.

/**
 * Tests that all entries and backups of a {@link PutAllPartitionAwareOperationFactory} are sent to the correct members.
 * <p>
 * The test creates a cluster with a single partition per member and invokes {@link PutAllPartitionAwareOperationFactory}
 * which contains a single entry for every partition in the cluster. So just a single entry is for the member the factory
 * is executed on.
 * <p>
 * After the operation is invoked we assert that each member owns one entry of the map and that all backups have been written.
 */
private void testPutAllPerMemberOperation(final int entriesPerPartition) throws Exception {
    final int expectedEntryCount = INSTANCE_COUNT * entriesPerPartition;
    final String mapName = randomMapName();
    HazelcastInstance hz = instances[0];
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    SerializationService serializationService = nodeEngine.getSerializationService();
    // create a PutAllPerMemberOperation with entries for all partitions
    int[] allPartitions = getAllPartitions();
    PartitionAwareOperationFactory factory = createPutAllOperationFactory(allPartitions, entriesPerPartition, mapName, hz, serializationService);
    // invoke the operation on a random remote target
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    operationService.invokeOnPartitions(MapService.SERVICE_NAME, factory, allPartitions);
    // assert that all entries have been written
    IMap<String, String> map = hz.getMap(mapName);
    assertEquals(format("Expected %d entries in the map", expectedEntryCount), expectedEntryCount, map.size());
    for (Map.Entry<String, String> entry : map.entrySet()) {
        assertEquals("Expected that key and value are the same", entry.getKey(), entry.getValue());
    }
    // assert that each member owns entriesPerPartition entries of the map and that all backups have been written
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            int totalBackups = 0;
            for (int i = 0; i < INSTANCE_COUNT; i++) {
                IMap map = instances[i].getMap(mapName);
                assertEquals(format("Each member should own %d entries of the map", entriesPerPartition), entriesPerPartition, map.getLocalMapStats().getOwnedEntryCount());
                totalBackups += map.getLocalMapStats().getBackupEntryCount();
            }
            assertEquals(format("Expected to find %d backups in the cluster", expectedEntryCount), expectedEntryCount, totalBackups);
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) SerializationService(com.hazelcast.internal.serialization.SerializationService) PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) PutAllPartitionAwareOperationFactory(com.hazelcast.map.impl.operation.PutAllPartitionAwareOperationFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) Map(java.util.Map) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 63 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class EvictBatchBackupOperationTest method operation_evicts_all_replicas.

@Test
public void operation_evicts_all_replicas() {
    // 1. Create config
    int backupCount = 2;
    final String mapName = "test";
    Config config = getConfig();
    config.getMapConfig(mapName).setBackupCount(backupCount);
    // 2. Create nodes
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    HazelcastInstance node3 = factory.newHazelcastInstance(config);
    // 3. Populate replicas
    IMap map = node1.getMap(mapName);
    for (int i = 0; i < 1000; i++) {
        map.set(i, i);
    }
    // 4. Evict all replicas
    int partitionCount = getPartitionService(node1).getPartitionCount();
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        for (int replicaIndex = 0; replicaIndex <= backupCount; replicaIndex++) {
            EvictBatchBackupOperation operation = new EvictBatchBackupOperation(mapName, Collections.<ExpiredKey>emptyList(), 0);
            OperationServiceImpl operationService = getOperationService(node1);
            operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, partitionId).setReplicaIndex(replicaIndex).invoke().join();
        }
    }
    // 5. All replicas should be empty in the end.
    for (HazelcastInstance node : factory.getAllHazelcastInstances()) {
        assertEquals(0, sumOwnedAndBackupEntryCount(node.getMap(mapName).getLocalMapStats()));
    }
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) 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 64 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class IndeterminateOperationStateExceptionTest method partitionInvocation_shouldFailOnBackupTimeout_whenConfigurationEnabledForInvocation.

@Test
public void partitionInvocation_shouldFailOnBackupTimeout_whenConfigurationEnabledForInvocation() throws InterruptedException, TimeoutException {
    setup(false);
    dropOperationsBetween(instance1, instance2, F_ID, singletonList(SpiDataSerializerHook.BACKUP));
    int partitionId = getPartitionId(instance1);
    OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
    InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new PrimaryOperation(), partitionId).setFailOnIndeterminateOperationState(true).invoke();
    try {
        future.get(2, TimeUnit.MINUTES);
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof IndeterminateOperationStateException);
    }
}
Also used : 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 65 with OperationServiceImpl

use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.

the class IndeterminateOperationStateExceptionTest method partitionInvocation_shouldFailOnBackupTimeout_whenConfigurationEnabledGlobally.

@Test
public void partitionInvocation_shouldFailOnBackupTimeout_whenConfigurationEnabledGlobally() throws InterruptedException, TimeoutException {
    setup(true);
    dropOperationsBetween(instance1, instance2, F_ID, singletonList(SpiDataSerializerHook.BACKUP));
    int partitionId = getPartitionId(instance1);
    OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
    InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new PrimaryOperation(), partitionId).invoke();
    try {
        future.get(2, TimeUnit.MINUTES);
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof IndeterminateOperationStateException);
    }
}
Also used : 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)

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