-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(10891): Provide a configuration item for the maximum number of p…
…ush retries, instead of directly hardcoding it to 50 times in the code.
Showing
6 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
config/src/main/java/com/alibaba/nacos/config/server/configuration/ConfigCommonConfigs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.config.server.configuration; | ||
|
||
import com.alibaba.nacos.common.event.ServerConfigChangeEvent; | ||
import com.alibaba.nacos.common.notify.Event; | ||
import com.alibaba.nacos.common.notify.NotifyCenter; | ||
import com.alibaba.nacos.common.notify.listener.Subscriber; | ||
import com.alibaba.nacos.sys.env.EnvUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Nacos config common configs. | ||
* | ||
* @author blake.qiu | ||
*/ | ||
@Configuration | ||
public class ConfigCommonConfigs extends Subscriber<ServerConfigChangeEvent> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCommonConfigs.class); | ||
|
||
@Value("${nacos.config.push.maxRetryTime:50}") | ||
private int maxPushRetryTimes; | ||
|
||
public ConfigCommonConfigs() { | ||
NotifyCenter.registerSubscriber(this); | ||
} | ||
|
||
public int getMaxPushRetryTimes() { | ||
return maxPushRetryTimes; | ||
} | ||
|
||
public void setMaxPushRetryTimes(int maxPushRetryTimes) { | ||
this.maxPushRetryTimes = maxPushRetryTimes; | ||
} | ||
|
||
@Override | ||
public void onEvent(ServerConfigChangeEvent event) { | ||
try { | ||
maxPushRetryTimes = EnvUtil.getProperty("nacos.config.push.maxRetryTime", Integer.class, 50); | ||
} catch (Exception e) { | ||
LOGGER.warn("Upgrade nacos-config common configs from env failed, use old value", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<? extends Event> subscribeType() { | ||
return ServerConfigChangeEvent.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../src/test/java/com/alibaba/nacos/config/server/configuration/ConfigCommonConfigsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 1999-2020 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.config.server.configuration; | ||
|
||
import com.alibaba.nacos.common.event.ServerConfigChangeEvent; | ||
import com.alibaba.nacos.sys.env.EnvUtil; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.InjectMocks; | ||
import org.springframework.mock.env.MockEnvironment; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Nacos config common configs test. | ||
* | ||
* @author blake.qiu | ||
*/ | ||
public class ConfigCommonConfigsTest { | ||
|
||
@InjectMocks | ||
private ConfigCommonConfigs commonConfigs; | ||
|
||
private MockEnvironment environment; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
environment = new MockEnvironment(); | ||
EnvUtil.setEnvironment(environment); | ||
commonConfigs = new ConfigCommonConfigs(); | ||
} | ||
|
||
@Test | ||
public void testUpgradeFromEvent() { | ||
environment.setProperty("nacos.config.push.maxRetryTime", "100"); | ||
commonConfigs.onEvent(ServerConfigChangeEvent.newEvent()); | ||
assertEquals(100, commonConfigs.getMaxPushRetryTimes()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters