Search in sources :

Example 1 with ReadonlyOperation

use of com.hazelcast.spi.impl.operationservice.ReadonlyOperation 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)

Aggregations

AbstractLockOperation (com.hazelcast.internal.locksupport.operations.AbstractLockOperation)1 DataSerializerHook (com.hazelcast.internal.serialization.DataSerializerHook)1 MapEventJournalSubscribeOperation (com.hazelcast.map.impl.journal.MapEventJournalSubscribeOperation)1 AwaitMapFlushOperation (com.hazelcast.map.impl.operation.AwaitMapFlushOperation)1 IsKeyLoadFinishedOperation (com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation)1 IsPartitionLoadedOperation (com.hazelcast.map.impl.operation.IsPartitionLoadedOperation)1 NotifyMapFlushOperation (com.hazelcast.map.impl.operation.NotifyMapFlushOperation)1 TriggerLoadIfNeededOperation (com.hazelcast.map.impl.operation.TriggerLoadIfNeededOperation)1 DataSerializableFactory (com.hazelcast.nio.serialization.DataSerializableFactory)1 IdentifiedDataSerializable (com.hazelcast.nio.serialization.IdentifiedDataSerializable)1 MutatingOperation (com.hazelcast.spi.impl.operationservice.MutatingOperation)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 ReadonlyOperation (com.hazelcast.spi.impl.operationservice.ReadonlyOperation)1 UrgentSystemOperation (com.hazelcast.spi.impl.operationservice.UrgentSystemOperation)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1