use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class RaftService method completeFutures.
/**
* Completes all futures registered with {@code indices}
* in the CP group associated with {@code groupId}.
*
* @return {@code true} if the CP group exists, {@code false} otherwise.
*/
public boolean completeFutures(CPGroupId groupId, Collection<Long> indices, Object result) {
if (cpSubsystemEnabled) {
RaftNodeImpl raftNode = (RaftNodeImpl) getRaftNode(groupId);
if (raftNode == null) {
return false;
}
for (Long index : indices) {
raftNode.completeFuture(index, result);
}
} else {
int partitionId = getCPGroupPartitionId(groupId);
UnsafeModePartitionState unsafeModeState = unsafeModeStates[partitionId];
for (Long index : indices) {
Operation op = unsafeModeState.removeWaitingOp(index);
sendOperationResponse(op, result);
}
}
return true;
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class ContainsValueOperationTest method executeOperation.
private InternalCompletableFuture<Object> executeOperation(Map map, String key, int value) {
int partitionId = getNode(member1).getPartitionService().getPartitionId(key);
MapProxyImpl mapProxy = (MapProxyImpl) map;
MapServiceContext mapServiceContext = ((MapService) mapProxy.getService()).getMapServiceContext();
MapOperationProvider operationProvider = mapServiceContext.getMapOperationProvider(mapProxy.getName());
OperationFactory operationFactory = operationProvider.createContainsValueOperationFactory(mapProxy.getName(), mapServiceContext.toData(value));
Operation operation = operationFactory.createOperation();
OperationServiceImpl operationService = getOperationService(member1);
return operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, partitionId).invoke();
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class SplitBrainProtectionOperationTest method assertThatInternalOperationsAreNotSplitBrainProtectionDependent.
@Test
public void assertThatInternalOperationsAreNotSplitBrainProtectionDependent() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Iterator<DataSerializerHook> hooks = ServiceLoader.iterator(DataSerializerHook.class, FACTORY_ID, classLoader);
while (hooks.hasNext()) {
DataSerializerHook hook = hooks.next();
String simpleClassName = hook.getClass().getName();
LOGGER.info("Testing " + simpleClassName + "...");
DataSerializableFactory factory = hook.createFactory();
int typeId = 0;
while (true) {
IdentifiedDataSerializable ids = createIDS(factory, typeId++);
if (ids == null) {
break;
}
Class<? extends IdentifiedDataSerializable> clazz = ids.getClass();
String className = clazz.getName();
String name = lowerCaseInternal(clazz.getSimpleName());
LOGGER.info(clazz.getSimpleName());
if (matches(NO_SPLIT_BRAIN_PROTECTION_PACKAGES, className)) {
continue;
}
boolean shouldBeMutatingOperation = false;
boolean shouldBeReadonlyOperation = false;
if (!(ids instanceof Operation) || ids instanceof UrgentSystemOperation || matches(INTERNAL_CLASS_NAMES, name) || matches(INTERNAL_PACKAGES, className)) {
// no, urgent, internal or no split brain protection operations
shouldBeMutatingOperation = false;
shouldBeReadonlyOperation = false;
} else if (ids instanceof AbstractLockOperation || matches(MUTATING_CLASS_NAMES, name)) {
// mutating operations
if (isForcedReadOnly(className)) {
shouldBeReadonlyOperation = true;
} else {
shouldBeMutatingOperation = true;
}
} else if (matches(READONLY_CLASS_NAMES, name)) {
// read-only operations
shouldBeReadonlyOperation = true;
} else {
fail(className + " doesn't match any criteria!");
}
// asserts
if (ids instanceof MutatingOperation) {
if (!shouldBeMutatingOperation) {
fail(className + " implements " + MUTATING_OP_NAME);
}
} else if (shouldBeMutatingOperation) {
fail(className + " should implement " + MUTATING_OP_NAME);
}
if (ids instanceof ReadonlyOperation) {
if (!shouldBeReadonlyOperation) {
fail(className + " implements " + READ_ONLY_OP_NAME);
}
} else if (shouldBeReadonlyOperation) {
fail(className + " should implement " + READ_ONLY_OP_NAME);
}
}
}
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class InvocationFuture_GetNewInstanceTest method invocationToLocalMember.
@Test
public void invocationToLocalMember() throws ExecutionException, InterruptedException {
Node localNode = getNode(local);
Data response = localNode.nodeEngine.toData(new DummyObject());
Operation op = new OperationWithResponse(response);
OperationService service = getOperationService(local);
Future future = service.createInvocationBuilder(null, op, localNode.address).invoke();
Object instance1 = future.get();
Object instance2 = future.get();
assertNotNull(instance1);
assertNotNull(instance2);
assertTrue(instance1 instanceof DummyObject);
assertTrue(instance2 instanceof DummyObject);
assertNotSame(instance1, instance2);
assertNotSame(instance1, response);
assertNotSame(instance2, response);
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class InvocationFuture_GetNewInstanceTest method invocationToRemoteMember.
@Test
public void invocationToRemoteMember() throws ExecutionException, InterruptedException {
Node localNode = getNode(local);
Data response = localNode.nodeEngine.toData(new DummyObject());
Operation op = new OperationWithResponse(response);
Address remoteAddress = getAddress(remote);
OperationService operationService = getOperationService(local);
Future future = operationService.createInvocationBuilder(null, op, remoteAddress).invoke();
Object instance1 = future.get();
Object instance2 = future.get();
assertNotNull(instance1);
assertNotNull(instance2);
assertTrue(instance1 instanceof DummyObject);
assertTrue(instance2 instanceof DummyObject);
assertNotSame(instance1, instance2);
assertNotSame(instance1, response);
assertNotSame(instance2, response);
}
Aggregations