Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public PollScaleReportHandle(

public synchronized void report(T task, Throwable e) {
if (e != null) {
// We want to avoid scaling down on errors if we have never seen a scaling decision
// since we might never scale up again.
if (!everSawScalingDecision) {
return;
}
if ((e instanceof StatusRuntimeException)) {
StatusRuntimeException statusRuntimeException = (StatusRuntimeException) e;
if (statusRuntimeException.getStatus().getCode() == Status.Code.RESOURCE_EXHAUSTED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ public class PollScaleReportHandleTest {
public void handleResourceExhaustedError() {
// Mock dependencies
Functions.Proc1<Integer> mockScaleCallback = Mockito.mock(Functions.Proc1.class);
ScalingTask mockTask = Mockito.mock(ScalingTask.class);
ScalingTask.ScalingDecision mockDecision = Mockito.mock(ScalingTask.ScalingDecision.class);
Mockito.when(mockTask.getScalingDecision()).thenReturn(mockDecision);
Mockito.when(mockDecision.getPollRequestDeltaSuggestion()).thenReturn(0);
PollScaleReportHandle<ScalingTask> handle =
new PollScaleReportHandle<>(1, 10, 8, mockScaleCallback);

// Simulate RESOURCE_EXHAUSTED error
StatusRuntimeException exception = new StatusRuntimeException(Status.RESOURCE_EXHAUSTED);
handle.report(mockTask, null);
handle.report(null, exception);

// Verify target poller count is halved and callback is invoked
Expand All @@ -27,10 +32,15 @@ public void handleResourceExhaustedError() {
public void handleGenericError() {
// Mock dependencies
Functions.Proc1<Integer> mockScaleCallback = Mockito.mock(Functions.Proc1.class);
ScalingTask mockTask = Mockito.mock(ScalingTask.class);
ScalingTask.ScalingDecision mockDecision = Mockito.mock(ScalingTask.ScalingDecision.class);
Mockito.when(mockTask.getScalingDecision()).thenReturn(mockDecision);
Mockito.when(mockDecision.getPollRequestDeltaSuggestion()).thenReturn(0);
PollScaleReportHandle<ScalingTask> handle =
new PollScaleReportHandle<>(1, 10, 5, mockScaleCallback);

// Simulate a generic error
handle.report(mockTask, null);
handle.report(null, new RuntimeException("Generic error"));

// Verify target poller count is decremented and callback is invoked
Expand Down
Loading