Search in sources :

Example 11 with TestingDispatcherGateway

use of org.apache.flink.runtime.webmonitor.TestingDispatcherGateway in project flink by apache.

the class SessionDispatcherLeaderProcessTest method confirmLeaderSessionFuture_completesAfterDispatcherServiceHasBeenStarted.

@Test
public void confirmLeaderSessionFuture_completesAfterDispatcherServiceHasBeenStarted() throws Exception {
    final OneShotLatch createDispatcherServiceLatch = new OneShotLatch();
    final String dispatcherAddress = "myAddress";
    final TestingDispatcherGateway dispatcherGateway = TestingDispatcherGateway.newBuilder().setAddress(dispatcherAddress).build();
    dispatcherServiceFactory = createFactoryBasedOnGenericSupplier(() -> {
        try {
            createDispatcherServiceLatch.await();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return TestingDispatcherGatewayService.newBuilder().setDispatcherGateway(dispatcherGateway).build();
    });
    try (final SessionDispatcherLeaderProcess dispatcherLeaderProcess = createDispatcherLeaderProcess()) {
        final CompletableFuture<String> confirmLeaderSessionFuture = dispatcherLeaderProcess.getLeaderAddressFuture();
        dispatcherLeaderProcess.start();
        assertThat(confirmLeaderSessionFuture).isNotDone();
        createDispatcherServiceLatch.trigger();
        assertThat(confirmLeaderSessionFuture).succeedsWithin(100, TimeUnit.MILLISECONDS).isEqualTo(dispatcherAddress);
    }
}
Also used : TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) Test(org.junit.jupiter.api.Test)

Example 12 with TestingDispatcherGateway

use of org.apache.flink.runtime.webmonitor.TestingDispatcherGateway in project flink by apache.

the class SessionDispatcherLeaderProcessTest method onAddedJobGraph_failingRecoveredJobSubmission_failsFatally.

@Test
public void onAddedJobGraph_failingRecoveredJobSubmission_failsFatally() throws Exception {
    final TestingDispatcherGateway dispatcherGateway = TestingDispatcherGateway.newBuilder().setSubmitFunction(jobGraph -> FutureUtils.completedExceptionally(new JobSubmissionException(jobGraph.getJobID(), "test exception"))).build();
    runOnAddedJobGraphTest(dispatcherGateway, this::verifyOnAddedJobGraphResultFailsFatally);
}
Also used : OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) FlinkException(org.apache.flink.util.FlinkException) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TestingJobGraphStore(org.apache.flink.runtime.testutils.TestingJobGraphStore) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AfterAll(org.junit.jupiter.api.AfterAll) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) FlinkAssertions(org.apache.flink.core.testutils.FlinkAssertions) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) ThrowingConsumer(org.apache.flink.util.function.ThrowingConsumer) FlinkAssertions.anyCauseMatches(org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches) ExecutorService(java.util.concurrent.ExecutorService) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) JobID(org.apache.flink.api.common.JobID) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) STREAM_THROWABLE(org.apache.flink.core.testutils.FlinkAssertions.STREAM_THROWABLE) JobGraphStore(org.apache.flink.runtime.jobmanager.JobGraphStore) Collections(java.util.Collections) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) Test(org.junit.jupiter.api.Test)

Example 13 with TestingDispatcherGateway

use of org.apache.flink.runtime.webmonitor.TestingDispatcherGateway in project flink by apache.

the class SessionDispatcherLeaderProcessTest method onAddedJobGraph_duplicateJobSubmissionDueToFalsePositive_willBeIgnored.

@Test
public void onAddedJobGraph_duplicateJobSubmissionDueToFalsePositive_willBeIgnored() throws Exception {
    final TestingDispatcherGateway dispatcherGateway = TestingDispatcherGateway.newBuilder().setSubmitFunction(jobGraph -> FutureUtils.completedExceptionally(DuplicateJobSubmissionException.of(jobGraph.getJobID()))).build();
    runOnAddedJobGraphTest(dispatcherGateway, this::verifyOnAddedJobGraphResultDidNotFail);
}
Also used : OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) FlinkException(org.apache.flink.util.FlinkException) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TestingJobGraphStore(org.apache.flink.runtime.testutils.TestingJobGraphStore) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AfterAll(org.junit.jupiter.api.AfterAll) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) FlinkAssertions(org.apache.flink.core.testutils.FlinkAssertions) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) ThrowingConsumer(org.apache.flink.util.function.ThrowingConsumer) FlinkAssertions.anyCauseMatches(org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches) ExecutorService(java.util.concurrent.ExecutorService) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) JobID(org.apache.flink.api.common.JobID) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) STREAM_THROWABLE(org.apache.flink.core.testutils.FlinkAssertions.STREAM_THROWABLE) JobGraphStore(org.apache.flink.runtime.jobmanager.JobGraphStore) Collections(java.util.Collections) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Test(org.junit.jupiter.api.Test)

Aggregations

TestingDispatcherGateway (org.apache.flink.runtime.webmonitor.TestingDispatcherGateway)13 CompletableFuture (java.util.concurrent.CompletableFuture)9 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)9 Test (org.junit.jupiter.api.Test)9 Collections (java.util.Collections)8 Executors (java.util.concurrent.Executors)8 TimeUnit (java.util.concurrent.TimeUnit)8 Supplier (java.util.function.Supplier)8 JobID (org.apache.flink.api.common.JobID)8 DuplicateJobSubmissionException (org.apache.flink.runtime.client.DuplicateJobSubmissionException)8 JobResult (org.apache.flink.runtime.jobmaster.JobResult)8 ExecutorUtils (org.apache.flink.util.ExecutorUtils)8 FlinkException (org.apache.flink.util.FlinkException)8 TestLoggerExtension (org.apache.flink.util.TestLoggerExtension)8 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)8 AfterEach (org.junit.jupiter.api.AfterEach)8 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)8 Optional (java.util.Optional)6 EmbeddedExecutor (org.apache.flink.client.deployment.application.executors.EmbeddedExecutor)6 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)6