use of org.apache.ignite.internal.configuration.SuperRoot in project ignite-3 by apache.
the class ConfigurationUtilTest method testFlattenedMapPolymorphicConfig.
@Test
void testFlattenedMapPolymorphicConfig() {
InnerNode polymorphicRootInnerNode = newNodeInstance(PolymorphicRootConfigurationSchema.class);
addDefaults(polymorphicRootInnerNode);
RootKey<?, ?> rootKey = PolymorphicRootConfiguration.KEY;
SuperRoot superRoot = new SuperRoot(key -> null, Map.of(rootKey, polymorphicRootInnerNode));
final Map<String, Serializable> act = flattenedMap(superRoot, rootKey, node -> ((PolymorphicRootChange) node).changePolymorphicSubCfg(c -> c.convert(SecondPolymorphicInstanceChange.class)));
Map<String, Serializable> exp = new HashMap<>();
exp.put("rootPolymorphic.polymorphicSubCfg.typeId", "second");
exp.put("rootPolymorphic.polymorphicSubCfg.longVal", 0L);
exp.put("rootPolymorphic.polymorphicSubCfg.strVal", null);
exp.put("rootPolymorphic.polymorphicSubCfg.intVal", 0);
assertEquals(exp, act);
}
use of org.apache.ignite.internal.configuration.SuperRoot in project ignite-3 by apache.
the class ConfigurationUtilTest method flattenedMap.
/**
* Patches super root and returns flat representation of the changes. Passed {@code superRoot} object will contain patched tree when
* method execution is completed.
*
* @param superRoot Super root to patch.
* @param patch Closure to change inner node.
* @return Flat map with all changes from the patch.
*/
@NotNull
private Map<String, Serializable> flattenedMap(SuperRoot superRoot, RootKey<?, ?> rootKey, Consumer<InnerNode> patch) {
// Preserve a copy of the super root to use it as a golden source of data.
SuperRoot originalSuperRoot = superRoot.copy();
// Make a copy of the root inside the superRoot. This copy will be used for further patching.
superRoot.construct(rootKey.key(), EMPTY_CFG_SRC, true);
// Patch root node.
patch.accept(superRoot.getRoot(rootKey));
// Create flat diff between two super trees.
return createFlattenedUpdatesMap(originalSuperRoot, superRoot);
}
use of org.apache.ignite.internal.configuration.SuperRoot in project ignite-3 by apache.
the class ConfigurationUtilTest method testFlattenedMapPolymorphicNamedConfig.
@Test
void testFlattenedMapPolymorphicNamedConfig() {
InnerNode polymorphicRootInnerNode = newNodeInstance(PolymorphicRootConfigurationSchema.class);
PolymorphicRootChange polymorphicRootChange = ((PolymorphicRootChange) polymorphicRootInnerNode);
polymorphicRootChange.changePolymorphicNamedCfg(c -> c.create("0", c1 -> {
}));
addDefaults(polymorphicRootInnerNode);
RootKey<?, ?> rootKey = PolymorphicRootConfiguration.KEY;
SuperRoot superRoot = new SuperRoot(key -> null, Map.of(rootKey, polymorphicRootInnerNode));
final Map<String, Serializable> act = flattenedMap(superRoot, rootKey, node -> ((PolymorphicRootChange) node).changePolymorphicNamedCfg(c -> c.createOrUpdate("0", c1 -> c1.convert(SecondPolymorphicInstanceChange.class))));
NamedListNode<?> polymorphicNamedCfgListNode = (NamedListNode<?>) polymorphicRootChange.polymorphicNamedCfg();
UUID internalId = polymorphicNamedCfgListNode.internalId("0");
Map<String, Serializable> exp = new HashMap<>();
exp.put("rootPolymorphic.polymorphicNamedCfg." + internalId + ".typeId", "second");
exp.put("rootPolymorphic.polymorphicNamedCfg." + internalId + ".longVal", 0L);
exp.put("rootPolymorphic.polymorphicNamedCfg." + internalId + ".strVal", null);
exp.put("rootPolymorphic.polymorphicNamedCfg." + internalId + ".intVal", 0);
assertEquals(exp, act);
}
use of org.apache.ignite.internal.configuration.SuperRoot in project ignite-3 by apache.
the class ValidationUtilTest method validateLeafNode.
@Test
public void validateLeafNode() {
var rootsNode = new SuperRoot(key -> null, Map.of(ValidatedRootConfiguration.KEY, root));
Validator<LeafValidation, String> validator = new Validator<>() {
@Override
public void validate(LeafValidation annotation, ValidationContext<String> ctx) {
assertEquals("root.child.str", ctx.currentKey());
assertEquals("foo", ctx.getOldValue());
assertEquals("foo", ctx.getNewValue());
ctx.addIssue(new ValidationIssue("bar"));
}
};
Map<Class<? extends Annotation>, Set<Validator<?, ?>>> validators = Map.of(LeafValidation.class, Set.of(validator));
List<ValidationIssue> issues = ValidationUtil.validate(rootsNode, rootsNode, null, new HashMap<>(), validators);
assertEquals(1, issues.size());
assertEquals("bar", issues.get(0).message());
}
use of org.apache.ignite.internal.configuration.SuperRoot in project ignite-3 by apache.
the class ValidationUtilTest method validateInnerNode.
@Test
public void validateInnerNode() throws Exception {
var rootsNode = new SuperRoot(key -> null, Map.of(ValidatedRootConfiguration.KEY, root));
Validator<InnerValidation, ValidatedChildView> validator = new Validator<>() {
@Override
public void validate(InnerValidation annotation, ValidationContext<ValidatedChildView> ctx) {
assertEquals("root.child", ctx.currentKey());
assertEquals("foo", ctx.getOldValue().str());
assertEquals("foo", ctx.getNewValue().str());
ctx.addIssue(new ValidationIssue("bar"));
}
};
Map<Class<? extends Annotation>, Set<Validator<?, ?>>> validators = Map.of(InnerValidation.class, Set.of(validator));
List<ValidationIssue> issues = ValidationUtil.validate(rootsNode, rootsNode, null, new HashMap<>(), validators);
assertEquals(1, issues.size());
assertEquals("bar", issues.get(0).message());
}
Aggregations