Search in sources :

Example 6 with MockedCliFrontend

use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.

the class CliFrontendStopWithSavepointTest method testStopWithMaxWMAndExplicitSavepointDir.

@Test
public void testStopWithMaxWMAndExplicitSavepointDir() throws Exception {
    JobID jid = new JobID();
    String[] parameters = { "-d", "-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(true));
        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 7 with MockedCliFrontend

use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.

the class CliFrontendStopWithSavepointTest method testStopWithOnlyJobId.

@Test
public void testStopWithOnlyJobId() throws Exception {
    // test stop properly
    JobID jid = new JobID();
    String jidString = jid.toString();
    String[] parameters = { jidString };
    OneShotLatch stopWithSavepointLatch = new OneShotLatch();
    TestingClusterClient<String> clusterClient = new TestingClusterClient<>();
    clusterClient.setStopWithSavepointFunction((jobID, advanceToEndOfEventTime, savepointDirectory, formatType) -> {
        assertThat(jobID, is(jid));
        assertThat(advanceToEndOfEventTime, is(false));
        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)

Example 8 with MockedCliFrontend

use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.

the class CliFrontendStopWithSavepointTest method testWrongSavepointDirOrder.

@Test(expected = CliArgsException.class)
public void testWrongSavepointDirOrder() throws Exception {
    JobID jid = new JobID();
    String[] parameters = { "-s", "-d", "test-target-dir", jid.toString() };
    MockedCliFrontend testFrontend = new MockedCliFrontend(new TestingClusterClient());
    testFrontend.stop(parameters);
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) TestingClusterClient(org.apache.flink.client.program.TestingClusterClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 9 with MockedCliFrontend

use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.

the class CliFrontendSavepointTest method testTriggerSavepointFailure.

@Test
public void testTriggerSavepointFailure() throws Exception {
    replaceStdOutAndStdErr();
    JobID jobId = new JobID();
    String expectedTestException = "expectedTestException";
    Exception testException = new Exception(expectedTestException);
    final ClusterClient<String> clusterClient = createFailingClusterClient(testException);
    try {
        MockedCliFrontend frontend = new MockedCliFrontend(clusterClient);
        String[] parameters = { jobId.toString() };
        try {
            frontend.savepoint(parameters);
            fail("Savepoint should have failed.");
        } catch (FlinkException e) {
            assertTrue(ExceptionUtils.findThrowableWithMessage(e, expectedTestException).isPresent());
        }
    } finally {
        clusterClient.close();
        restoreStdOutAndStdErr();
    }
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) JobID(org.apache.flink.api.common.JobID) FlinkException(org.apache.flink.util.FlinkException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 10 with MockedCliFrontend

use of org.apache.flink.client.cli.util.MockedCliFrontend in project flink by apache.

the class CliFrontendSavepointTest method testTriggerSavepointFailureIllegalJobID.

@Test
public void testTriggerSavepointFailureIllegalJobID() throws Exception {
    replaceStdOutAndStdErr();
    try {
        CliFrontend frontend = new MockedCliFrontend(new RestClusterClient<>(getConfiguration(), StandaloneClusterId.getInstance()));
        String[] parameters = { "invalid job id" };
        try {
            frontend.savepoint(parameters);
            fail("Should have failed.");
        } catch (CliArgsException e) {
            assertThat(e.getMessage(), Matchers.containsString("Cannot parse JobID"));
        }
    } finally {
        restoreStdOutAndStdErr();
    }
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) 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