Search in sources :

Example 1 with SuperRoot

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);
}
Also used : PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Arrays(java.util.Arrays) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) DISTRIBUTED(org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ConfigurationUtil.addDefaults(org.apache.ignite.internal.configuration.util.ConfigurationUtil.addDefaults) Matchers.allOf(org.hamcrest.Matchers.allOf) Set(java.util.Set) UUID(java.util.UUID) RootKey(org.apache.ignite.configuration.RootKey) Serializable(java.io.Serializable) ConfigurationUtil.removeLastKey(org.apache.ignite.internal.configuration.util.ConfigurationUtil.removeLastKey) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) List(java.util.List) NAME(org.apache.ignite.internal.configuration.tree.NamedListNode.NAME) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) ConfigurationUtil.checkConfigurationType(org.apache.ignite.internal.configuration.util.ConfigurationUtil.checkConfigurationType) ConfigurationUtil.collectSchemas(org.apache.ignite.internal.configuration.util.ConfigurationUtil.collectSchemas) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Config(org.apache.ignite.configuration.annotation.Config) Matchers.is(org.hamcrest.Matchers.is) NotNull(org.jetbrains.annotations.NotNull) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) EMPTY_CFG_SRC(org.apache.ignite.internal.configuration.util.ConfigurationUtil.EMPTY_CFG_SRC) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) ORDER_IDX(org.apache.ignite.internal.configuration.tree.NamedListNode.ORDER_IDX) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) ConfigurationUtil.internalSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.internalSchemaExtensions) TraversableTreeNode(org.apache.ignite.internal.configuration.tree.TraversableTreeNode) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) ConfigurationUtil.extensionsFields(org.apache.ignite.internal.configuration.util.ConfigurationUtil.extensionsFields) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) ConfigurationUtil.compressDeletedEntries(org.apache.ignite.internal.configuration.util.ConfigurationUtil.compressDeletedEntries) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Consumer(java.util.function.Consumer) ConverterToMapVisitor(org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor) Collectors.toList(java.util.stream.Collectors.toList) ConfigurationUtil.find(org.apache.ignite.internal.configuration.util.ConfigurationUtil.find) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ConfigurationUtil.polymorphicSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.polymorphicSchemaExtensions) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Value(org.apache.ignite.configuration.annotation.Value) InternalConfiguration(org.apache.ignite.configuration.annotation.InternalConfiguration) Serializable(java.io.Serializable) HashMap(java.util.HashMap) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) Matchers.hasToString(org.hamcrest.Matchers.hasToString) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) Test(org.junit.jupiter.api.Test)

Example 2 with SuperRoot

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);
}
Also used : SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) NotNull(org.jetbrains.annotations.NotNull) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull)

Example 3 with 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);
}
Also used : PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Arrays(java.util.Arrays) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) DISTRIBUTED(org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ConfigurationUtil.addDefaults(org.apache.ignite.internal.configuration.util.ConfigurationUtil.addDefaults) Matchers.allOf(org.hamcrest.Matchers.allOf) Set(java.util.Set) UUID(java.util.UUID) RootKey(org.apache.ignite.configuration.RootKey) Serializable(java.io.Serializable) ConfigurationUtil.removeLastKey(org.apache.ignite.internal.configuration.util.ConfigurationUtil.removeLastKey) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) List(java.util.List) NAME(org.apache.ignite.internal.configuration.tree.NamedListNode.NAME) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) ConfigurationUtil.checkConfigurationType(org.apache.ignite.internal.configuration.util.ConfigurationUtil.checkConfigurationType) ConfigurationUtil.collectSchemas(org.apache.ignite.internal.configuration.util.ConfigurationUtil.collectSchemas) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Config(org.apache.ignite.configuration.annotation.Config) Matchers.is(org.hamcrest.Matchers.is) NotNull(org.jetbrains.annotations.NotNull) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) EMPTY_CFG_SRC(org.apache.ignite.internal.configuration.util.ConfigurationUtil.EMPTY_CFG_SRC) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) ORDER_IDX(org.apache.ignite.internal.configuration.tree.NamedListNode.ORDER_IDX) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) ConfigurationUtil.internalSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.internalSchemaExtensions) TraversableTreeNode(org.apache.ignite.internal.configuration.tree.TraversableTreeNode) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) ConfigurationUtil.extensionsFields(org.apache.ignite.internal.configuration.util.ConfigurationUtil.extensionsFields) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) ConfigurationUtil.compressDeletedEntries(org.apache.ignite.internal.configuration.util.ConfigurationUtil.compressDeletedEntries) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Consumer(java.util.function.Consumer) ConverterToMapVisitor(org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor) Collectors.toList(java.util.stream.Collectors.toList) ConfigurationUtil.find(org.apache.ignite.internal.configuration.util.ConfigurationUtil.find) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ConfigurationUtil.polymorphicSchemaExtensions(org.apache.ignite.internal.configuration.util.ConfigurationUtil.polymorphicSchemaExtensions) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Value(org.apache.ignite.configuration.annotation.Value) InternalConfiguration(org.apache.ignite.configuration.annotation.InternalConfiguration) Serializable(java.io.Serializable) NamedListNode(org.apache.ignite.internal.configuration.tree.NamedListNode) HashMap(java.util.HashMap) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) Matchers.hasToString(org.hamcrest.Matchers.hasToString) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with SuperRoot

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());
}
Also used : Set(java.util.Set) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) Annotation(java.lang.annotation.Annotation) ValidationContext(org.apache.ignite.configuration.validation.ValidationContext) Validator(org.apache.ignite.configuration.validation.Validator) Test(org.junit.jupiter.api.Test)

Example 5 with SuperRoot

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());
}
Also used : Set(java.util.Set) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) Annotation(java.lang.annotation.Annotation) ValidationContext(org.apache.ignite.configuration.validation.ValidationContext) Validator(org.apache.ignite.configuration.validation.Validator) Test(org.junit.jupiter.api.Test)

Aggregations

SuperRoot (org.apache.ignite.internal.configuration.SuperRoot)8 Test (org.junit.jupiter.api.Test)6 Set (java.util.Set)5 RootInnerNode (org.apache.ignite.internal.configuration.RootInnerNode)4 Annotation (java.lang.annotation.Annotation)3 Collections.singletonMap (java.util.Collections.singletonMap)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 RootKey (org.apache.ignite.configuration.RootKey)3 ValidationContext (org.apache.ignite.configuration.validation.ValidationContext)3 ValidationIssue (org.apache.ignite.configuration.validation.ValidationIssue)3 Validator (org.apache.ignite.configuration.validation.Validator)3 ConfigurationAsmGenerator (org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator)3 ConverterToMapVisitor (org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor)3 InnerNode (org.apache.ignite.internal.configuration.tree.InnerNode)3 NotNull (org.jetbrains.annotations.NotNull)3 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)3 Serializable (java.io.Serializable)2 Arrays (java.util.Arrays)2