Search in sources :

Example 6 with Value

use of org.apache.ignite.configuration.annotation.Value in project ignite-3 by apache.

the class DirectPropertiesTest method testNamedListDirectNestedProperties.

/**
 * Same as {@link #testDirectProperties} but checks Named List properties.
 */
@Test
public void testNamedListDirectNestedProperties() throws Exception {
    DirectConfiguration cfg = registry.getConfiguration(DirectConfiguration.KEY);
    cfg.children().change(list -> list.create("foo", e -> e.changeChildren2(list2 -> list2.create("boo", e2 -> {
    })))).get(1, TimeUnit.SECONDS);
    UUID fooId = cfg.children().get("foo").id().value();
    UUID booId = cfg.children().get("foo").children2().get("boo").id().value();
    assertThat(booId, is(notNullValue()));
    // Check all possible ways to access "str", just to be sure. Some of these checks are clearly excessive, but they look organic.
    // Using names in both lists.
    assertThat(directProxy(cfg).value().children().get("foo").children2().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg).children().value().get("foo").children2().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg).children().get("foo").value().children2().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg).children().get("foo").children2().value().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg).children().get("foo").children2().get("boo").value().str(), is("bar"));
    assertThat(directProxy(cfg).children().get("foo").children2().get("boo").str().value(), is("bar"));
    assertThat(directProxy(cfg.children()).value().get("foo").children2().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg.children()).get("foo").value().children2().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg.children()).get("foo").children2().value().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg.children()).get("foo").children2().get("boo").value().str(), is("bar"));
    assertThat(directProxy(cfg.children()).get("foo").children2().get("boo").str().value(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo")).value().children2().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo")).children2().value().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo")).children2().get("boo").value().str(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo")).children2().get("boo").str().value(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo").children2()).value().get("boo").str(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo").children2()).get("boo").value().str(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo").children2()).get("boo").str().value(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo").children2().get("boo")).value().str(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo").children2().get("boo")).str().value(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo").children2().get("boo").str()).value(), is("bar"));
    // Using internalId and name.
    assertThat(getByInternalId(directProxy(cfg).value().children(), fooId).children2().get("boo").str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children().value(), fooId).children2().get("boo").str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children(), fooId).value().children2().get("boo").str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children(), fooId).children2().value().get("boo").str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children(), fooId).children2().get("boo").value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children(), fooId).children2().get("boo").str().value(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()).value(), fooId).children2().get("boo").str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()), fooId).value().children2().get("boo").str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()), fooId).children2().value().get("boo").str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()), fooId).children2().get("boo").value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()), fooId).children2().get("boo").str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId)).value().children2().get("boo").str(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId)).children2().value().get("boo").str(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId)).children2().get("boo").value().str(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId)).children2().get("boo").str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId).children2()).value().get("boo").str(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId).children2()).get("boo").value().str(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId).children2()).get("boo").str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId).children2().get("boo")).value().str(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId).children2().get("boo")).str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId).children2().get("boo").str()).value(), is("bar"));
    // Using name and internalId.
    assertThat(getByInternalId(directProxy(cfg).value().children().get("foo").children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children().value().get("foo").children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children().get("foo").value().children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children().get("foo").children2().value(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children().get("foo").children2(), booId).value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children().get("foo").children2(), booId).str().value(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()).value().get("foo").children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()).get("foo").value().children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()).get("foo").children2().value(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()).get("foo").children2(), booId).value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()).get("foo").children2(), booId).str().value(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children().get("foo")).value().children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children().get("foo")).children2().value(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children().get("foo")).children2(), booId).value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children().get("foo")).children2(), booId).str().value(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children().get("foo").children2()).value(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children().get("foo").children2()), booId).value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children().get("foo").children2()), booId).str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children().get("foo").children2(), booId)).value().str(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children().get("foo").children2(), booId)).str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children().get("foo").children2(), booId).str()).value(), is("bar"));
    // Using internalId and internalId.
    assertThat(getByInternalId(getByInternalId(directProxy(cfg).value().children(), fooId).children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg).children().value(), fooId).children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg).children(), fooId).value().children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg).children(), fooId).children2().value(), booId).str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg).children(), fooId).children2(), booId).value().str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg).children(), fooId).children2(), booId).str().value(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg.children()).value(), fooId).children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg.children()), fooId).value().children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg.children()), fooId).children2().value(), booId).str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg.children()), fooId).children2(), booId).value().str(), is("bar"));
    assertThat(getByInternalId(getByInternalId(directProxy(cfg.children()), fooId).children2(), booId).str().value(), is("bar"));
    assertThat(getByInternalId(directProxy(getByInternalId(cfg.children(), fooId)).value().children2(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(getByInternalId(cfg.children(), fooId)).children2().value(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(getByInternalId(cfg.children(), fooId)).children2(), booId).value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(getByInternalId(cfg.children(), fooId)).children2(), booId).str().value(), is("bar"));
    assertThat(getByInternalId(directProxy(getByInternalId(cfg.children(), fooId).children2()).value(), booId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(getByInternalId(cfg.children(), fooId).children2()), booId).value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(getByInternalId(cfg.children(), fooId).children2()), booId).str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(getByInternalId(cfg.children(), fooId).children2(), booId)).value().str(), is("bar"));
    assertThat(directProxy(getByInternalId(getByInternalId(cfg.children(), fooId).children2(), booId)).str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(getByInternalId(cfg.children(), fooId).children2(), booId).str()).value(), is("bar"));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) ConfigurationUtil.directProxy(org.apache.ignite.internal.configuration.util.ConfigurationUtil.directProxy) ConfigurationUtil.getByInternalId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.getByInternalId) CompletableFuture(java.util.concurrent.CompletableFuture) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NamedConfigurationTree(org.apache.ignite.configuration.NamedConfigurationTree) NoSuchElementException(java.util.NoSuchElementException) ConfigurationListenOnlyException(org.apache.ignite.configuration.ConfigurationListenOnlyException) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) Name(org.apache.ignite.configuration.annotation.Name) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) CompletableFutureMatcher.willBe(org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe) UUID(java.util.UUID) InternalId(org.apache.ignite.configuration.annotation.InternalId) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) InjectedName(org.apache.ignite.configuration.annotation.InjectedName) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Config(org.apache.ignite.configuration.annotation.Config) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Matchers.is(org.hamcrest.Matchers.is) Value(org.apache.ignite.configuration.annotation.Value) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 7 with Value

