Skip to content

Commit 72266fc

Browse files
authored
Improve naming module unit test coverage (#15251)
* Improve naming model and paramcheck unit coverage Add phase 1 unit coverage for naming HTTP parameter extractors, form defaults, legacy POJO conversions, and deprecated VO mapping. Assisted-by: Claude Code * Improve naming web filter unit coverage Add phase 2 coverage for naming filter registration, service name normalization, traffic revision, distro tag generation, and distro filter routing branches. Assisted-by: Claude Code * Improve naming client service unit coverage Add phase 3 coverage for ClientServiceImpl client detail, publisher/subscriber list, compatibility response, filtering, and responsible server query branches. Assisted-by: Claude Code * Improve naming core operator coverage Add phase 4 coverage for service and instance operators, service storage cache rebuilding, and distro mapping branches. Assisted-by: Claude Code * Improve naming operator utility coverage Add phase 5 coverage for OperatorV2 metrics delegation and ServiceUtil paging, filtering, and protection branches. Assisted-by: Claude Code * Improve naming instance metadata coverage Add phase 6 coverage for instance metadata processor registration, apply, error, snapshot, and group paths. Assisted-by: Claude Code * Improve naming metrics collector coverage Add phase 7 coverage for naming subscriber/publisher and service event queue metrics collectors. Assisted-by: Claude Code * Improve naming metadata snapshot coverage Add phase 8 coverage for metadata snapshot write, read, and checksum failure paths. Assisted-by: Claude Code * Improve naming fuzzy watch handler coverage Add phase 9 coverage for fuzzy watch request handler success, failure, limit, cancel, and invalid request paths. Assisted-by: Claude Code * Improve naming selector coverage Add phase 10 coverage for label selector selection paths and selector manager guard/fallback branches. Assisted-by: Claude Code * Improve naming CMDB selector context coverage Add phase 11 coverage for CMDB selector context builder consumer, provider, null-provider, and type paths. Assisted-by: Claude Code * Improve naming performance logger coverage Add phase 12 coverage for performance logger metric refresh, collection, distro logging, and rolling metric reset paths. Assisted-by: Claude Code * Improve naming subscriber aggregation coverage Add phase 13 tests for remote subscriber aggregation success and fallback paths. Assisted-by: Claude Code * Improve naming push task coverage Add phase 14 coverage for fuzzy watch change notify callbacks and push pending task metrics collection. Assisted-by: Claude Code * Improve naming persistent snapshot coverage Add phase 15 coverage for persistent client snapshot dump/load, sync data updates, and stale client cleanup. Assisted-by: Claude Code * Improve naming support utility coverage Add phase 16 coverage for response exception handling, dynamic topN meter refresh, and batch read/write DTOs. Assisted-by: Claude Code * Improve naming switch snapshot coverage Add phase 17 coverage for switch domain snapshot write, load, checksum failure, and snapshot tags. Assisted-by: Claude Code * Improve naming instance utility coverage Add phase 18 coverage for health-check instance state and InstanceUtil extended metadata branches. Assisted-by: Claude Code * Improve naming metadata utility coverage Add phase 19 coverage for expired metadata info and metadata operation submit paths. Assisted-by: Claude Code * Improve naming logger utility coverage Add phase 20 coverage for naming log level switch paths. Assisted-by: Claude Code * Improve naming fuzzy watch delay engine coverage Add phase 21 coverage for fuzzy watch push delay engine task processing and task keys. Assisted-by: Claude Code * Improve naming service metadata processor coverage Add phase 22 coverage for service metadata merge and failure paths. Assisted-by: Claude Code * Improve naming event publisher coverage Add phase 23 coverage for subscriber shortcuts, notify branches, and publisher guard paths. Assisted-by: Claude Code * Improve naming filter and local subscriber coverage Add phase 24 coverage for naming enablement filter modes and local subscriber delegation. Assisted-by: Claude Code * Improve naming metrics monitor coverage Add phase 25 coverage for metrics counters and batch decrement paths. Assisted-by: Claude Code * Improve naming readiness and batch data coverage Add phase 26 coverage for readiness checks and batch instance data accessors. Assisted-by: Claude Code * Improve naming fuzzy watch sync task coverage Add phase 27 coverage for fuzzy watch sync notify task merge paths. Assisted-by: Claude Code * Improve naming instance metadata snapshot coverage Add phase 28 coverage for instance metadata snapshot dump and load paths. Assisted-by: Claude Code * Improve naming lightweight component coverage Add phase 29 coverage for service name views, request registry payloads, and no-op health checks. Assisted-by: Claude Code * Improve naming registry and subscriber coverage Add phase 30 coverage for response registry, datum creation, persistent IP-port factory, verify info, and subscribe manager branches. Assisted-by: Claude Code * Improve naming index manager coverage Add phase 31 coverage for global config defaults, client service index edge paths, and persistent client manager helpers. Assisted-by: Claude Code * Improve naming cleaner shutdown coverage Add phase 32 coverage for expired metadata cleanup branches and graceful shutdown listener destroy paths. Assisted-by: Claude Code * Improve naming service helper coverage Add phase 33 coverage for distro retry handling, service metadata equality, client operation batch routing, and health check extension helpers. Assisted-by: Claude Code * Improve naming client manager coverage Add phase 34 coverage for ephemeral IP-port factory, connection client manager edge paths, and subscriber push service branches. Assisted-by: Claude Code * Improve naming client and selector coverage Add phase 35 coverage for IP-port client branches, selector initialization failures, and service value-object behavior. Assisted-by: Claude Code * Improve naming health check common coverage Add phase 36 coverage for health check success, pre-threshold, and missing-instance branches. Assisted-by: Claude Code * Improve naming HTTP health check coverage Add phase 37 coverage for HTTP health check early exits, failure handling, and callback branches. Assisted-by: Claude Code * Improve naming instance controller coverage Add phase 38 coverage for instance metadata deletion, partial updates, and healthy-only listing. Assisted-by: Claude Code * Improve naming service controller coverage Add phase 39 coverage for service list-with-instances and selector parsing branches. Assisted-by: Claude Code * Improve naming client controller coverage Add phase 40 coverage for client subscription, distro, and missing-client branches. Assisted-by: Claude Code * Improve naming distro request handler coverage Add phase 41 coverage for distro verify, change, and exception handling branches. Assisted-by: Claude Code * Improve naming metadata manager coverage Add phase 42 coverage for metadata snapshots, missing services, and disconnect expiry branches. Assisted-by: Claude Code * Improve naming catalog service coverage Add phase 43 coverage for catalog cluster metadata, list-all, ignore-empty, and paging branches. Assisted-by: Claude Code * Improve naming expression interpreter coverage Add phase 44 coverage for selector expression parsing and syntax validation branches. Assisted-by: Claude Code * Improve naming service name filter coverage Add phase 45 coverage for service name filter grouping, bad request, and exception branches. Assisted-by: Claude Code * Improve naming distro utils coverage Add phase 46 coverage for non-IP-port client default checksum and hash branches. Assisted-by: Claude Code * Improve naming health operator coverage Add phase 47 coverage for persistent health status validation and early return branches. Assisted-by: Claude Code * Improve naming client beat processor coverage Add phase 48 coverage for beat refresh and health recovery branches. Assisted-by: Claude Code * Improve naming snapshot operation coverage Add phase 49 coverage for snapshot save success and failure callbacks. Assisted-by: Claude Code * Improve naming global executor coverage Add phase 50 coverage for global executor scheduling wrappers. Assisted-by: Claude Code * Improve naming abstract client coverage Add phase 51 coverage for batch sync, remove, and release branches. Assisted-by: Claude Code * Improve naming persistent operation coverage Add phase 52 coverage for persistent operation error and deregister branches. Assisted-by: Claude Code * Improve naming fuzzy watch coverage Add phase 53 coverage for fuzzy watch limits, init, and context cleanup branches. Assisted-by: Claude Code * Improve naming performance logger coverage Add phase 54 coverage for performance logger scheduling. Assisted-by: Claude Code * Improve naming switch domain coverage Add phase 55 coverage for switch domain direct accessors. Assisted-by: Claude Code * Improve naming ephemeral operation coverage Add phase 56 coverage for persistent batch registration and deregister edge cases. Assisted-by: Claude Code * Improve naming distro processor coverage Add phase 57 coverage for DistroClientDataProcessor edge cases. Assisted-by: Claude Code * Improve naming health operator coverage Add phase 58 coverage for unavailable health checker handling. Assisted-by: Claude Code * Improve naming operator coverage Add phase 59 coverage for operator controllers and service query defaults. Assisted-by: Claude Code * Improve naming event publisher coverage Add phase 60 coverage for interrupted event queue handling. Assisted-by: Claude Code * Improve naming instance patch coverage Add phase 61 coverage for InstancePatchObject healthy accessors. Assisted-by: Claude Code * Improve naming health check reactor coverage Add phase 62 coverage for beat scheduling and cancel failure handling. Assisted-by: Claude Code * Improve naming ephemeral client manager coverage Add phase 63 coverage for client manager boundary paths. Assisted-by: Claude Code * Improve naming push coverage * Improve naming beat check interceptor coverage * Improve naming health check extension coverage * Improve naming push task coverage * Improve naming web form coverage * Improve naming health check common coverage * Improve naming utility coverage * Improve naming distro callback coverage * Improve naming expired client cleaner coverage Assisted-by: Claude Code * Improve naming defensive branch coverage Assisted-by: Claude Code * Improve naming push delay task coverage Assisted-by: Claude Code * Improve naming small branch coverage Assisted-by: Claude Code * Improve naming metadata branch coverage Assisted-by: Claude Code * Improve naming utility branch coverage Assisted-by: Claude Code * Improve naming event coverage Assisted-by: Claude Code
1 parent c326892 commit 72266fc

121 files changed

Lines changed: 9793 additions & 22 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 1999-2026 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.nacos.naming;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.mockito.MockedStatic;
21+
import org.mockito.Mockito;
22+
import org.springframework.boot.SpringApplication;
23+
24+
class NamingAppTest {
25+
26+
@Test
27+
void testMainStartsSpringApplication() {
28+
String[] args = new String[] {"--server.port=0"};
29+
30+
try (MockedStatic<SpringApplication> mockedSpringApplication =
31+
Mockito.mockStatic(SpringApplication.class)) {
32+
NamingApp.main(args);
33+
34+
mockedSpringApplication.verify(() -> SpringApplication.run(NamingApp.class, args));
35+
}
36+
}
37+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 1999-2026 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.nacos.naming.cluster;
18+
19+
import com.alibaba.nacos.api.common.Constants;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.ExtendWith;
23+
import org.mockito.Mock;
24+
import org.mockito.junit.jupiter.MockitoExtension;
25+
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertFalse;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
29+
import static org.mockito.Mockito.when;
30+
31+
@ExtendWith(MockitoExtension.class)
32+
class NamingReadinessCheckServiceTest {
33+
34+
@Mock
35+
private ServerStatusManager serverStatusManager;
36+
37+
private NamingReadinessCheckService readinessCheckService;
38+
39+
@BeforeEach
40+
void setUp() {
41+
readinessCheckService = new NamingReadinessCheckService(serverStatusManager);
42+
}
43+
44+
@Test
45+
void testReadinessWhenServerStatusUp() {
46+
when(serverStatusManager.getServerStatus()).thenReturn(ServerStatus.UP);
47+
48+
assertTrue(readinessCheckService.readiness());
49+
}
50+
51+
@Test
52+
void testReadinessWhenServerStatusNotUp() {
53+
when(serverStatusManager.getServerStatus()).thenReturn(ServerStatus.DOWN);
54+
55+
assertFalse(readinessCheckService.readiness());
56+
}
57+
58+
@Test
59+
void testReadinessWhenGetServerStatusThrowsException() {
60+
when(serverStatusManager.getServerStatus()).thenThrow(new RuntimeException("failed"));
61+
62+
assertFalse(readinessCheckService.readiness());
63+
}
64+
65+
@Test
66+
void testGetModuleName() {
67+
assertEquals(Constants.Naming.NAMING_MODULE, readinessCheckService.getModuleName());
68+
}
69+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 1999-2026 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.nacos.naming.cluster.remote.request;
18+
19+
import com.alibaba.nacos.api.remote.Payload;
20+
import com.alibaba.nacos.core.cluster.remote.request.AbstractClusterRequest;
21+
import org.junit.jupiter.api.Test;
22+
23+
import java.util.Set;
24+
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertNotNull;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
29+
class RequestRegistryTest {
30+
31+
@Test
32+
void testConstructor() {
33+
assertNotNull(new RequestRegistry());
34+
}
35+
36+
@Test
37+
void testGetPayloads() {
38+
Set<Class<? extends Payload>> payloads = RequestRegistry.getPayloads();
39+
40+
assertEquals(2, payloads.size());
41+
assertTrue(payloads.contains(AbstractClusterRequest.class));
42+
assertTrue(payloads.contains(DistroDataRequest.class));
43+
}
44+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 1999-2026 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.nacos.naming.cluster.remote.response;
18+
19+
import com.alibaba.nacos.api.remote.Payload;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.util.Set;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
28+
class ResponseRegistryTest {
29+
30+
@Test
31+
void testConstructor() {
32+
assertNotNull(new ResponseRegistry());
33+
}
34+
35+
@Test
36+
void testGetPayloads() {
37+
Set<Class<? extends Payload>> payloads = ResponseRegistry.getPayloads();
38+
39+
assertEquals(1, payloads.size());
40+
assertTrue(payloads.contains(DistroDataResponse.class));
41+
}
42+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 1999-2026 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.nacos.naming.config;
18+
19+
import com.alibaba.nacos.naming.NamingApp;
20+
import com.alibaba.nacos.sys.env.EnvUtil;
21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
24+
import org.springframework.test.util.ReflectionTestUtils;
25+
26+
import java.util.Collections;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertFalse;
30+
import static org.junit.jupiter.api.Assertions.assertTrue;
31+
32+
class NamingEnabledFilterTest {
33+
34+
private NamingEnabledFilter filter;
35+
36+
private String originalFunctionMode;
37+
38+
@BeforeEach
39+
void setUp() {
40+
filter = new NamingEnabledFilter();
41+
originalFunctionMode =
42+
(String) ReflectionTestUtils.getField(EnvUtil.class, "functionModeType");
43+
}
44+
45+
@AfterEach
46+
void tearDown() {
47+
ReflectionTestUtils.setField(EnvUtil.class, "functionModeType", originalFunctionMode);
48+
}
49+
50+
@Test
51+
void testGetResponsiblePackagePrefix() {
52+
assertEquals(NamingApp.class.getPackage().getName(),
53+
filter.getResponsiblePackagePrefix());
54+
}
55+
56+
@Test
57+
void testIsExcludedWhenFunctionModeIsEmpty() {
58+
ReflectionTestUtils.setField(EnvUtil.class, "functionModeType", "");
59+
60+
assertFalse(filter.isExcluded("com.alibaba.nacos.naming.Test",
61+
Collections.emptySet()));
62+
}
63+
64+
@Test
65+
void testIsExcludedWhenFunctionModeAllowsNaming() {
66+
String[] functionModes = new String[] {EnvUtil.FUNCTION_MODE_NAMING,
67+
EnvUtil.FUNCTION_MODE_MICROSERVICE, EnvUtil.FUNCTION_MODE_AI};
68+
for (String functionMode : functionModes) {
69+
ReflectionTestUtils.setField(EnvUtil.class, "functionModeType", functionMode);
70+
71+
assertFalse(filter.isExcluded("com.alibaba.nacos.naming.Test",
72+
Collections.emptySet()));
73+
}
74+
}
75+
76+
@Test
77+
void testIsExcludedWhenFunctionModeDisablesNaming() {
78+
ReflectionTestUtils.setField(EnvUtil.class, "functionModeType",
79+
EnvUtil.FUNCTION_MODE_CONFIG);
80+
81+
assertTrue(filter.isExcluded("com.alibaba.nacos.naming.Test", Collections.emptySet()));
82+
}
83+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 1999-2026 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.nacos.naming.consistency;
18+
19+
import com.alibaba.nacos.naming.pojo.Record;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertSame;
24+
import static org.mockito.Mockito.mock;
25+
26+
class DatumTest {
27+
28+
@Test
29+
@SuppressWarnings("unchecked")
30+
void testCreateDatum() {
31+
Record value = mock(Record.class);
32+
33+
Datum<Record> datum = Datum.createDatum("datum-key", value);
34+
35+
assertEquals("datum-key", datum.key);
36+
assertSame(value, datum.value);
37+
assertEquals(0L, datum.timestamp.get());
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 1999-2026 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.nacos.naming.consistency;
18+
19+
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
26+
class KeyBuilderTest {
27+
28+
@Test
29+
void testBuildKeys() {
30+
new KeyBuilder();
31+
32+
assertEquals("com.alibaba.nacos.naming.domains.meta.namespace##group@@service",
33+
KeyBuilder.buildServiceMetaKey("namespace", "group@@service"));
34+
assertEquals("com.alibaba.nacos.naming.domains.meta." + UtilsAndCommons.SWITCH_DOMAIN_NAME,
35+
KeyBuilder.getSwitchDomainKey());
36+
assertTrue(KeyBuilder.matchSwitchKey(KeyBuilder.getSwitchDomainKey()));
37+
assertFalse(KeyBuilder.matchSwitchKey("other"));
38+
}
39+
}

0 commit comments

Comments
 (0)