use of com.hazelcast.spi.impl.operationservice.UrgentSystemOperation 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);
}
}
}
}
Aggregations