use of org.apache.ignite.configuration.annotation.Value in project ignite-3 by apache.

the class DirectPropertiesTest method testNamedListDirectProperties.

/**
 * Same as {@link #testDirectProperties} but checks Named List properties.
 */
@Test
public void testNamedListDirectProperties() throws Exception {
    DirectConfiguration cfg = registry.getConfiguration(DirectConfiguration.KEY);
    cfg.children().change(change -> change.create("foo", value -> {
    })).get(1, TimeUnit.SECONDS);
    UUID fooId = cfg.children().get("foo").id().value();
    assertThat(fooId, is(notNullValue()));
    // Check all possible ways to access "str" of element named "foo".
    assertThat(directProxy(cfg).value().children().get("foo").str(), is("bar"));
    assertThat(directProxy(cfg).children().value().get("foo").str(), is("bar"));
    assertThat(directProxy(cfg).children().get("foo").value().str(), is("bar"));
    assertThat(directProxy(cfg).children().get("foo").str().value(), is("bar"));
    assertThat(directProxy(cfg.children()).value().get("foo").str(), is("bar"));
    assertThat(directProxy(cfg.children()).get("foo").value().str(), is("bar"));
    assertThat(directProxy(cfg.children()).get("foo").str().value(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo")).value().str(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo")).str().value(), is("bar"));
    assertThat(directProxy(cfg.children().get("foo").str()).value(), is("bar"));
    // Check all possible ways to access "str" of element with given internal id.
    assertThat(getByInternalId(directProxy(cfg).value().children(), fooId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children().value(), fooId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children(), fooId).value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg).children(), fooId).str().value(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()).value(), fooId).str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()), fooId).value().str(), is("bar"));
    assertThat(getByInternalId(directProxy(cfg.children()), fooId).str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId)).value().str(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId)).str().value(), is("bar"));
    assertThat(directProxy(getByInternalId(cfg.children(), fooId).str()).value(), is("bar"));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) ConfigurationUtil.directProxy(org.apache.ignite.internal.configuration.util.ConfigurationUtil.directProxy) ConfigurationUtil.getByInternalId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.getByInternalId) CompletableFuture(java.util.concurrent.CompletableFuture) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NamedConfigurationTree(org.apache.ignite.configuration.NamedConfigurationTree) NoSuchElementException(java.util.NoSuchElementException) ConfigurationListenOnlyException(org.apache.ignite.configuration.ConfigurationListenOnlyException) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) Name(org.apache.ignite.configuration.annotation.Name) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) CompletableFutureMatcher.willBe(org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe) UUID(java.util.UUID) InternalId(org.apache.ignite.configuration.annotation.InternalId) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) InjectedName(org.apache.ignite.configuration.annotation.InjectedName) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Config(org.apache.ignite.configuration.annotation.Config) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Matchers.is(org.hamcrest.Matchers.is) Value(org.apache.ignite.configuration.annotation.Value) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 8 with Value

