@@ -12,11 +12,16 @@ public class PollScaleReportHandleTest {
12
12
public void handleResourceExhaustedError () {
13
13
// Mock dependencies
14
14
Functions .Proc1 <Integer > mockScaleCallback = Mockito .mock (Functions .Proc1 .class );
15
+ ScalingTask mockTask = Mockito .mock (ScalingTask .class );
16
+ ScalingTask .ScalingDecision mockDecision = Mockito .mock (ScalingTask .ScalingDecision .class );
17
+ Mockito .when (mockTask .getScalingDecision ()).thenReturn (mockDecision );
18
+ Mockito .when (mockDecision .getPollRequestDeltaSuggestion ()).thenReturn (0 );
15
19
PollScaleReportHandle <ScalingTask > handle =
16
20
new PollScaleReportHandle <>(1 , 10 , 8 , mockScaleCallback );
17
21
18
22
// Simulate RESOURCE_EXHAUSTED error
19
23
StatusRuntimeException exception = new StatusRuntimeException (Status .RESOURCE_EXHAUSTED );
24
+ handle .report (mockTask , null );
20
25
handle .report (null , exception );
21
26
22
27
// Verify target poller count is halved and callback is invoked
@@ -27,10 +32,15 @@ public void handleResourceExhaustedError() {
27
32
public void handleGenericError () {
28
33
// Mock dependencies
29
34
Functions .Proc1 <Integer > mockScaleCallback = Mockito .mock (Functions .Proc1 .class );
35
+ ScalingTask mockTask = Mockito .mock (ScalingTask .class );
36
+ ScalingTask .ScalingDecision mockDecision = Mockito .mock (ScalingTask .ScalingDecision .class );
37
+ Mockito .when (mockTask .getScalingDecision ()).thenReturn (mockDecision );
38
+ Mockito .when (mockDecision .getPollRequestDeltaSuggestion ()).thenReturn (0 );
30
39
PollScaleReportHandle <ScalingTask > handle =
31
40
new PollScaleReportHandle <>(1 , 10 , 5 , mockScaleCallback );
32
41
33
42
// Simulate a generic error
43
+ handle .report (mockTask , null );
34
44
handle .report (null , new RuntimeException ("Generic error" ));
35
45
36
46
// Verify target poller count is decremented and callback is invoked
0 commit comments