Search in sources :

Example 6 with TestingClusterClient

use of org.apache.flink.client.program.TestingClusterClient 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 7 with TestingClusterClient

use of org.apache.flink.client.program.TestingClusterClient 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)

Example 8 with TestingClusterClient

use of org.apache.flink.client.program.TestingClusterClient in project flink by apache.

the class CliFrontendStopWithSavepointTest method testStopWithDefaultSavepointDir.

@Test
public void testStopWithDefaultSavepointDir() throws Exception {
    JobID jid = new JobID();
    String[] parameters = { 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));
        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 9 with TestingClusterClient

use of org.apache.flink.client.program.TestingClusterClient in project flink by apache.

the class CliFrontendStopWithSavepointTest method testStopWithMaxWMAndDefaultSavepointDir.

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

Example 10 with TestingClusterClient

use of org.apache.flink.client.program.TestingClusterClient in project flink by apache.

the class CliFrontendCancelTest method testCancel.

@Test
public void testCancel() throws Exception {
    // test cancel properly
    JobID jid = new JobID();
    OneShotLatch cancelLatch = new OneShotLatch();
    String[] parameters = { jid.toString() };
    TestingClusterClient<String> clusterClient = new TestingClusterClient<>();
    clusterClient.setCancelFunction(jobID -> {
        cancelLatch.trigger();
        return CompletableFuture.completedFuture(Acknowledge.get());
    });
    MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
    testFrontend.cancel(parameters);
    cancelLatch.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

JobID (org.apache.flink.api.common.JobID)10 MockedCliFrontend (org.apache.flink.client.cli.util.MockedCliFrontend)10 TestingClusterClient (org.apache.flink.client.program.TestingClusterClient)10 Test (org.junit.Test)10 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)8 FlinkException (org.apache.flink.util.FlinkException)1