use of org.apache.ignite.configuration.annotation.Value in project ignite-3 by apache.

the class ConfigurationUtilTest method findSuccessfully.

/**
 * Tests that {@link ConfigurationUtil#find(List, TraversableTreeNode, boolean)} finds proper node when provided with correct path.
 */
@Test
public void findSuccessfully() {
    InnerNode parentNode = newNodeInstance(ParentConfigurationSchema.class);
    ParentChange parentChange = (ParentChange) parentNode;
    parentChange.changeElements(elements -> elements.createOrUpdate("name", element -> element.changeChild(child -> child.changeStr("value"))));
    assertSame(parentNode, ConfigurationUtil.find(List.of(), parentNode, true));
    assertSame(parentChange.elements(), ConfigurationUtil.find(List.of("elements"), parentNode, true));
    assertSame(parentChange.elements().get("name"), ConfigurationUtil.find(List.of("elements", "name"), parentNode, true));
    assertSame(parentChange.elements().get("name").child(), ConfigurationUtil.find(List.of("elements", "name", "child"), parentNode, true));
    assertSame(parentChange.elements().get("name").child().str(), ConfigurationUtil.find(List.of("elements", "name", "child", "str"), parentNode, true));
}
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) RootInnerNode(org.apache.ignite.internal.configuration.RootInnerNode) InnerNode(org.apache.ignite.internal.configuration.tree.InnerNode) Test(org.junit.jupiter.api.Test)

Example 9 with Value

use of org.apache.ignite.configuration.annotation.Value in project ignite-3 by apache.

the class Processor method getInterfaceGetMethodType.

/**
 * Get types for configuration classes generation.
 *
 * @param field Field.
 * @return Bundle with all types for configuration
 */
