Search in sources :

Example 1 with MockedCliFrontend

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();
    }
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) RestClusterClient(org.apache.flink.client.program.rest.RestClusterClient) ClusterClient(org.apache.flink.client.program.ClusterClient) MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) Test(org.junit.Test)

Example 2 with MockedCliFrontend

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();
    }
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 3 with MockedCliFrontend

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();
    }
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 4 with MockedCliFrontend

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();
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) TestingClusterClient(org.apache.flink.client.program.TestingClusterClient) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 5 with MockedCliFrontend

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();
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) TestingClusterClient(org.apache.flink.client.program.TestingClusterClient) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

MockedCliFrontend (org.apache.flink.client.cli.util.MockedCliFrontend)18 Test (org.junit.Test)18 JobID (org.apache.flink.api.common.JobID)14 TestingClusterClient (org.apache.flink.client.program.TestingClusterClient)10 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)8 FlinkException (org.apache.flink.util.FlinkException)3 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 ClusterClient (org.apache.flink.client.program.ClusterClient)1 RestClusterClient (org.apache.flink.client.program.rest.RestClusterClient)1