|
33 | 33 | import java.lang.reflect.Parameter; |
34 | 34 | import java.util.ArrayList; |
35 | 35 | import java.util.List; |
| 36 | +import java.util.NoSuchElementException; |
36 | 37 | import java.util.ServiceLoader; |
37 | 38 | import java.util.UUID; |
38 | 39 | import java.util.concurrent.CompletableFuture; |
|
42 | 43 | import java.util.function.Function; |
43 | 44 | import org.apache.ignite.configuration.ConfigurationModule; |
44 | 45 | import org.apache.ignite.configuration.RootKey; |
| 46 | +import org.apache.ignite.configuration.SuperRootChange; |
45 | 47 | import org.apache.ignite.configuration.annotation.ConfigurationType; |
46 | 48 | import org.apache.ignite.configuration.annotation.PolymorphicConfigInstance; |
47 | 49 | import org.apache.ignite.internal.configuration.DynamicConfiguration; |
@@ -245,7 +247,13 @@ private static Object cfgValue( |
245 | 247 | false |
246 | 248 | ); |
247 | 249 |
|
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 | + ); |
249 | 257 |
|
250 | 258 | ConfigObject hoconCfg = ConfigFactory.parseString(annotation.value()).root(); |
251 | 259 |
|
@@ -345,10 +353,20 @@ private static boolean supportsAsConfigurationType(Class<?> type) { |
345 | 353 |
|
346 | 354 | private static void patchWithDynamicDefault(ConfigurationType type, SuperRoot superRoot) { |
347 | 355 | 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 |
352 | 370 | } |
353 | 371 | } |
354 | 372 | } |
0 commit comments