use of org.apache.ignite.internal.configuration.tree.TraversableTreeNode in project ignite-3 by apache.
the class ConfigurationUtilTest method findUnsuccessfully.
/**
* Tests that {@link ConfigurationUtil#find(List, TraversableTreeNode, boolean)} throws {@link KeyNotFoundException} when provided with
* a wrong path.
*/
@Test
public void findUnsuccessfully() {
InnerNode parentNode = newNodeInstance(ParentConfigurationSchema.class);
ParentChange parentChange = (ParentChange) parentNode;
assertThrows(KeyNotFoundException.class, () -> ConfigurationUtil.find(List.of("elements", "name", "child"), parentNode, true));
parentChange.changeElements(elements -> elements.createOrUpdate("name", element -> {
}));
assertThrows(KeyNotFoundException.class, () -> ConfigurationUtil.find(List.of("elements", "name", "child", "str0"), parentNode, true));
((NamedElementChange) parentChange.elements().get("name")).changeChild(child -> child.changeStr("value"));
assertThrows(KeyNotFoundException.class, () -> ConfigurationUtil.find(List.of("elements", "name", "child", "str", "foo"), parentNode, true));
}
use of org.apache.ignite.internal.configuration.tree.TraversableTreeNode in project ignite-3 by apache.
the class ConfigurationNode method refreshValue.
/**
* Returns latest value of the configuration or throws exception.
*
* @return Latest configuration value.
* @throws NoSuchElementException If configuration is a part of already deleted named list configuration entry.
* @throws ConfigurationListenOnlyException If there was an attempt to get or update a property value in {@link #listenOnly listen-only}
* mode.
*/
protected final VIEWT refreshValue() throws NoSuchElementException {
TraversableTreeNode newRootNode = changer.getRootNode(rootKey);
TraversableTreeNode oldRootNode = cachedRootNode;
// 'invalid' and 'val' visibility is guaranteed by the 'cachedRootNode' volatile read
if (invalid) {
throw noSuchElementException();
} else if (listenOnly) {
throw listenOnlyException();
}
if (oldRootNode == newRootNode) {
return val;
}
try {
VIEWT newVal = ConfigurationUtil.find(keys.subList(1, keys.size()), newRootNode, true);
synchronized (this) {
if (cachedRootNode == oldRootNode) {
beforeRefreshValue(newVal, val);
val = newVal;
cachedRootNode = newRootNode;
return newVal;
} else {
if (invalid) {
throw noSuchElementException();
}
return val;
}
}
} catch (KeyNotFoundException e) {
synchronized (this) {
invalid = true;
cachedRootNode = newRootNode;
}
throw noSuchElementException();
}
}
use of org.apache.ignite.internal.configuration.tree.TraversableTreeNode 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.TraversableTreeNode 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));
}
Aggregations