Skip to content

Commit 448b082

Browse files
IGNITE-25789 Fix ConfigurationExtension nodeCreator ignoring key parameter (#7329)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 500299c commit 448b082

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

modules/configuration/src/test/java/org/apache/ignite/internal/configuration/util/ConfigurationUtilTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,10 @@ void testSuperRootWithInternalConfig() {
945945

946946
generator.compileRootSchema(schemaClass, Map.of(), Map.of());
947947

948-
SuperRoot superRoot = new SuperRoot(
949-
s -> new RootInnerNode(schemaKey, generator.instantiateNode(schemaClass))
948+
SuperRoot superRoot = new SuperRoot(s ->
949+
s.equals(schemaKey.key())
950+
? new RootInnerNode(schemaKey, generator.instantiateNode(schemaClass))
951+
: null
950952
);
951953

952954
assertThrows(NoSuchElementException.class, () -> superRoot.construct(schemaKey.key(), null, false));

modules/configuration/src/testFixtures/java/org/apache/ignite/internal/configuration/testframework/ConfigurationExtension.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.lang.reflect.Parameter;
3434
import java.util.ArrayList;
3535
import java.util.List;
36+
import java.util.NoSuchElementException;
3637
import java.util.ServiceLoader;
3738
import java.util.UUID;
3839
import java.util.concurrent.CompletableFuture;
@@ -42,6 +43,7 @@
4243
import java.util.function.Function;
4344
import org.apache.ignite.configuration.ConfigurationModule;
4445
import org.apache.ignite.configuration.RootKey;
46+
import org.apache.ignite.configuration.SuperRootChange;
4547
import org.apache.ignite.configuration.annotation.ConfigurationType;
4648
import org.apache.ignite.configuration.annotation.PolymorphicConfigInstance;
4749
import org.apache.ignite.internal.configuration.DynamicConfiguration;
@@ -245,7 +247,13 @@ private static Object cfgValue(
245247
false
246248
);
247249

248-
SuperRoot superRoot = new SuperRoot(s -> new RootInnerNode(rootKey, cgen.instantiateNode(schemaClass)));
250+
// Accept both "mock" (HOCON convention per @InjectConfiguration docs) and rootKey.key()
251+
// (for patchConfigurationWithDynamicDefaults which uses the real root key).
252+
SuperRoot superRoot = new SuperRoot(s ->
253+
s.equals(rootKey.key()) || s.equals("mock")
254+
? new RootInnerNode(rootKey, cgen.instantiateNode(schemaClass))
255+
: null
256+
);
249257

250258
ConfigObject hoconCfg = ConfigFactory.parseString(annotation.value()).root();
251259

@@ -345,10 +353,20 @@ private static boolean supportsAsConfigurationType(Class<?> type) {
345353

346354
private static void patchWithDynamicDefault(ConfigurationType type, SuperRoot superRoot) {
347355
SuperRootChangeImpl rootChange = new SuperRootChangeImpl(superRoot);
348-
if (type == LOCAL) {
349-
LOCAL_MODULES.forEach(module -> module.patchConfigurationWithDynamicDefaults(rootChange));
350-
} else {
351-
DISTRIBUTED_MODULES.forEach(module -> module.patchConfigurationWithDynamicDefaults(rootChange));
356+
List<ConfigurationModule> modules = type == LOCAL ? LOCAL_MODULES : DISTRIBUTED_MODULES;
357+
modules.forEach(module -> patchIfRootExists(module, rootChange));
358+
}
359+
360+
/**
361+
* Patches configuration with dynamic defaults if the required root exists.
362+
* Modules may try to access roots that don't exist in a test SuperRoot (when using custom rootName),
363+
* in which case the patching is silently skipped.
364+
*/
365+
private static void patchIfRootExists(ConfigurationModule module, SuperRootChange rootChange) {
366+
try {
367+
module.patchConfigurationWithDynamicDefaults(rootChange);
368+
} catch (NoSuchElementException ignored) {
369+
// Module tried to access a root that doesn't exist in this SuperRoot - skip
352370
}
353371
}
354372
}

0 commit comments

Comments
 (0)