From 38b8d060d327dd64c78fc8f0c9b04d14db9044d2 Mon Sep 17 00:00:00 2001 From: liangtianyu <124244236@qq.com> Date: Sat, 17 Feb 2024 13:38:01 +0800 Subject: [PATCH 1/2] [ISSUE #11718] Fix ErrorCode have the same code --- .../alibaba/nacos/api/model/v2/ErrorCode.java | 2 +- .../nacos/api/model/v2/ErrorCodeTest.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java diff --git a/api/src/main/java/com/alibaba/nacos/api/model/v2/ErrorCode.java b/api/src/main/java/com/alibaba/nacos/api/model/v2/ErrorCode.java index b86897c116e..53b4c35735f 100644 --- a/api/src/main/java/com/alibaba/nacos/api/model/v2/ErrorCode.java +++ b/api/src/main/java/com/alibaba/nacos/api/model/v2/ErrorCode.java @@ -178,7 +178,7 @@ public enum ErrorCode { /** * node down failure. */ - NODE_DOWN_FAILURE(23001, "node down failure"), + NODE_DOWN_FAILURE(23002, "node down failure"), /** * server error. diff --git a/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java b/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java new file mode 100644 index 00000000000..e11e133170d --- /dev/null +++ b/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java @@ -0,0 +1,24 @@ +package com.alibaba.nacos.api.model.v2; + +import static org.junit.Assert.assertEquals; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; + +public class ErrorCodeTest { + @Test + public void testCodeNotSame() { + Class errorCodeClass = ErrorCode.class; + + ErrorCode[] errorCodes = errorCodeClass.getEnumConstants(); + Set codeSet = new HashSet(errorCodes.length); + + for(ErrorCode errorCode : errorCodes) { + codeSet.add(errorCode.getCode()); + } + + assertEquals(errorCodes.length, codeSet.size()); + } +} From ee48cc3e915518d80567729bbcc9fb53664d3a25 Mon Sep 17 00:00:00 2001 From: liangtianyu <124244236@qq.com> Date: Tue, 20 Feb 2024 11:36:36 +0800 Subject: [PATCH 2/2] Fix code style. --- .../nacos/api/model/v2/ErrorCodeTest.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java b/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java index e11e133170d..3c61881135f 100644 --- a/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java +++ b/api/src/test/java/com/alibaba/nacos/api/model/v2/ErrorCodeTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 1999-2021 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.api.model.v2; import static org.junit.Assert.assertEquals; @@ -8,15 +24,15 @@ import org.junit.Test; public class ErrorCodeTest { - @Test + @Test public void testCodeNotSame() { Class errorCodeClass = ErrorCode.class; ErrorCode[] errorCodes = errorCodeClass.getEnumConstants(); Set codeSet = new HashSet(errorCodes.length); - for(ErrorCode errorCode : errorCodes) { - codeSet.add(errorCode.getCode()); + for (ErrorCode errorCode : errorCodes) { + codeSet.add(errorCode.getCode()); } assertEquals(errorCodes.length, codeSet.size());