Search in sources :

Example 11 with MockedCliFrontend

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

Example 12 with MockedCliFrontend

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();
    }
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) CompletableFuture(java.util.concurrent.CompletableFuture) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) File(java.io.File) Test(org.junit.Test)

Example 13 with MockedCliFrontend

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

Example 14 with MockedCliFrontend

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

Example 15 with MockedCliFrontend

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();
}
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