use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.
the class DynamicConfiguration method change.
/**
* {@inheritDoc}
*/
@Override
public final CompletableFuture<Void> change(Consumer<CHANGET> change) {
Objects.requireNonNull(change, "Configuration consumer cannot be null.");
if (listenOnly) {
throw listenOnlyException();
}
assert keys instanceof RandomAccess;
ConfigurationSource src = new ConfigurationSource() {
/**
* Current index in the {@code keys}.
*/
private int level = 0;
/**
* {@inheritDoc}
*/
@Override
public void descend(ConstructableTreeNode node) {
if (level == keys.size()) {
if (node instanceof InnerNode) {
// To support polymorphic configuration.
change.accept(((InnerNode) node).specificNode());
} else {
// To support namedList configuration.
change.accept((CHANGET) node);
}
} else {
node.construct(keys.get(level++), this, true);
}
}
/**
* {@inheritDoc}
*/
@Override
public void reset() {
level = 0;
}
};
// Use resulting tree as update request for the storage.
return changer.change(src);
}
use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.
the class ConfigurationUtilTest method fillFromPrefixMapSuccessfullyWithRemove.
/**
* Tests that patching of configuration node with a prefix map works fine when prefix map is valid.
*/
@Test
public void fillFromPrefixMapSuccessfullyWithRemove() {
InnerNode parentNode = newNodeInstance(ParentConfigurationSchema.class);
ParentChange parentChange = (ParentChange) parentNode;
parentChange.changeElements(elements -> elements.createOrUpdate("name", element -> element.changeChild(child -> {
})));
UUID internalId = ((InnerNode) ((ParentView) parentNode).elements().get("name")).internalId();
ConfigurationUtil.fillFromPrefixMap(parentNode, Map.of("elements", singletonMap(internalId.toString(), null)));
assertNull(parentChange.elements().get("node"));
}
use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.
the class ConfigurationUtilTest method findNulls.
/**
* Tests that {@link ConfigurationUtil#find(List, TraversableTreeNode, boolean)} returns null when path points to nonexistent named list
* element.
*/
@Test
public void findNulls() {
InnerNode parentNode = newNodeInstance(ParentConfigurationSchema.class);
ParentChange parentChange = (ParentChange) parentNode;
assertNull(ConfigurationUtil.find(List.of("elements", "name"), parentNode, true));
parentChange.changeElements(elements -> elements.createOrUpdate("name", element -> {
}));
assertNull(ConfigurationUtil.find(List.of("elements", "name", "child", "str"), parentNode, true));
}
use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.
the class ConfigurationUtilTest method fillFromPrefixMapSuccessfully.
/**
* Tests that patching of configuration node with a prefix map works fine when prefix map is valid.
*/
@Test
public void fillFromPrefixMapSuccessfully() {
InnerNode parentNode = newNodeInstance(ParentConfigurationSchema.class);
ParentChange parentChange = (ParentChange) parentNode;
ConfigurationUtil.fillFromPrefixMap(parentNode, Map.of("elements", Map.of("01234567-89ab-cdef-0123-456789abcdef", Map.of("child", Map.of("str", "value2"), ORDER_IDX, 1, NAME, "name2"), "12345678-9abc-def0-1234-56789abcdef0", Map.of("child", Map.of("str", "value1"), ORDER_IDX, 0, NAME, "name1"))));
assertEquals("value1", parentChange.elements().get("name1").child().str());
assertEquals("value2", parentChange.elements().get("name2").child().str());
}
use of org.apache.ignite.internal.configuration.tree.InnerNode in project ignite-3 by apache.
the class ConfigurationUtilTest method testFindInternalConfigs.
@Test
void testFindInternalConfigs() {
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);
// Check that no internal configuration will be found.
assertThrows(KeyNotFoundException.class, () -> find(List.of("str2"), innerNode, false));
assertThrows(KeyNotFoundException.class, () -> find(List.of("str3"), innerNode, false));
assertThrows(KeyNotFoundException.class, () -> find(List.of("subCfg1"), innerNode, false));
assertThrows(KeyNotFoundException.class, () -> find(List.of("subCfg", "str01"), innerNode, false));
assertThrows(KeyNotFoundException.class, () -> find(List.of("subCfg", "str02"), innerNode, false));
// Check that internal configuration will be found.
assertNull(find(List.of("str2"), innerNode, true));
assertEquals("foo", find(List.of("str3"), innerNode, true));
assertNotNull(find(List.of("subCfg1"), innerNode, true));
assertEquals("foo", find(List.of("subCfg", "str01"), innerNode, true));
assertEquals("foo", find(List.of("subCfg", "str02"), innerNode, true));
}
Aggregations