Search in sources :

Example 96 with Operation

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;
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 97 with Operation

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();
}
Also used : MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 98 with Operation

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);
            }
        }
    }
}
Also used : IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) IsPartitionLoadedOperation(com.hazelcast.map.impl.operation.IsPartitionLoadedOperation) MutatingOperation(com.hazelcast.spi.impl.operationservice.MutatingOperation) TriggerLoadIfNeededOperation(com.hazelcast.map.impl.operation.TriggerLoadIfNeededOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) ReadonlyOperation(com.hazelcast.spi.impl.operationservice.ReadonlyOperation) MapEventJournalSubscribeOperation(com.hazelcast.map.impl.journal.MapEventJournalSubscribeOperation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) NotifyMapFlushOperation(com.hazelcast.map.impl.operation.NotifyMapFlushOperation) UrgentSystemOperation(com.hazelcast.spi.impl.operationservice.UrgentSystemOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) AbstractLockOperation(com.hazelcast.internal.locksupport.operations.AbstractLockOperation) AbstractLockOperation(com.hazelcast.internal.locksupport.operations.AbstractLockOperation) MutatingOperation(com.hazelcast.spi.impl.operationservice.MutatingOperation) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) ReadonlyOperation(com.hazelcast.spi.impl.operationservice.ReadonlyOperation) DataSerializerHook(com.hazelcast.internal.serialization.DataSerializerHook) UrgentSystemOperation(com.hazelcast.spi.impl.operationservice.UrgentSystemOperation) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 99 with Operation

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);
}
Also used : Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.internal.serialization.Data) Operation(com.hazelcast.spi.impl.operationservice.Operation) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 100 with Operation

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);
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.internal.serialization.Data) Operation(com.hazelcast.spi.impl.operationservice.Operation) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Operation (com.hazelcast.spi.impl.operationservice.Operation)271 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)79 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)56 Address (com.hazelcast.cluster.Address)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)25 Data (com.hazelcast.internal.serialization.Data)24 Future (java.util.concurrent.Future)24 Member (com.hazelcast.cluster.Member)22 ArrayList (java.util.ArrayList)21 NodeEngine (com.hazelcast.spi.impl.NodeEngine)18 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)17 AssertTask (com.hazelcast.test.AssertTask)15 ILogger (com.hazelcast.logging.ILogger)14 UrgentSystemOperation (com.hazelcast.spi.impl.operationservice.UrgentSystemOperation)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 Config (com.hazelcast.config.Config)12 CompletableFuture (java.util.concurrent.CompletableFuture)12