konlue opened a new pull request, #7710:
URL: https://github.com/apache/shenyu/pull/7710

   Fixes #7698.
   
   ## Summary
   
   `KubernetesScaler#scaleByNum` constructs a bare `V1Scale` and dereferences 
its spec with `Objects.requireNonNull`. A fresh `V1Scale` has a null spec, so 
every replica update throws NPE before reaching the Kubernetes API — the fixed 
and time-window scaling policies and the dynamic `scaleByAction` are all dead 
on arrival. The NPE also escapes the surrounding `catch (ApiException)`.
   
   ## Modifications
   
   - Initialise the spec explicitly: `scale.setSpec(new 
V1ScaleSpec().replicas(replicaCount))` instead of 
`requireNonNull(scale.getSpec()).setReplicas(...)`. `V1ScaleSpec` was already 
imported in the file.
   - Add `KubernetesScalerTest`, the scale module's first unit test, with a 
Mockito-mocked `AppsV1Api`:
     - `testScaleByNumSetsSpecBeforeReplace` captures the scale passed to 
`replaceNamespacedDeploymentScale` and asserts the spec is non-null with the 
requested replicas.
     - `testScaleByActionReadsCurrentAndAppliesDelta` mocks 
`readNamespacedDeploymentScale` (replicas=2) and asserts 
`scaleByAction(SCALE_UP)` replaces with replicas=3.
   
   ## Verifying this change
   
   - [x] Red-green: with the original `requireNonNull` line restored, both new 
tests fail with `NullPointerException` at `KubernetesScaler.scaleByNum` 
(matching the stack trace in the issue); with the fix they pass (2/2).
   - [x] Targeted tests pass:
   
     ```bash
     ./mvnw -B -ntp -pl shenyu-admin test -Dtest=KubernetesScalerTest
     ```
   
     2/2 green.
   
   - [x] Checkstyle passes:
   
     ```bash
     ./mvnw -B -ntp -pl shenyu-admin checkstyle:check
     ```
   
     clean.
   
   ## Notes
   
   The replace call's other arguments (`pretty` / `dryRun` / `fieldManager` / 
`fieldValidation`) stay null, unchanged. No behaviour change beyond making the 
call actually reach the API server.


-- 
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