diff --git a/core/src/test/java/com/alibaba/nacos/core/ability/config/AbilityConfigsTest.java b/core/src/test/java/com/alibaba/nacos/core/ability/config/AbilityConfigsTest.java index 86e081f44..8ae52fd6d 100644 --- a/core/src/test/java/com/alibaba/nacos/core/ability/config/AbilityConfigsTest.java +++ b/core/src/test/java/com/alibaba/nacos/core/ability/config/AbilityConfigsTest.java @@ -17,6 +17,8 @@ package com.alibaba.nacos.core.ability.config; import com.alibaba.nacos.api.ability.constant.AbilityKey; +import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry; +import com.alibaba.nacos.api.ability.register.impl.ServerAbilities; import com.alibaba.nacos.common.ability.handler.HandlerMapping; import com.alibaba.nacos.common.event.ServerConfigChangeEvent; import com.alibaba.nacos.core.ability.TestServerAbilityControlManager; @@ -27,6 +29,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.mock.env.MockEnvironment; +import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; @@ -45,6 +48,8 @@ public class AbilityConfigsTest { private ServerAbilityControlManager serverAbilityControlManager; + private Map currentAbilities; + @Before public void setUp() throws Exception { environment = new MockEnvironment(); @@ -68,6 +73,32 @@ public class AbilityConfigsTest { this.serverAbilityControlManager = serverAbilityControlManager; } + + public void fill() throws NoSuchFieldException, IllegalAccessException { + Field instanceField = ServerAbilities.class.getDeclaredField("INSTANCE"); + Field abilitiesField = AbstractAbilityRegistry.class.getDeclaredField("supportedAbilities"); + abilitiesField.setAccessible(true); + instanceField.setAccessible(true); + ServerAbilities serverAbilities = (ServerAbilities) instanceField.get(ServerAbilities.class); + currentAbilities = (Map) abilitiesField.get(serverAbilities); + currentAbilities.put(AbilityKey.TEST_1, true); + currentAbilities.put(AbilityKey.TEST_2, true); + } + + @Test + public void testLoadAbilities() throws NoSuchFieldException, IllegalAccessException, InterruptedException { + environment.setProperty(AbilityConfigs.PREFIX + AbilityKey.TEST_1.getName(), Boolean.TRUE.toString()); + environment.setProperty(AbilityConfigs.PREFIX + AbilityKey.TEST_2.getName(), Boolean.FALSE.toString()); + // test load + fill(); + ServerAbilityControlManager manager = new ServerAbilityControlManager(); + // config has higher priority + Assert.assertTrue(manager.isCurrentNodeAbilityRunning(AbilityKey.TEST_1)); + Assert.assertFalse(manager.isCurrentNodeAbilityRunning(AbilityKey.TEST_2)); + // clear + currentAbilities.clear(); + } + @Test public void testInit() { Assert.assertTrue(serverAbilityControlManager.isCurrentNodeAbilityRunning(AbilityKey.TEST_1));