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();
}
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);
}
});
}
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()));
}
}
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);
}
}
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);
}
}
Aggregations