@Test public void testDisposeSavepointSuccess() throws Exception { replaceStdOutAndStdErr(); try { String savepointPath = "expectedSavepointPath"; ActorGateway jobManager = mock(ActorGateway.class); Promise<Object> triggerResponse = new scala.concurrent.impl.Promise.DefaultPromise<>(); when(jobManager.ask( Mockito.eq(new JobManagerMessages.DisposeSavepoint(savepointPath)), Mockito.any(FiniteDuration.class))) .thenReturn(triggerResponse.future()); triggerResponse.success(JobManagerMessages.getDisposeSavepointSuccess()); CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager); String[] parameters = {"-d", savepointPath}; int returnCode = frontend.savepoint(parameters); assertEquals(0, returnCode); verify(jobManager, times(1)) .ask( Mockito.eq(new JobManagerMessages.DisposeSavepoint(savepointPath)), Mockito.any(FiniteDuration.class)); String outMsg = buffer.toString(); assertTrue(outMsg.contains(savepointPath)); assertTrue(outMsg.contains("disposed")); } finally { restoreStdOutAndStdErr(); } }
@Test public void testTriggerSavepointFailure() throws Exception { replaceStdOutAndStdErr(); try { JobID jobId = new JobID(); ActorGateway jobManager = mock(ActorGateway.class); Promise<Object> triggerResponse = new scala.concurrent.impl.Promise.DefaultPromise<>(); when(jobManager.ask( Mockito.eq(new JobManagerMessages.TriggerSavepoint(jobId)), Mockito.any(FiniteDuration.class))) .thenReturn(triggerResponse.future()); Exception testException = new Exception("expectedTestException"); triggerResponse.success(new JobManagerMessages.TriggerSavepointFailure(jobId, testException)); CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager); String[] parameters = {jobId.toString()}; int returnCode = frontend.savepoint(parameters); assertTrue(returnCode != 0); verify(jobManager, times(1)) .ask( Mockito.eq(new JobManagerMessages.TriggerSavepoint(jobId)), Mockito.any(FiniteDuration.class)); assertTrue(buffer.toString().contains("expectedTestException")); } finally { restoreStdOutAndStdErr(); } }
@Test public void testTriggerSavepointFailureIllegalJobID() throws Exception { replaceStdOutAndStdErr(); try { CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir()); String[] parameters = {"invalid job id"}; int returnCode = frontend.savepoint(parameters); assertTrue(returnCode != 0); assertTrue(buffer.toString().contains("not a valid ID")); } finally { restoreStdOutAndStdErr(); } }