Hyeon-moGu opened a new pull request, #13718:
URL: https://github.com/apache/skywalking/pull/13718

   - [ ] If this pull request closes/resolves/fixes an existing issue, replace 
the issue number. Closes #13709 .
   - [x] Update the [`CHANGES` 
log](https://github.com/apache/skywalking/blob/master/docs/en/changes/changes.md).
   
   
   ### [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`:
   
   - Eliminated Redundant Mocks: Removed unused `CoreModule` and 
`MetricsStreamProcessor` stubbings.
   
   - Benefit: Removing these dead mock configurations simplifies the test 
setup, adheres to the minimal mocking principle, and ensures full compatibility 
with modern Mockito strictness.
   
   `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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to