use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendSavepointTest method testTriggerSavepointSuccess.
// ------------------------------------------------------------------------
// Trigger savepoint
// ------------------------------------------------------------------------
@Test
public void testTriggerSavepointSuccess() throws Exception {
replaceStdOutAndStdErr();
JobID jobId = new JobID();
String savepointPath = "expectedSavepointPath";
final ClusterClient<String> clusterClient = createClusterClient(savepointPath);
try {
MockedCliFrontend frontend = new MockedCliFrontend(clusterClient);
String[] parameters = { jobId.toString() };
frontend.savepoint(parameters);
verify(clusterClient, times(1)).triggerSavepoint(eq(jobId), isNull(String.class), eq(SavepointFormatType.DEFAULT));
assertTrue(buffer.toString().contains(savepointPath));
} finally {
clusterClient.close();
restoreStdOutAndStdErr();
}
}
use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendSavepointTest method testDisposeWithJar.
/**
* Tests disposal with a JAR file.
*/
@Test
public void testDisposeWithJar() throws Exception {
replaceStdOutAndStdErr();
final CompletableFuture<String> disposeSavepointFuture = new CompletableFuture<>();
final DisposeSavepointClusterClient clusterClient = new DisposeSavepointClusterClient((String savepointPath) -> {
disposeSavepointFuture.complete(savepointPath);
return CompletableFuture.completedFuture(Acknowledge.get());
}, getConfiguration());
try {
CliFrontend frontend = new MockedCliFrontend(clusterClient);
// Fake JAR file
File f = tmp.newFile();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f));
out.close();
final String disposePath = "any-path";
String[] parameters = { "-d", disposePath, "-j", f.getAbsolutePath() };
frontend.savepoint(parameters);
final String actualSavepointPath = disposeSavepointFuture.get();
assertEquals(disposePath, actualSavepointPath);
} finally {
clusterClient.close();
restoreStdOutAndStdErr();
}
}
use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendSavepointTest method testTriggerSavepointCustomTarget.
/**
* Tests that a CLI call with a custom savepoint directory target is forwarded correctly to the
* cluster client.
*/
@Test
public void testTriggerSavepointCustomTarget() 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 };
frontend.savepoint(parameters);
verify(clusterClient, times(1)).triggerSavepoint(eq(jobId), eq(savepointDirectory), eq(SavepointFormatType.DEFAULT));
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 testUnknownJobId.
@Test
public void testUnknownJobId() throws Exception {
// test unknown job Id
JobID jid = new JobID();
String[] parameters = { "-p", "test-target-dir", jid.toString() };
String expectedMessage = "Test exception";
FlinkException testException = new FlinkException(expectedMessage);
TestingClusterClient<String> clusterClient = new TestingClusterClient<>();
clusterClient.setStopWithSavepointFunction((jobID, advanceToEndOfEventTime, savepointDirectory, formatType) -> FutureUtils.completedExceptionally(testException));
MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
try {
testFrontend.stop(parameters);
fail("Should have failed.");
} catch (FlinkException e) {
assertTrue(ExceptionUtils.findThrowableWithMessage(e, expectedMessage).isPresent());
}
}
use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.
the class CliFrontendStopWithSavepointTest method testStopOnlyWithMaxWM.
@Test
public void testStopOnlyWithMaxWM() throws Exception {
JobID jid = new JobID();
String[] parameters = { "-d", jid.toString() };
OneShotLatch stopWithSavepointLatch = new OneShotLatch();
TestingClusterClient<String> clusterClient = new TestingClusterClient<>();
clusterClient.setStopWithSavepointFunction((jobID, advanceToEndOfEventTime, savepointDirectory, formatType) -> {
assertThat(jobID, is(jid));
assertThat(advanceToEndOfEventTime, is(true));
assertNull(savepointDirectory);
stopWithSavepointLatch.trigger();
return CompletableFuture.completedFuture(savepointDirectory);
});
MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
testFrontend.stop(parameters);
stopWithSavepointLatch.await();
}
Aggregations