private static TypeName getInterfaceGetMethodType(VariableElement field) {
    TypeName interfaceGetMethodType = null;
    TypeName baseType = TypeName.get(field.asType());
    ConfigValue confAnnotation = field.getAnnotation(ConfigValue.class);
    if (confAnnotation != null) {
        interfaceGetMethodType = Utils.getConfigurationInterfaceName((ClassName) baseType);
    }
    NamedConfigValue namedConfigAnnotation = field.getAnnotation(NamedConfigValue.class);
    if (namedConfigAnnotation != null) {
        ClassName interfaceGetType = Utils.getConfigurationInterfaceName((ClassName) baseType);
        TypeName viewClassType = Utils.getViewName((ClassName) baseType);
        TypeName changeClassType = Utils.getChangeName((ClassName) baseType);
        interfaceGetMethodType = ParameterizedTypeName.get(ClassName.get(NamedConfigurationTree.class), interfaceGetType, viewClassType, changeClassType);
    }
    Value valueAnnotation = field.getAnnotation(Value.class);
    PolymorphicId polymorphicIdAnnotation = field.getAnnotation(PolymorphicId.class);
    InjectedName injectedNameAnnotation = field.getAnnotation(InjectedName.class);
    InternalId internalIdAnnotation = field.getAnnotation(InternalId.class);
    if (valueAnnotation != null || polymorphicIdAnnotation != null || injectedNameAnnotation != null || internalIdAnnotation != null) {
        // It is necessary to use class names without loading classes so that we won't
        // accidentally get NoClassDefFoundError
        ClassName confValueClass = ClassName.get("org.apache.ignite.configuration", "ConfigurationValue");
        TypeName genericType = baseType;
        if (genericType.isPrimitive()) {
            genericType = genericType.box();
        }
        interfaceGetMethodType = ParameterizedTypeName.get(confValueClass, genericType);
    }
    return interfaceGetMethodType;
}
Also used : NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) TypeName(com.squareup.javapoet.TypeName) WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) InternalId(org.apache.ignite.configuration.annotation.InternalId) InjectedName(org.apache.ignite.configuration.annotation.InjectedName) ClassName(com.squareup.javapoet.ClassName) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Value(org.apache.ignite.configuration.annotation.Value)

Example 10 with Value

use of org.apache.ignite.configuration.annotation.Value in project ignite-3 by apache.

the class Processor method process0.

/**
 * Processes a set of annotation types on type elements.
 *
 * @param roundEnvironment Processing environment.
 * @return Whether the set of annotation types are claimed by this processor.
 */
