Commit e28b284
committed
Refactor: Replace Whitebox with standard reflection in Analyzer, Server-Cluster-Plugin and Receiver & Fetcher Plugins.
### [Analyzer]
**General Refactoring (`agent-analyzer`, `log-analyzer`):**
- Systematically eliminated `Whitebox` usages across various analyzer tests.
- Migrated internal state manipulations to standard Java Reflection API (`Field.setAccessible()` etc.), ensuring proper checked exception handling to prevent polluting test method signatures.
**`AnalyzerTest` (meter-analyzer):**
- Replaced `Whitebox` with `MockedStatic` (using Mockito) to safely inject and mock the `MetricsStreamProcessor` singleton.
- Added explicit `.close()` calls in the `@AfterEach` (or `tearDownEach`) lifecycle methods to properly release the static mocks and prevent resource leaks or interference between tests.
**`K8sTagTest` (meter-analyzer):**
- Since `KubernetesPods` and `KubernetesServices` are implemented as Enum singletons, mocking the entire objects was problematic. To resolve this:
- Handled the internal lazy-loading `LoadingCache` instances by injecting Mock objects directly into these fields via standard reflection.
- Fixed potential `NullPointerException`s during cache misses by explicitly stubbing the mocked caches to return `Optional.empty()` or empty collections for non-matching keys, ensuring better test isolation and stability.
### [Server-Cluster-Plugin]
- Replaced all `Whitebox.setInternalState()` and `getInternalState()` usages with standard `java.lang.reflect.Field` to inject internal dependencies (e.g., `client`, `config`, `loadedProvider`, `healthChecker`) into Coordinators and Providers across all 5 cluster plugins (Zookeeper, Nacos, Etcd, Kubernetes, Consul).
- **Handled Checked Exceptions Safely:** Since standard Reflection APIs strictly throw checked exceptions (`NoSuchFieldException`, `IllegalAccessException`), explicitly wrapped them in `RuntimeException` within `try-catch` blocks. This successfully removed the PowerMock dependency while preserving the existing test lifecycle method signatures (like `@BeforeEach` or `@Test`) without adding unnecessary `throws` declarations.
### [Receiver & Fetcher Plugins]
** General Refactoring (`server-receiver-plugin`, `server-fetcher-plugin`):**
- Systematically removed `Whitebox` dependencies and migrated to standard Java Reflection API.
- Centralized reflection logic within `try-catch` blocks to wrap checked exceptions into `RuntimeException`, ensuring no changes were required to existing test method signatures.
`ZabbixMetricsTest` & `ZabbixBaseTest`:
- Static Mock Lifecycle Management: Replaced manual `Whitebox` field manipulation of the `MetricsStreamProcessor` singleton with `MockedStatic`.
- Implemented strict `.close()` logic within the `@AfterEach` lifecycle to prevent memory leaks and resource conflicts, which is particularly critical for stability in newer JVM environments.
- Resolved a legacy `NullPointerException` by combining `MockedStatic` with a `Mockito.spy()` of the actual processor instance, ensuring a safe and stateful mock return.
`TelegrafMetricsTest`:
- Clean Mocking: Eliminated redundant `CoreModule` mocks and unused stubbings, resolving `UnnecessaryStubbingException` and improving test performance
- Modernization: Fixed anti-patterns (spying on class literals) and aligned with JUnit 5 best practices.
`ClusterManagerMetricsAdapterTest`:
- Static State Isolation: Addressed potential flaky test behavior by explicitly clearing shared static maps (e.g., `initialized` flag in `FieldsHelper`) during `@BeforeEach`.
- This ensures complete test isolation by preventing state leakage between test cases, leading to a more deterministic and reliable test suite.
`CiliumNodeManagerTest` & Others:
- Successfully migrated internal state injections(remoteInstances and allNodes) to standard reflection, maintaining the original testing intent while removing the PowerMock requirement.1 parent 95b6a19 commit e28b284
File tree
23 files changed
+332
-134
lines changed- docs/en/changes
- oap-server
- analyzer
- agent-analyzer/src/test/java/org/apache/skywalking/oap/server/analyzer/provider
- meter/process
- trace
- log-analyzer/src/test/java/org/apache/skywalking/oap/log/analyzer/dsl
- meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/dsl
- server-cluster-plugin
- cluster-consul-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/consul
- cluster-etcd-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/etcd
- cluster-kubernetes-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/kubernetes
- cluster-nacos-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/nacos
- cluster-zookeeper-plugin/src/test/java/org/apache/skywalking/oap/server/cluster/plugin/zookeeper
- server-fetcher-plugin/cilium-fetcher-plugin/src/test/java/org/apache/skywalking/oap/server/fetcher/cilium/nodes
- server-receiver-plugin
- configuration-discovery-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/configuration/discovery
- envoy-metrics-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/envoy
- skywalking-telegraf-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/telegraf
- skywalking-zabbix-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/zabbix/provider
23 files changed
+332
-134
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
Lines changed: 14 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| 52 | + | |
51 | 53 | | |
52 | | - | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
| |||
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 90 | + | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
98 | 106 | | |
99 | 107 | | |
100 | 108 | | |
| |||
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
228 | 227 | | |
229 | 228 | | |
230 | 229 | | |
231 | | - | |
| 230 | + | |
232 | 231 | | |
233 | 232 | | |
234 | 233 | | |
235 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
236 | 237 | | |
237 | 238 | | |
238 | 239 | | |
| |||
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
253 | | - | |
| 254 | + | |
254 | 255 | | |
255 | 256 | | |
256 | 257 | | |
| |||
368 | 369 | | |
369 | 370 | | |
370 | 371 | | |
371 | | - | |
372 | | - | |
373 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
374 | 377 | | |
375 | 378 | | |
376 | 379 | | |
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
35 | | - | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
Lines changed: 17 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
107 | | - | |
108 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| |||
124 | 127 | | |
125 | 128 | | |
126 | 129 | | |
127 | | - | |
128 | | - | |
129 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
130 | 141 | | |
131 | 142 | | |
132 | 143 | | |
| |||
Lines changed: 13 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
36 | | - | |
| 34 | + | |
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
| |||
196 | 194 | | |
197 | 195 | | |
198 | 196 | | |
199 | | - | |
200 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
222 | 222 | | |
223 | | - | |
224 | | - | |
225 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
226 | 230 | | |
227 | 231 | | |
228 | 232 | | |
| |||
Lines changed: 17 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | | - | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
| |||
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
89 | 98 | | |
90 | 99 | | |
91 | 100 | | |
| |||
Lines changed: 50 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| |||
237 | 240 | | |
238 | 241 | | |
239 | 242 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
246 | 264 | | |
247 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
248 | 275 | | |
249 | 276 | | |
250 | 277 | | |
251 | 278 | | |
252 | 279 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
257 | 288 | | |
258 | 289 | | |
259 | 290 | | |
260 | 291 | | |
261 | | - | |
262 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
263 | 298 | | |
264 | 299 | | |
265 | 300 | | |
| |||
0 commit comments