Search in sources :

Example 1 with ConverterToMapVisitor

use of org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor in project ignite-3 by apache.

the class ConfigurationUtilTest method testGetInternalConfigs.

@Test
void testGetInternalConfigs() {
    Map<Class<?>, Set<Class<?>>> internalExtensions = internalSchemaExtensions(List.of(InternalFirstRootConfigurationSchema.class, InternalSecondRootConfigurationSchema.class, InternalFirstConfigurationSchema.class, InternalSecondConfigurationSchema.class));
    ConfigurationAsmGenerator generator = new ConfigurationAsmGenerator();
    generator.compileRootSchema(InternalRootConfigurationSchema.class, internalExtensions, Map.of());
    InnerNode innerNode = generator.instantiateNode(InternalRootConfigurationSchema.class);
    addDefaults(innerNode);
    Map<String, Object> config = (Map<String, Object>) innerNode.accept(null, new ConverterToMapVisitor(false));
    // Check that no internal configuration will be received.
    assertEquals(4, config.size());
    assertNull(config.get("str0"));
    assertEquals("foo", config.get("str1"));
    assertNotNull(config.get("subCfg"));
    assertNotNull(config.get("namedCfg"));
    Map<String, Object> subConfig = (Map<String, Object>) config.get("subCfg");
    assertEquals(1, subConfig.size());
    assertEquals("foo", subConfig.get("str00"));
    // Check that no internal configuration will be received.
    config = (Map<String, Object>) innerNode.accept(null, new ConverterToMapVisitor(true));
    assertEquals(7, config.size());
    assertNull(config.get("str0"));
    assertNull(config.get("str2"));
    assertEquals("foo", config.get("str1"));
    assertEquals("foo", config.get("str3"));
    assertNotNull(config.get("subCfg"));
    assertNotNull(config.get("subCfg1"));
    assertNotNull(config.get("namedCfg"));
    subConfig = (Map<String, Object>) config.get("subCfg");
    assertEquals(3, subConfig.size());
    assertEquals("foo", subConfig.get("str00"));
    assertEquals("foo", subConfig.get("str01"));
    assertEquals("foo", subConfig.get("str02"));
    subConfig = (Map<String, Object>) config.get("subCfg1");
    assertEquals(3, subConfig.size());
    assertEquals("foo", subConfig.get("str00"));
    assertEquals("foo", subConfig.get("str01"));
    assertEquals("foo", subConfig.get("str02"));
}
Also used : Set(java.util.Set) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) ConverterToMapVisitor(org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor) Matchers.hasToString(org.hamcrest.Matchers.hasToString) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) Map(java.util.Map) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Test(org.junit.jupiter.api.Test)

Example 2 with ConverterToMapVisitor

use of org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor in project ignite-3 by apache.

the class ConfigurationUtilTest method testSuperRootWithInternalConfig.

@Test
void testSuperRootWithInternalConfig() {
    ConfigurationAsmGenerator generator = new ConfigurationAsmGenerator();
    Class<?> schemaClass = InternalWithoutSuperclassConfigurationSchema.class;
    RootKey<?, ?> schemaKey = InternalWithoutSuperclassConfiguration.KEY;
    generator.compileRootSchema(schemaClass, Map.of(), Map.of());
    SuperRoot superRoot = new SuperRoot(s -> new RootInnerNode(schemaKey, generator.instantiateNode(schemaClass)));
    assertThrows(NoSuchElementException.class, () -> superRoot.construct(schemaKey.key(), null, false));
    superRoot.construct(schemaKey.key(), null, true);
    superRoot.addRoot(schemaKey, generator.instantiateNode(schemaClass));
    assertThrows(KeyNotFoundException.class, () -> find(List.of(schemaKey.key()), superRoot, false));
    assertNotNull(find(List.of(schemaKey.key()), superRoot, true));
    Map<String, Object> config = (Map<String, Object>) superRoot.accept(schemaKey.key(), new ConverterToMapVisitor(false));
    assertTrue(config.isEmpty());
    config = (Map<String, Object>) superRoot.accept(schemaKey.key(), new ConverterToMapVisitor(true));
    assertEquals(1, config.size());
    assertNotNull(config.get(schemaKey.key()));
}
Also used : RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) ConverterToMapVisitor(org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor) SuperRoot(org.apache.ignite.internal.configuration.SuperRoot) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Map(java.util.Map) ConfigurationFlattener.createFlattenedUpdatesMap(org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Test(org.junit.jupiter.api.Test)

Aggregations

Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RootInnerNode (org.apache.ignite.internal.configuration.RootInnerNode)2 ConfigurationAsmGenerator (org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator)2 ConverterToMapVisitor (org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor)2 ConfigurationFlattener.createFlattenedUpdatesMap (org.apache.ignite.internal.configuration.util.ConfigurationFlattener.createFlattenedUpdatesMap)2 Matchers.anEmptyMap (org.hamcrest.Matchers.anEmptyMap)2 Matchers.hasToString (org.hamcrest.Matchers.hasToString)2 Test (org.junit.jupiter.api.Test)2 Set (java.util.Set)1 SuperRoot (org.apache.ignite.internal.configuration.SuperRoot)1 InnerNode (org.apache.ignite.internal.configuration.tree.InnerNode)1