Search in sources :

Example 1 with ConfigurationAsmGenerator

use of org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator in project ignite-3 by apache.

the class ConfigurationExtension method beforeEach.

/**
 * {@inheritDoc}
 */
@Override
public void beforeEach(ExtensionContext context) throws Exception {
    ConfigurationAsmGenerator cgen = new ConfigurationAsmGenerator();
    context.getStore(NAMESPACE).put(CGEN_KEY, cgen);
    Object testInstance = context.getRequiredTestInstance();
    ExecutorService pool = context.getStore(NAMESPACE).get(POOL_KEY, ExecutorService.class);
    StorageRevisionListenerHolderImpl revisionListenerHolder = new StorageRevisionListenerHolderImpl();
    context.getStore(NAMESPACE).put(REVISION_LISTENER_HOLDER_KEY, revisionListenerHolder);
    for (Field field : getInjectConfigurationFields(testInstance.getClass())) {
        field.setAccessible(true);
        InjectConfiguration annotation = field.getAnnotation(InjectConfiguration.class);
        field.set(testInstance, cfgValue(field.getType(), annotation, cgen, pool, revisionListenerHolder));
    }
    for (Field field : getInjectRevisionListenerHolderFields(testInstance.getClass())) {
        field.setAccessible(true);
        field.set(testInstance, revisionListenerHolder);
    }
}
Also used : Field(java.lang.reflect.Field) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) ExecutorService(java.util.concurrent.ExecutorService) ConfigObject(com.typesafe.config.ConfigObject)

Example 2 with ConfigurationAsmGenerator

use of org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator in project ignite-3 by apache.

the class ConfigurationExtension method resolveParameter.

/**
 * {@inheritDoc}
 */
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
    if (parameterContext.isAnnotated(InjectConfiguration.class)) {
        Parameter parameter = parameterContext.getParameter();
        ConfigurationAsmGenerator cgen = extensionContext.getStore(NAMESPACE).get(CGEN_KEY, ConfigurationAsmGenerator.class);
        StorageRevisionListenerHolderImpl revisionListenerHolder = extensionContext.getStore(NAMESPACE).get(REVISION_LISTENER_HOLDER_KEY, StorageRevisionListenerHolderImpl.class);
        try {
            ExecutorService pool = extensionContext.getStore(NAMESPACE).get(POOL_KEY, ExecutorService.class);
            return cfgValue(parameter.getType(), parameter.getAnnotation(InjectConfiguration.class), cgen, pool, revisionListenerHolder);
        } catch (ClassNotFoundException classNotFoundException) {
            throw new ParameterResolutionException("Cannot find a configuration schema class that matches " + parameter.getType().getCanonicalName(), classNotFoundException);
        }
    } else if (parameterContext.isAnnotated(InjectRevisionListenerHolder.class)) {
        return extensionContext.getStore(NAMESPACE).get(REVISION_LISTENER_HOLDER_KEY, StorageRevisionListenerHolderImpl.class);
    } else {
        throw new ParameterResolutionException("Unknown parametr:" + parameterContext.getParameter());
    }
}
Also used : ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) ExecutorService(java.util.concurrent.ExecutorService) Parameter(java.lang.reflect.Parameter)

Example 3 with ConfigurationAsmGenerator

use of org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator in project ignite-3 by apache.

the class TraversableTreeNodeTest method beforeAll.

/**
 * Before all.
 */
@BeforeAll
public static void beforeAll() {
    cgen = new ConfigurationAsmGenerator();
    cgen.compileRootSchema(ParentConfigurationSchema.class, Map.of(), Map.of());
}
Also used : ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with ConfigurationAsmGenerator

use of org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator 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 5 with ConfigurationAsmGenerator

use of org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator in project ignite-3 by apache.

the class ValidationUtilTest method beforeAll.

/**
 * Before all.
 */
@BeforeAll
public static void beforeAll() {
    cgen = new ConfigurationAsmGenerator();
    cgen.compileRootSchema(ValidatedRootConfigurationSchema.class, Map.of(), Map.of());
}
Also used : ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ConfigurationAsmGenerator (org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator)9 BeforeAll (org.junit.jupiter.api.BeforeAll)4 RootInnerNode (org.apache.ignite.internal.configuration.RootInnerNode)3 Test (org.junit.jupiter.api.Test)3 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 ConverterToMapVisitor (org.apache.ignite.internal.configuration.tree.ConverterToMapVisitor)2 InnerNode (org.apache.ignite.internal.configuration.tree.InnerNode)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 ConfigObject (com.typesafe.config.ConfigObject)1 Field (java.lang.reflect.Field)1 Parameter (java.lang.reflect.Parameter)1 SuperRoot (org.apache.ignite.internal.configuration.SuperRoot)1 ParameterResolutionException (org.junit.jupiter.api.extension.ParameterResolutionException)1