private boolean process0(RoundEnvironment roundEnvironment) {
    Elements elementUtils = processingEnv.getElementUtils();
    // All classes annotated with {@link #supportedAnnotationTypes}.
    List<TypeElement> annotatedConfigs = roundEnvironment.getElementsAnnotatedWithAny(supportedAnnotationTypes()).stream().filter(element -> element.getKind() == ElementKind.CLASS).map(TypeElement.class::cast).collect(toList());
    if (annotatedConfigs.isEmpty()) {
        return false;
    }
    for (TypeElement clazz : annotatedConfigs) {
        // Find all the fields of the schema.
        List<VariableElement> fields = fields(clazz);
        validate(clazz, fields);
        // Get package name of the schema class
        String packageName = elementUtils.getPackageOf(clazz).getQualifiedName().toString();
        ClassName schemaClassName = ClassName.get(packageName, clazz.getSimpleName().toString());
        // Get name for generated configuration interface.
        ClassName configInterface = Utils.getConfigurationInterfaceName(schemaClassName);
        TypeSpec.Builder configurationInterfaceBuilder = TypeSpec.interfaceBuilder(configInterface).addModifiers(PUBLIC);
        for (VariableElement field : fields) {
            if (!field.getModifiers().contains(PUBLIC)) {
                throw new ProcessorException("Field " + clazz.getQualifiedName() + "." + field + " must be public");
            }
            final String fieldName = field.getSimpleName().toString();
            // Get configuration types (VIEW, CHANGE and so on)
            final TypeName interfaceGetMethodType = getInterfaceGetMethodType(field);
            if (field.getAnnotation(ConfigValue.class) != null) {
                checkConfigField(field, ConfigValue.class);
                checkMissingNameForInjectedName(field);
            }
            if (field.getAnnotation(NamedConfigValue.class) != null) {
                checkConfigField(field, NamedConfigValue.class);
            }
            Value valueAnnotation = field.getAnnotation(Value.class);
            if (valueAnnotation != null) {
                // Must be a primitive or an array of the primitives (including java.lang.String)
                if (!isPrimitiveOrArray(field.asType())) {
                    throw new ProcessorException("@Value " + clazz.getQualifiedName() + "." + field.getSimpleName() + " field must" + " have one of the following types: boolean, int, long, double, String or an array of " + "aforementioned type.");
                }
            }
            PolymorphicId polymorphicId = field.getAnnotation(PolymorphicId.class);
            if (polymorphicId != null) {
                if (!isClass(field.asType(), String.class)) {
                    throw new ProcessorException(String.format(FIELD_MUST_BE_SPECIFIC_CLASS_ERROR_FORMAT, simpleName(PolymorphicId.class), clazz.getQualifiedName(), field.getSimpleName(), String.class.getSimpleName()));
                }
            }
            if (field.getAnnotation(InternalId.class) != null) {
                if (!isClass(field.asType(), UUID.class)) {
                    throw new ProcessorException(String.format(FIELD_MUST_BE_SPECIFIC_CLASS_ERROR_FORMAT, simpleName(InternalId.class), clazz.getQualifiedName(), field.getSimpleName(), UUID.class.getSimpleName()));
                }
            }
            createGetters(configurationInterfaceBuilder, fieldName, interfaceGetMethodType);
        }
        // Is root of the configuration.
        boolean isRootConfig = clazz.getAnnotation(ConfigurationRoot.class) != null;
        // Is the internal configuration.
        boolean isInternalConfig = clazz.getAnnotation(InternalConfiguration.class) != null;
        // Is a polymorphic configuration.
        boolean isPolymorphicConfig = clazz.getAnnotation(PolymorphicConfig.class) != null;
        // Is an instance of a polymorphic configuration.
        boolean isPolymorphicInstance = clazz.getAnnotation(PolymorphicConfigInstance.class) != null;
        // Create VIEW and CHANGE classes.
        createPojoBindings(fields, schemaClassName, configurationInterfaceBuilder, (isInternalConfig && !isRootConfig) || isPolymorphicInstance, clazz, isPolymorphicConfig, isPolymorphicInstance);
        if (isRootConfig) {
            createRootKeyField(configInterface, configurationInterfaceBuilder, schemaClassName, clazz);
        }
        // Write configuration interface
        buildClass(packageName, configurationInterfaceBuilder.build());
    }
    return true;
}
Also used : PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) TypeName(com.squareup.javapoet.TypeName) WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) InternalId(org.apache.ignite.configuration.annotation.InternalId) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) Elements(javax.lang.model.util.Elements) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) ClassName(com.squareup.javapoet.ClassName) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) Value(org.apache.ignite.configuration.annotation.Value) InternalConfiguration(org.apache.ignite.configuration.annotation.InternalConfiguration) UUID(java.util.UUID) TypeSpec(com.squareup.javapoet.TypeSpec)

Aggregations

ConfigValue (org.apache.ignite.configuration.annotation.ConfigValue)11 Value (org.apache.ignite.configuration.annotation.Value)11 NamedConfigValue (org.apache.ignite.configuration.annotation.NamedConfigValue)10 UUID (java.util.UUID)8 ConfigurationRoot (org.apache.ignite.configuration.annotation.ConfigurationRoot)8 TestConfigurationStorage (org.apache.ignite.internal.configuration.storage.TestConfigurationStorage)8 Matchers.nullValue (org.hamcrest.Matchers.nullValue)8 List (java.util.List)7 Map (java.util.Map)7 NoSuchElementException (java.util.NoSuchElementException)7 Config (org.apache.ignite.configuration.annotation.Config)7 LOCAL (org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL)7 InjectedName (org.apache.ignite.configuration.annotation.InjectedName)7 InternalId (org.apache.ignite.configuration.annotation.InternalId)7 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Matchers.is (org.hamcrest.Matchers.is)7 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)7 Test (org.junit.jupiter.api.Test)7 ConfigurationRegistry (org.apache.ignite.internal.configuration.ConfigurationRegistry)6 CompletableFuture (java.util.concurrent.CompletableFuture)5