@Test
public void testScaleStream() throws ExecutionException, InterruptedException {
when(this.mockControllerService.checkScale(anyString(), anyString(), anyInt())).thenReturn(
CompletableFuture.completedFuture(Controller.ScaleStatusResponse.newBuilder()
.setStatus(Controller.ScaleStatusResponse.ScaleStatus.SUCCESS).build()));
when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong())).thenReturn(
CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder()
.setStatus(Controller.ScaleResponse.ScaleStreamStatus.STARTED).build()));
Assert.assertTrue(this.testController.scaleStream(new StreamImpl("scope", "stream"),
new ArrayList<>(), new HashMap<>(), executorService()).getFuture().join());
when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong())).thenReturn(
CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder()
.setStatus(Controller.ScaleResponse.ScaleStreamStatus.PRECONDITION_FAILED).build()));
Assert.assertFalse(this.testController.scaleStream(new StreamImpl("scope", "stream"),
new ArrayList<>(), new HashMap<>(), executorService()).getFuture().join());
when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong())).thenReturn(
CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder()
.setStatus(Controller.ScaleResponse.ScaleStreamStatus.FAILURE).build()));
assertThrows("Expected ControllerFailureException",
() -> this.testController.startScale(new StreamImpl("scope", "stream"),
new ArrayList<>(), new HashMap<>()).join(),
ex -> ex instanceof ControllerFailureException);
when(this.mockControllerService.scale(any(), any(), any(), any(), anyLong())).thenReturn(
CompletableFuture.completedFuture(Controller.ScaleResponse.newBuilder()
.setStatusValue(-1).build()));
assertThrows("Expected ControllerFailureException",
() -> this.testController.startScale(new StreamImpl("scope", "stream"),
new ArrayList<>(), new HashMap<>()).join(),
ex -> ex instanceof ControllerFailureException);
}