Search in sources :

Example 1 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testSendCoordinationRequest.

@Test
public void testSendCoordinationRequest() throws Exception {
    final TestClientCoordinationHandler handler = new TestClientCoordinationHandler();
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(handler)) {
        RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        String payload = "testing payload";
        TestCoordinationRequest<String> request = new TestCoordinationRequest<>(payload);
        try {
            CompletableFuture<CoordinationResponse> future = restClusterClient.sendCoordinationRequest(jobId, new OperatorID(), request);
            TestCoordinationResponse response = (TestCoordinationResponse) future.get();
            assertEquals(payload, response.payload);
        } finally {
            restClusterClient.close();
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) CoordinationResponse(org.apache.flink.runtime.operators.coordination.CoordinationResponse) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Test(org.junit.Test)

Example 2 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testNotShowSuspendedJobStatus.

/**
 * The SUSPENDED job status should never be returned by the client thus client retries until it
 * either receives a different job status or the cluster is not reachable.
 */
@Test
public void testNotShowSuspendedJobStatus() throws Exception {
    final List<JobDetailsInfo> jobDetails = new ArrayList<>();
    jobDetails.add(buildJobDetail(JobStatus.SUSPENDED));
    jobDetails.add(buildJobDetail(JobStatus.RUNNING));
    final TestJobStatusHandler jobStatusHandler = new TestJobStatusHandler(jobDetails.iterator());
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(jobStatusHandler)) {
        final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        try {
            final CompletableFuture<JobStatus> future = restClusterClient.getJobStatus(jobId);
            assertEquals(JobStatus.RUNNING, future.get());
        } finally {
            restClusterClient.close();
        }
    }
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) JobDetailsInfo(org.apache.flink.runtime.rest.messages.job.JobDetailsInfo) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testListJobs.

@Test
public void testListJobs() throws Exception {
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(new TestListJobsHandler())) {
        RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        try {
            CompletableFuture<Collection<JobStatusMessage>> jobDetailsFuture = restClusterClient.listJobs();
            Collection<JobStatusMessage> jobDetails = jobDetailsFuture.get();
            Iterator<JobStatusMessage> jobDetailsIterator = jobDetails.iterator();
            JobStatusMessage job1 = jobDetailsIterator.next();
            JobStatusMessage job2 = jobDetailsIterator.next();
            Assert.assertNotEquals("The job status should not be equal.", job1.getJobState(), job2.getJobState());
        } finally {
            restClusterClient.close();
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) JobStatusMessage(org.apache.flink.runtime.client.JobStatusMessage) Collection(java.util.Collection) Test(org.junit.Test)

Example 4 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testDisposeSavepoint.

@Test
public void testDisposeSavepoint() throws Exception {
    final String savepointPath = "foobar";
    final String exceptionMessage = "Test exception.";
    final FlinkException testException = new FlinkException(exceptionMessage);
    final TestSavepointDisposalHandlers testSavepointDisposalHandlers = new TestSavepointDisposalHandlers(savepointPath);
    final TestSavepointDisposalHandlers.TestSavepointDisposalTriggerHandler testSavepointDisposalTriggerHandler = testSavepointDisposalHandlers.new TestSavepointDisposalTriggerHandler();
    final TestSavepointDisposalHandlers.TestSavepointDisposalStatusHandler testSavepointDisposalStatusHandler = testSavepointDisposalHandlers.new TestSavepointDisposalStatusHandler(OptionalFailure.of(AsynchronousOperationInfo.complete()), OptionalFailure.of(AsynchronousOperationInfo.completeExceptional(new SerializedThrowable(testException))), OptionalFailure.ofFailure(testException));
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(testSavepointDisposalStatusHandler, testSavepointDisposalTriggerHandler)) {
        RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        try {
            {
                final CompletableFuture<Acknowledge> disposeSavepointFuture = restClusterClient.disposeSavepoint(savepointPath);
                assertThat(disposeSavepointFuture.get(), is(Acknowledge.get()));
            }
            {
                final CompletableFuture<Acknowledge> disposeSavepointFuture = restClusterClient.disposeSavepoint(savepointPath);
                try {
                    disposeSavepointFuture.get();
                    fail("Expected an exception");
                } catch (ExecutionException ee) {
                    assertThat(ExceptionUtils.findThrowableWithMessage(ee, exceptionMessage).isPresent(), is(true));
                }
            }
            {
                try {
                    restClusterClient.disposeSavepoint(savepointPath).get();
                    fail("Expected an exception.");
                } catch (ExecutionException ee) {
                    assertThat(ExceptionUtils.findThrowable(ee, RestClientException.class).isPresent(), is(true));
                }
            }
        } finally {
            restClusterClient.close();
        }
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Test(org.junit.Test)

Example 5 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testJobSubmitCancel.

@Test
public void testJobSubmitCancel() throws Exception {
    TestJobSubmitHandler submitHandler = new TestJobSubmitHandler();
    TestJobCancellationHandler terminationHandler = new TestJobCancellationHandler();
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(submitHandler, terminationHandler)) {
        try (RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort())) {
            Assert.assertFalse(submitHandler.jobSubmitted);
            restClusterClient.submitJob(jobGraph).get();
            Assert.assertTrue(submitHandler.jobSubmitted);
            Assert.assertFalse(terminationHandler.jobCanceled);
            restClusterClient.cancel(jobId).get();
            Assert.assertTrue(terminationHandler.jobCanceled);
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) Test(org.junit.Test)

Aggregations

TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)12 Test (org.junit.Test)12 ExecutionException (java.util.concurrent.ExecutionException)5 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)3 FlinkException (org.apache.flink.util.FlinkException)3 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RestClientException (org.apache.flink.runtime.rest.util.RestClientException)2 ConfigurationException (org.apache.flink.util.ConfigurationException)2 SerializedThrowable (org.apache.flink.util.SerializedThrowable)2 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)1 JobID (org.apache.flink.api.common.JobID)1 JobStatus (org.apache.flink.api.common.JobStatus)1