org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter Java Examples
The following examples show how to use
org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExecutionGraphSuspendTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that we can suspend a job when in state RESTARTING. */ @Test public void testSuspendWhileRestarting() throws Exception { final ExecutionGraph eg = ExecutionGraphTestUtils.createSimpleTestGraph(new InfiniteDelayRestartStrategy(10)); eg.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); eg.scheduleForExecution(); assertEquals(JobStatus.RUNNING, eg.getState()); ExecutionGraphTestUtils.switchAllVerticesToRunning(eg); eg.failGlobal(new Exception("test")); assertEquals(JobStatus.FAILING, eg.getState()); ExecutionGraphTestUtils.completeCancellingForAllVertices(eg); assertEquals(JobStatus.RESTARTING, eg.getState()); final Exception exception = new Exception("Suspended"); eg.suspend(exception); assertEquals(JobStatus.SUSPENDED, eg.getState()); assertEquals(exception, eg.getFailureCause()); }
Example #2
Source File: FinalizeOnMasterTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFinalizeIsNotCalledUponFailure() throws Exception { final JobID jid = new JobID(); final JobVertex vertex = spy(new JobVertex("test vertex 1")); vertex.setInvokableClass(NoOpInvokable.class); vertex.setParallelism(1); final ExecutionGraph eg = createSimpleTestGraph(jid, vertex); eg.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); eg.scheduleForExecution(); assertEquals(JobStatus.RUNNING, eg.getState()); ExecutionGraphTestUtils.switchAllVerticesToRunning(eg); // fail the execution final Execution exec = eg.getJobVertex(vertex.getID()).getTaskVertices()[0].getCurrentExecutionAttempt(); exec.fail(new Exception("test")); assertEquals(JobStatus.FAILED, eg.waitUntilTerminal()); verify(vertex, times(0)).finalizeOnMaster(any(ClassLoader.class)); assertEquals(0, eg.getRegisteredExecutions().size()); }
Example #3
Source File: ExecutionGraphTestUtils.java From flink with Apache License 2.0 | 6 votes |
public static ExecutionJobVertex getExecutionVertex( JobVertexID id, ScheduledExecutorService executor, ScheduleMode scheduleMode) throws Exception { JobVertex ajv = new JobVertex("TestVertex", id); ajv.setInvokableClass(AbstractInvokable.class); ExecutionGraph graph = new TestingExecutionGraphBuilder(ajv) .setIoExecutor(executor) .setFutureExecutor(executor) .setScheduleMode(scheduleMode) .build(); graph.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); return new ExecutionJobVertex(graph, ajv, 1, AkkaUtils.getDefaultTimeout()); }
Example #4
Source File: FinalizeOnMasterTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFinalizeIsCalledUponSuccess() throws Exception { final JobVertex vertex1 = spy(new JobVertex("test vertex 1")); vertex1.setInvokableClass(NoOpInvokable.class); vertex1.setParallelism(3); final JobVertex vertex2 = spy(new JobVertex("test vertex 2")); vertex2.setInvokableClass(NoOpInvokable.class); vertex2.setParallelism(2); final ExecutionGraph eg = createSimpleTestGraph(vertex1, vertex2); eg.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); eg.scheduleForExecution(); assertEquals(JobStatus.RUNNING, eg.getState()); ExecutionGraphTestUtils.switchAllVerticesToRunning(eg); // move all vertices to finished state ExecutionGraphTestUtils.finishAllVertices(eg); assertEquals(JobStatus.FINISHED, eg.waitUntilTerminal()); verify(vertex1, times(1)).finalizeOnMaster(any(ClassLoader.class)); verify(vertex2, times(1)).finalizeOnMaster(any(ClassLoader.class)); assertEquals(0, eg.getRegisteredExecutions().size()); }
Example #5
Source File: ExecutionGraphVariousFailuesTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a failing scheduleOrUpdateConsumers call with a non-existing execution attempt * id, will not fail the execution graph. */ @Test public void testFailingScheduleOrUpdateConsumers() throws Exception { final ExecutionGraph eg = ExecutionGraphTestUtils.createSimpleTestGraph(new InfiniteDelayRestartStrategy(10)); eg.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); eg.scheduleForExecution(); assertEquals(JobStatus.RUNNING, eg.getState()); ExecutionGraphTestUtils.switchAllVerticesToRunning(eg); IntermediateResultPartitionID intermediateResultPartitionId = new IntermediateResultPartitionID(); ExecutionAttemptID producerId = new ExecutionAttemptID(); ResultPartitionID resultPartitionId = new ResultPartitionID(intermediateResultPartitionId, producerId); // The execution attempt id does not exist and thus the scheduleOrUpdateConsumers call // should fail try { eg.scheduleOrUpdateConsumers(resultPartitionId); fail("Expected ExecutionGraphException."); } catch (ExecutionGraphException e) { // we've expected this exception to occur } assertEquals(JobStatus.RUNNING, eg.getState()); }
Example #6
Source File: GlobalModVersionTest.java From flink with Apache License 2.0 | 6 votes |
private ExecutionGraph createSampleGraph(FailoverStrategy failoverStrategy) throws Exception { final JobID jid = new JobID(); final int parallelism = new Random().nextInt(10) + 1; JobVertex jv = new JobVertex("test vertex"); jv.setInvokableClass(NoOpInvokable.class); jv.setParallelism(parallelism); JobGraph jg = new JobGraph(jid, "testjob", jv); final SimpleSlotProvider slotProvider = new SimpleSlotProvider(parallelism); // build a simple execution graph with on job vertex, parallelism 2 final ExecutionGraph graph = TestingExecutionGraphBuilder .newBuilder() .setJobGraph(jg) .setRestartStrategy(new InfiniteDelayRestartStrategy()) .setFailoverStrategyFactory(new CustomStrategy(failoverStrategy)) .setSlotProvider(slotProvider) .build(); graph.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); return graph; }
Example #7
Source File: ExecutionGraphVariousFailuesTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a {@link SuppressRestartsException} in state RESTARTING stops the restarting * immediately and sets the execution graph's state to FAILED. */ @Test public void testSuppressRestartFailureWhileRestarting() throws Exception { final ExecutionGraph eg = ExecutionGraphTestUtils.createSimpleTestGraph(new InfiniteDelayRestartStrategy(10)); eg.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); eg.scheduleForExecution(); assertEquals(JobStatus.RUNNING, eg.getState()); ExecutionGraphTestUtils.switchAllVerticesToRunning(eg); eg.failGlobal(new Exception("test")); assertEquals(JobStatus.FAILING, eg.getState()); ExecutionGraphTestUtils.completeCancellingForAllVertices(eg); assertEquals(JobStatus.RESTARTING, eg.getState()); // suppress a possible restart eg.failGlobal(new SuppressRestartsException(new Exception("Test"))); assertEquals(JobStatus.FAILED, eg.getState()); }
Example #8
Source File: SchedulerTestBase.java From flink with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { final JobID jobId = new JobID(); final SlotPool slotPool = new TestingSlotPoolImpl(jobId); final TestingScheduler testingScheduler = new TestingScheduler( new HashMap<>(16), LocationPreferenceSlotSelectionStrategy.INSTANCE, slotPool); testingSlotProvider = new TestingSlotPoolSlotProvider(slotPool, testingScheduler); final JobMasterId jobMasterId = JobMasterId.generate(); final String jobManagerAddress = "localhost"; ComponentMainThreadExecutor executor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); slotPool.start(jobMasterId, jobManagerAddress, executor); testingScheduler.start(executor); }
Example #9
Source File: ExecutionGraphSuspendTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that we can suspend a job when in state RESTARTING. */ @Test public void testSuspendWhileRestarting() throws Exception { final ExecutionGraph eg = ExecutionGraphTestUtils.createSimpleTestGraph(new InfiniteDelayRestartStrategy(10)); eg.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); eg.scheduleForExecution(); assertEquals(JobStatus.RUNNING, eg.getState()); ExecutionGraphTestUtils.switchAllVerticesToRunning(eg); eg.failGlobal(new Exception("test")); assertEquals(JobStatus.FAILING, eg.getState()); ExecutionGraphTestUtils.completeCancellingForAllVertices(eg); assertEquals(JobStatus.RESTARTING, eg.getState()); final Exception exception = new Exception("Suspended"); eg.suspend(exception); assertEquals(JobStatus.SUSPENDED, eg.getState()); assertEquals(exception, eg.getFailureCause()); }
Example #10
Source File: ExecutionGraphVariousFailuesTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a failing scheduleOrUpdateConsumers call with a non-existing execution attempt * id, will not fail the execution graph. */ @Test public void testFailingScheduleOrUpdateConsumers() throws Exception { final ExecutionGraph eg = ExecutionGraphTestUtils.createSimpleTestGraph(new InfiniteDelayRestartStrategy(10)); eg.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); eg.scheduleForExecution(); assertEquals(JobStatus.RUNNING, eg.getState()); ExecutionGraphTestUtils.switchAllVerticesToRunning(eg); IntermediateResultPartitionID intermediateResultPartitionId = new IntermediateResultPartitionID(); ExecutionAttemptID producerId = new ExecutionAttemptID(); ResultPartitionID resultPartitionId = new ResultPartitionID(intermediateResultPartitionId, producerId); // The execution attempt id does not exist and thus the scheduleOrUpdateConsumers call // should fail try { eg.scheduleOrUpdateConsumers(resultPartitionId); fail("Expected ExecutionGraphException."); } catch (ExecutionGraphException e) { // we've expected this exception to occur } assertEquals(JobStatus.RUNNING, eg.getState()); }
Example #11
Source File: SlotPoolPendingRequestFailureTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a pending slot request is failed with a timeout. */ @Test public void testPendingSlotRequestTimeout() throws Exception { final ScheduledExecutorService singleThreadExecutor = Executors.newSingleThreadScheduledExecutor(); final ComponentMainThreadExecutor componentMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(singleThreadExecutor); final SlotPoolImpl slotPool = setUpSlotPool(componentMainThreadExecutor); try { final Time timeout = Time.milliseconds(5L); final CompletableFuture<PhysicalSlot> slotFuture = CompletableFuture .supplyAsync(() -> requestNewAllocatedSlot(slotPool, new SlotRequestId(), timeout), componentMainThreadExecutor) .thenCompose(Function.identity()); try { slotFuture.get(); fail("Expected that the future completes with a TimeoutException."); } catch (ExecutionException ee) { assertThat(ExceptionUtils.stripExecutionException(ee), instanceOf(TimeoutException.class)); } } finally { CompletableFuture.runAsync(ThrowingRunnable.unchecked(slotPool::close), componentMainThreadExecutor).get(); singleThreadExecutor.shutdownNow(); } }
Example #12
Source File: ExecutionGraphSuspendTest.java From flink with Apache License 2.0 | 6 votes |
private static ExecutionGraph createExecutionGraph(TaskManagerGateway gateway, int parallelism) throws Exception { final JobID jobId = new JobID(); final JobVertex vertex = new JobVertex("vertex"); vertex.setInvokableClass(NoOpInvokable.class); vertex.setParallelism(parallelism); final SlotProvider slotProvider = new SimpleSlotProvider(jobId, parallelism, gateway); ExecutionGraph simpleTestGraph = ExecutionGraphTestUtils.createSimpleTestGraph( jobId, slotProvider, new FixedDelayRestartStrategy(0, 0), vertex); simpleTestGraph.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); return simpleTestGraph; }
Example #13
Source File: SlotPoolPendingRequestFailureTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a pending slot request is failed with a timeout. */ @Test public void testPendingSlotRequestTimeout() throws Exception { final ScheduledExecutorService singleThreadExecutor = Executors.newSingleThreadScheduledExecutor(); final ComponentMainThreadExecutor componentMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(singleThreadExecutor); final SlotPoolImpl slotPool = setUpSlotPool(componentMainThreadExecutor); try { final Time timeout = Time.milliseconds(5L); final CompletableFuture<PhysicalSlot> slotFuture = CompletableFuture .supplyAsync(() -> requestNewAllocatedSlot(slotPool, new SlotRequestId(), timeout), componentMainThreadExecutor) .thenCompose(Function.identity()); try { slotFuture.get(); fail("Expected that the future completes with a TimeoutException."); } catch (ExecutionException ee) { assertThat(ExceptionUtils.stripExecutionException(ee), instanceOf(TimeoutException.class)); } } finally { CompletableFuture.runAsync(ThrowingRunnable.unchecked(slotPool::close), componentMainThreadExecutor).get(); singleThreadExecutor.shutdownNow(); } }
Example #14
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a batch slot request does not react to {@link SlotPool#failAllocation(AllocationID, Exception)} * signals whose exception is not {@link UnfulfillableSlotRequestException}. */ @Test public void testPendingBatchSlotRequestDoesNotFailIfAllocationFails() throws Exception { final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway(); final CompletableFuture<AllocationID> allocationIdFuture = new CompletableFuture<>(); testingResourceManagerGateway.setRequestSlotConsumer(slotRequest -> allocationIdFuture.complete(slotRequest.getAllocationId())); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); final Time batchSlotTimeout = Time.milliseconds(1000L); try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setBatchSlotTimeout(batchSlotTimeout) .setResourceManagerGateway(testingResourceManagerGateway) .build()) { final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); SlotPoolUtils.failAllocation(slotPool, directMainThreadExecutor, allocationIdFuture.get(), new FlinkException("Failed request")); assertThat(slotFuture.isDone(), is(false)); } }
Example #15
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a batch slot request fails if its resource manager request fails with {@link UnfulfillableSlotRequestException}. */ @Test public void testPendingBatchSlotRequestFailsIfRMRequestFailsUnfulfillably() throws Exception { final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway(); testingResourceManagerGateway.setRequestSlotFuture(FutureUtils.completedExceptionally( new UnfulfillableSlotRequestException(new AllocationID(), ResourceProfile.UNKNOWN))); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setResourceManagerGateway(testingResourceManagerGateway) .build()) { final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); assertThat(slotFuture.isCompletedExceptionally(), is(true)); } }
Example #16
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a batch slot request won't fail if its resource manager request fails with exceptions other than * {@link UnfulfillableSlotRequestException}. */ @Test public void testPendingBatchSlotRequestDoesNotFailIfRMRequestFails() throws Exception { final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway(); testingResourceManagerGateway.setRequestSlotFuture(FutureUtils.completedExceptionally(new FlinkException("Failed request"))); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); final Time batchSlotTimeout = Time.milliseconds(1000L); try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setBatchSlotTimeout(batchSlotTimeout) .setResourceManagerGateway(testingResourceManagerGateway) .build()) { final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); assertThat(slotFuture.isDone(), is(false)); } }
Example #17
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a batch slot request does react to {@link SlotPool#failAllocation(AllocationID, Exception)} * signals whose exception is {@link UnfulfillableSlotRequestException}. */ @Test public void testPendingBatchSlotRequestFailsIfAllocationFailsUnfulfillably() throws Exception { final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway(); final CompletableFuture<AllocationID> allocationIdFuture = new CompletableFuture<>(); testingResourceManagerGateway.setRequestSlotConsumer(slotRequest -> allocationIdFuture.complete(slotRequest.getAllocationId())); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setResourceManagerGateway(testingResourceManagerGateway) .build()) { final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); SlotPoolUtils.failAllocation(slotPool, directMainThreadExecutor, allocationIdFuture.get(), new UnfulfillableSlotRequestException(new AllocationID(), ResourceProfile.UNKNOWN)); assertThat(slotFuture.isCompletedExceptionally(), is(true)); } }
Example #18
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a batch slot request does not react to {@link SlotPool#failAllocation(AllocationID, Exception)} * signals whose exception is not {@link UnfulfillableSlotRequestException}. */ @Test public void testPendingBatchSlotRequestDoesNotFailIfAllocationFails() throws Exception { final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway(); final CompletableFuture<AllocationID> allocationIdFuture = new CompletableFuture<>(); testingResourceManagerGateway.setRequestSlotConsumer(slotRequest -> allocationIdFuture.complete(slotRequest.getAllocationId())); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); final Time batchSlotTimeout = Time.milliseconds(1000L); try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setBatchSlotTimeout(batchSlotTimeout) .setResourceManagerGateway(testingResourceManagerGateway) .build()) { final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); SlotPoolUtils.failAllocation(slotPool, directMainThreadExecutor, allocationIdFuture.get(), new FlinkException("Failed request")); assertThat(slotFuture.isDone(), is(false)); } }
Example #19
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a batch slot request does react to {@link SlotPool#failAllocation(AllocationID, Exception)} * signals whose exception is {@link UnfulfillableSlotRequestException}. */ @Test public void testPendingBatchSlotRequestFailsIfAllocationFailsUnfulfillably() throws Exception { final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway(); final CompletableFuture<AllocationID> allocationIdFuture = new CompletableFuture<>(); testingResourceManagerGateway.setRequestSlotConsumer(slotRequest -> allocationIdFuture.complete(slotRequest.getAllocationId())); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setResourceManagerGateway(testingResourceManagerGateway) .build()) { final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); SlotPoolUtils.failAllocation(slotPool, directMainThreadExecutor, allocationIdFuture.get(), new UnfulfillableSlotRequestException(new AllocationID(), ResourceProfile.UNKNOWN)); assertThat(slotFuture.isCompletedExceptionally(), is(true)); } }
Example #20
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a batch slot request won't fail if its resource manager request fails with exceptions other than * {@link UnfulfillableSlotRequestException}. */ @Test public void testPendingBatchSlotRequestDoesNotFailIfRMRequestFails() throws Exception { final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway(); testingResourceManagerGateway.setRequestSlotFuture(FutureUtils.completedExceptionally(new FlinkException("Failed request"))); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); final Time batchSlotTimeout = Time.milliseconds(1000L); try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setBatchSlotTimeout(batchSlotTimeout) .setResourceManagerGateway(testingResourceManagerGateway) .build()) { final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); assertThat(slotFuture.isDone(), is(false)); } }
Example #21
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that a batch slot request fails if its resource manager request fails with {@link UnfulfillableSlotRequestException}. */ @Test public void testPendingBatchSlotRequestFailsIfRMRequestFailsUnfulfillably() throws Exception { final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway(); testingResourceManagerGateway.setRequestSlotFuture(FutureUtils.completedExceptionally( new UnfulfillableSlotRequestException(new AllocationID(), ResourceProfile.UNKNOWN))); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setResourceManagerGateway(testingResourceManagerGateway) .build()) { final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); assertThat(slotFuture.isCompletedExceptionally(), is(true)); } }
Example #22
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that a batch slot request won't time out if there exists a slot in the * SlotPool which fulfills the requested {@link ResourceProfile}. */ @Test public void testPendingBatchSlotRequestDoesNotTimeoutIfFulfillingSlotExists() throws Exception { final Time batchSlotTimeout = Time.milliseconds(2L); final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); final ManualClock clock = new ManualClock(); try (final TestingSlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setClock(clock) .setBatchSlotTimeout(batchSlotTimeout) .build()) { SlotPoolUtils.offerSlots(slotPool, directMainThreadExecutor, Collections.singletonList(resourceProfile)); final CompletableFuture<PhysicalSlot> firstSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); final CompletableFuture<PhysicalSlot> secondSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, ResourceProfile.UNKNOWN); final CompletableFuture<PhysicalSlot> thirdSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, smallerResourceProfile); final List<CompletableFuture<PhysicalSlot>> slotFutures = Arrays.asList(firstSlotFuture, secondSlotFuture, thirdSlotFuture); advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, clock, batchSlotTimeout); for (CompletableFuture<PhysicalSlot> slotFuture : slotFutures) { assertThat(slotFuture.isDone(), is(false)); } } }
Example #23
Source File: TestingComponentMainThreadExecutor.java From flink with Apache License 2.0 | 5 votes |
@Override protected void before() { this.innerExecutorService = Executors.newSingleThreadScheduledExecutor(); this.componentMainThreadTestExecutor = new TestingComponentMainThreadExecutor( ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(innerExecutorService)); }
Example #24
Source File: OperatorCoordinatorHolderTest.java From flink with Apache License 2.0 | 5 votes |
private OperatorCoordinatorHolder createCoordinatorHolder( final BiFunction<SerializedValue<OperatorEvent>, Integer, CompletableFuture<Acknowledge>> eventSender, final Function<OperatorCoordinator.Context, OperatorCoordinator> coordinatorCtor) throws Exception { return createCoordinatorHolder( eventSender, coordinatorCtor, ComponentMainThreadExecutorServiceAdapter.forMainThread()); }
Example #25
Source File: ExecutionGraphCheckpointCoordinatorTest.java From flink with Apache License 2.0 | 5 votes |
private ExecutionGraph createExecutionGraphAndEnableCheckpointing( CheckpointIDCounter counter, CompletedCheckpointStore store) throws Exception { final Time timeout = Time.days(1L); JobVertex jobVertex = new JobVertex("MockVertex"); jobVertex.setInvokableClass(AbstractInvokable.class); final ExecutionGraph executionGraph = new ExecutionGraphTestUtils.TestingExecutionGraphBuilder(jobVertex) .setRpcTimeout(timeout) .setAllocationTimeout(timeout) .allowQueuedScheduling() .build(); executionGraph.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); CheckpointCoordinatorConfiguration chkConfig = new CheckpointCoordinatorConfiguration( 100, 100, 100, 1, CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION, true, false, 0); executionGraph.enableCheckpointing( chkConfig, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), counter, store, new MemoryStateBackend(), CheckpointStatsTrackerTest.createTestTracker()); return executionGraph; }
Example #26
Source File: TaskSlotTableImplTest.java From flink with Apache License 2.0 | 5 votes |
private static TaskSlotTableImpl<TaskSlotPayload> createTaskSlotTableAndStart( final int numberOfSlots, final SlotActions slotActions) { final TaskSlotTableImpl<TaskSlotPayload> taskSlotTable = TaskSlotUtils.createTaskSlotTable(numberOfSlots); taskSlotTable.start(slotActions, ComponentMainThreadExecutorServiceAdapter.forMainThread()); return taskSlotTable; }
Example #27
Source File: SlotPoolBatchSlotRequestTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that a pending batch slot request times out after the last fulfilling slot gets * released. */ @Test public void testPendingBatchSlotRequestTimeoutAfterSlotRelease() throws Exception { final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); final ManualClock clock = new ManualClock(); final Time batchSlotTimeout = Time.milliseconds(1000L); try (final TestingSlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor) .setClock(clock) .setBatchSlotTimeout(batchSlotTimeout) .build()) { final ResourceID taskManagerResourceId = SlotPoolUtils.offerSlots(slotPool, directMainThreadExecutor, Collections.singletonList(resourceProfile)); final CompletableFuture<PhysicalSlot> firstSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); final CompletableFuture<PhysicalSlot> secondSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, ResourceProfile.UNKNOWN); final CompletableFuture<PhysicalSlot> thirdSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, smallerResourceProfile); final List<CompletableFuture<PhysicalSlot>> slotFutures = Arrays.asList(firstSlotFuture, secondSlotFuture, thirdSlotFuture); // initial batch slot timeout check advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, clock, batchSlotTimeout); assertThat(CompletableFuture.anyOf(slotFutures.toArray(COMPLETABLE_FUTURES_EMPTY_ARRAY)).isDone(), is(false)); SlotPoolUtils.releaseTaskManager(slotPool, directMainThreadExecutor, taskManagerResourceId); advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, clock, batchSlotTimeout); for (CompletableFuture<PhysicalSlot> slotFuture : slotFutures) { assertThat(slotFuture.isCompletedExceptionally(), is(true)); try { slotFuture.get(); fail("Expected that the slot future times out."); } catch (ExecutionException ee) { assertThat(ExceptionUtils.stripExecutionException(ee), instanceOf(TimeoutException.class)); } } } }
Example #28
Source File: OperatorCoordinatorHolderTest.java From flink with Apache License 2.0 | 5 votes |
private void checkpointEventValueAtomicity( final Function<OperatorCoordinator.Context, OperatorCoordinator> coordinatorCtor) throws Exception { final ManuallyTriggeredScheduledExecutorService executor = new ManuallyTriggeredScheduledExecutorService(); final ComponentMainThreadExecutor mainThreadExecutor = new ComponentMainThreadExecutorServiceAdapter( (ScheduledExecutorService) executor, Thread.currentThread()); final TestEventSender sender = new TestEventSender(); final OperatorCoordinatorHolder holder = createCoordinatorHolder( sender, coordinatorCtor, mainThreadExecutor); // give the coordinator some time to emit some events Thread.sleep(new Random().nextInt(10) + 20); executor.triggerAll(); // trigger the checkpoint - this should also shut the valve as soon as the future is completed final CompletableFuture<byte[]> checkpointFuture = new CompletableFuture<>(); holder.checkpointCoordinator(0L, checkpointFuture); executor.triggerAll(); // give the coordinator some time to emit some events Thread.sleep(new Random().nextInt(10) + 10); holder.close(); executor.triggerAll(); assertTrue(checkpointFuture.isDone()); final int checkpointedNumber = bytesToInt(checkpointFuture.get()); assertEquals(checkpointedNumber, sender.events.size()); for (int i = 0; i < checkpointedNumber; i++) { assertEquals(i, ((TestOperatorEvent) sender.events.get(i).event).getValue()); } }
Example #29
Source File: ExecutionGraphSchedulingTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that a partially completed eager scheduling operation fails if a * completed slot is released. See FLINK-9099. */ @Test public void testSlotReleasingFailsSchedulingOperation() throws Exception { final int parallelism = 2; final JobVertex jobVertex = new JobVertex("Testing job vertex"); jobVertex.setInvokableClass(NoOpInvokable.class); jobVertex.setParallelism(parallelism); final JobGraph jobGraph = new JobGraph(jobVertex); jobGraph.setAllowQueuedScheduling(true); jobGraph.setScheduleMode(ScheduleMode.EAGER); final ProgrammedSlotProvider slotProvider = new ProgrammedSlotProvider(parallelism); final LogicalSlot slot = createSingleLogicalSlot(new DummySlotOwner(), new SimpleAckingTaskManagerGateway(), new SlotRequestId()); slotProvider.addSlot(jobVertex.getID(), 0, CompletableFuture.completedFuture(slot)); final CompletableFuture<LogicalSlot> slotFuture = new CompletableFuture<>(); slotProvider.addSlot(jobVertex.getID(), 1, slotFuture); final ExecutionGraph executionGraph = createExecutionGraph(jobGraph, slotProvider); executionGraph.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); executionGraph.scheduleForExecution(); assertThat(executionGraph.getState(), is(JobStatus.RUNNING)); final ExecutionJobVertex executionJobVertex = executionGraph.getJobVertex(jobVertex.getID()); final ExecutionVertex[] taskVertices = executionJobVertex.getTaskVertices(); assertThat(taskVertices[0].getExecutionState(), is(ExecutionState.SCHEDULED)); assertThat(taskVertices[1].getExecutionState(), is(ExecutionState.SCHEDULED)); // fail the single allocated slot --> this should fail the scheduling operation slot.releaseSlot(new FlinkException("Test failure")); assertThat(executionGraph.getTerminationFuture().get(), is(JobStatus.FAILED)); }
Example #30
Source File: ExecutionGraphSchedulingTest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that an ongoing scheduling operation does not fail the {@link ExecutionGraph} * if it gets concurrently cancelled. */ @Test public void testSchedulingOperationCancellationWhenCancel() throws Exception { final JobVertex jobVertex = new JobVertex("NoOp JobVertex"); jobVertex.setInvokableClass(NoOpInvokable.class); jobVertex.setParallelism(2); final JobGraph jobGraph = new JobGraph(jobVertex); jobGraph.setScheduleMode(ScheduleMode.EAGER); jobGraph.setAllowQueuedScheduling(true); final CompletableFuture<LogicalSlot> slotFuture1 = new CompletableFuture<>(); final CompletableFuture<LogicalSlot> slotFuture2 = new CompletableFuture<>(); final ProgrammedSlotProvider slotProvider = new ProgrammedSlotProvider(2); slotProvider.addSlots(jobVertex.getID(), new CompletableFuture[]{slotFuture1, slotFuture2}); final ExecutionGraph executionGraph = createExecutionGraph(jobGraph, slotProvider); executionGraph.start(ComponentMainThreadExecutorServiceAdapter.forMainThread()); executionGraph.scheduleForExecution(); final TestingLogicalSlot slot = createTestingSlot(); final CompletableFuture<?> releaseFuture = slot.getReleaseFuture(); slotFuture1.complete(slot); // cancel should change the state of all executions to CANCELLED executionGraph.cancel(); // complete the now CANCELLED execution --> this should cause a failure slotFuture2.complete(new TestingLogicalSlotBuilder().createTestingLogicalSlot()); Thread.sleep(1L); // release the first slot to finish the cancellation releaseFuture.complete(null); // NOTE: This test will only occasionally fail without the fix since there is // a race between the releaseFuture and the slotFuture2 assertThat(executionGraph.getTerminationFuture().get(), is(JobStatus.CANCELED)); }