use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendSavepointTest method testDisposeSavepointSuccess.
// ------------------------------------------------------------------------
// Dispose savepoint
// ------------------------------------------------------------------------
@Test
public void testDisposeSavepointSuccess() throws Exception {
replaceStdOutAndStdErr();
String savepointPath = "expectedSavepointPath";
ClusterClient clusterClient = new DisposeSavepointClusterClient((String path) -> CompletableFuture.completedFuture(Acknowledge.get()), getConfiguration());
try {
CliFrontend frontend = new MockedCliFrontend(clusterClient);
String[] parameters = { "-d", savepointPath };
frontend.savepoint(parameters);
String outMsg = buffer.toString();
assertTrue(outMsg.contains(savepointPath));
assertTrue(outMsg.contains("disposed"));
} finally {
clusterClient.close();
restoreStdOutAndStdErr();
}
}
use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendSavepointTest method testDisposeSavepointFailure.
@Test
public void testDisposeSavepointFailure() throws Exception {
replaceStdOutAndStdErr();
String savepointPath = "expectedSavepointPath";
Exception testException = new Exception("expectedTestException");
DisposeSavepointClusterClient clusterClient = new DisposeSavepointClusterClient((String path) -> FutureUtils.completedExceptionally(testException), getConfiguration());
try {
CliFrontend frontend = new MockedCliFrontend(clusterClient);
String[] parameters = { "-d", savepointPath };
try {
frontend.savepoint(parameters);
fail("Savepoint should have failed.");
} catch (Exception e) {
assertTrue(ExceptionUtils.findThrowableWithMessage(e, testException.getMessage()).isPresent());
}
} finally {
clusterClient.close();
restoreStdOutAndStdErr();
}
}
use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendSavepointTest method testTriggerSavepointCustomFormat.
/**
* Tests that a CLI call with a custom savepoint directory target is forwarded correctly to the
* cluster client.
*/
@Test
public void testTriggerSavepointCustomFormat() throws Exception {
replaceStdOutAndStdErr();
JobID jobId = new JobID();
String savepointDirectory = "customTargetDirectory";
final ClusterClient<String> clusterClient = createClusterClient(savepointDirectory);
try {
MockedCliFrontend frontend = new MockedCliFrontend(clusterClient);
String[] parameters = { jobId.toString(), savepointDirectory, "-type", SavepointFormatType.NATIVE.toString() };
frontend.savepoint(parameters);
verify(clusterClient, times(1)).triggerSavepoint(eq(jobId), eq(savepointDirectory), eq(SavepointFormatType.NATIVE));
assertTrue(buffer.toString().contains(savepointDirectory));
} finally {
clusterClient.close();
restoreStdOutAndStdErr();
}
}
use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendStopWithSavepointTest method testStopWithExplicitSavepointType.
@Test
public void testStopWithExplicitSavepointType() throws Exception {
JobID jid = new JobID();
String[] parameters = { "-p", "test-target-dir", jid.toString(), "-type", SavepointFormatType.NATIVE.toString() };
OneShotLatch stopWithSavepointLatch = new OneShotLatch();
TestingClusterClient<String> clusterClient = new TestingClusterClient<>();
clusterClient.setStopWithSavepointFunction((jobID, advanceToEndOfEventTime, savepointDirectory, formatType) -> {
assertThat(jobID, is(jid));
assertThat(advanceToEndOfEventTime, is(false));
assertThat(savepointDirectory, is("test-target-dir"));
stopWithSavepointLatch.trigger();
return CompletableFuture.completedFuture(savepointDirectory);
});
MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
testFrontend.stop(parameters);
stopWithSavepointLatch.await();
}
use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendStopWithSavepointTest method testStopWithExplicitSavepointDir.
@Test
public void testStopWithExplicitSavepointDir() throws Exception {
JobID jid = new JobID();
String[] parameters = { "-p", "test-target-dir", jid.toString() };
OneShotLatch stopWithSavepointLatch = new OneShotLatch();
TestingClusterClient<String> clusterClient = new TestingClusterClient<>();
clusterClient.setStopWithSavepointFunction((jobID, advanceToEndOfEventTime, savepointDirectory, formatType) -> {
assertThat(jobID, is(jid));
assertThat(advanceToEndOfEventTime, is(false));
assertThat(savepointDirectory, is("test-target-dir"));
stopWithSavepointLatch.trigger();
return CompletableFuture.completedFuture(savepointDirectory);
});
MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
testFrontend.stop(parameters);
stopWithSavepointLatch.await();
}
Aggregations