Search in sources :

Example 1 with MockOperatorCoordinatorContext

use of org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext in project flink by apache.

the class SourceCoordinatorTest method testUserClassLoaderWhenCreatingNewEnumerator.

@Test
public void testUserClassLoaderWhenCreatingNewEnumerator() throws Exception {
    final ClassLoader testClassLoader = new URLClassLoader(new URL[0]);
    final OperatorCoordinator.Context context = new MockOperatorCoordinatorContext(new OperatorID(), testClassLoader);
    final EnumeratorCreatingSource<?, ClassLoaderTestEnumerator> source = new EnumeratorCreatingSource<>(ClassLoaderTestEnumerator::new);
    final SourceCoordinatorProvider<?> provider = new SourceCoordinatorProvider<>("testOperator", context.getOperatorId(), source, 1, WatermarkAlignmentParams.WATERMARK_ALIGNMENT_DISABLED);
    final OperatorCoordinator coordinator = provider.getCoordinator(context);
    coordinator.start();
    final ClassLoaderTestEnumerator enumerator = source.createEnumeratorFuture.get();
    assertSame(testClassLoader, enumerator.constructorClassLoader);
    assertSame(testClassLoader, enumerator.threadClassLoader.get());
    // cleanup
    coordinator.close();
}
Also used : MockOperatorCoordinatorContext(org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext) URLClassLoader(java.net.URLClassLoader) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) URLClassLoader(java.net.URLClassLoader) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Test(org.junit.Test)

Example 2 with MockOperatorCoordinatorContext

use of org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext in project flink by apache.

the class SourceCoordinatorProviderTest method testCheckpointAndReset.

@Test
public void testCheckpointAndReset() throws Exception {
    final OperatorCoordinator.Context context = new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SPLITS);
    final RecreateOnResetOperatorCoordinator coordinator = (RecreateOnResetOperatorCoordinator) provider.create(context);
    final SourceCoordinator<?, ?> sourceCoordinator = (SourceCoordinator<?, ?>) coordinator.getInternalCoordinator();
    // Start the coordinator.
    coordinator.start();
    // register reader 0 and take a checkpoint.
    coordinator.handleEventFromOperator(0, new ReaderRegistrationEvent(0, "location"));
    CompletableFuture<byte[]> future = new CompletableFuture<>();
    coordinator.checkpointCoordinator(0L, future);
    byte[] bytes = future.get();
    // Register reader 1.
    coordinator.handleEventFromOperator(1, new ReaderRegistrationEvent(1, "location"));
    // Wait until the coordinator context is updated with registration of reader 1.
    while (sourceCoordinator.getContext().registeredReaders().size() < 2) {
        Thread.sleep(1);
    }
    // reset the coordinator to the checkpoint which only contains reader 0.
    coordinator.resetToCheckpoint(0L, bytes);
    final SourceCoordinator<?, ?> restoredSourceCoordinator = (SourceCoordinator<?, ?>) coordinator.getInternalCoordinator();
    assertNotEquals("The restored source coordinator should be a different instance", restoredSourceCoordinator, sourceCoordinator);
    // FLINK-21452: do not (re)store registered readers
    assertEquals("There should be no registered reader.", 0, restoredSourceCoordinator.getContext().registeredReaders().size());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MockOperatorCoordinatorContext(org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) ReaderRegistrationEvent(org.apache.flink.runtime.source.event.ReaderRegistrationEvent) Test(org.junit.Test)

Example 3 with MockOperatorCoordinatorContext

use of org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext in project flink by apache.

the class SourceCoordinatorTestBase method setup.

// ------------------------------------------------------------------------
@Before
public void setup() throws Exception {
    receivingTasks = EventReceivingTasks.createForRunningTasks();
    operatorCoordinatorContext = new MockOperatorCoordinatorContext(TEST_OPERATOR_ID, NUM_SUBTASKS);
    splitSplitAssignmentTracker = new SplitAssignmentTracker<>();
    String coordinatorThreadName = TEST_OPERATOR_ID.toHexString();
    coordinatorThreadFactory = new SourceCoordinatorProvider.CoordinatorExecutorThreadFactory(coordinatorThreadName, getClass().getClassLoader());
    coordinatorExecutor = Executors.newScheduledThreadPool(1, coordinatorThreadFactory);
    sourceCoordinator = getNewSourceCoordinator();
    context = sourceCoordinator.getContext();
}
Also used : MockOperatorCoordinatorContext(org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext) Before(org.junit.Before)

Example 4 with MockOperatorCoordinatorContext

use of org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext in project flink by apache.

the class SourceCoordinatorTest method testUserClassLoaderWhenRestoringEnumerator.

@Test
public void testUserClassLoaderWhenRestoringEnumerator() throws Exception {
    final ClassLoader testClassLoader = new URLClassLoader(new URL[0]);
    final OperatorCoordinator.Context context = new MockOperatorCoordinatorContext(new OperatorID(), testClassLoader);
    final EnumeratorCreatingSource<?, ClassLoaderTestEnumerator> source = new EnumeratorCreatingSource<>(ClassLoaderTestEnumerator::new);
    final SourceCoordinatorProvider<?> provider = new SourceCoordinatorProvider<>("testOperator", context.getOperatorId(), source, 1, WatermarkAlignmentParams.WATERMARK_ALIGNMENT_DISABLED);
    final OperatorCoordinator coordinator = provider.getCoordinator(context);
    coordinator.resetToCheckpoint(1L, createEmptyCheckpoint());
    coordinator.start();
    final ClassLoaderTestEnumerator enumerator = source.restoreEnumeratorFuture.get();
    assertSame(testClassLoader, enumerator.constructorClassLoader);
    assertSame(testClassLoader, enumerator.threadClassLoader.get());
    // cleanup
    coordinator.close();
}
Also used : MockOperatorCoordinatorContext(org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext) URLClassLoader(java.net.URLClassLoader) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) URLClassLoader(java.net.URLClassLoader) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Test(org.junit.Test)

Example 5 with MockOperatorCoordinatorContext

use of org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext in project flink by apache.

the class SourceCoordinatorProviderTest method testCreate.

@Test
public void testCreate() throws Exception {
    OperatorCoordinator coordinator = provider.create(new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SPLITS));
    assertTrue(coordinator instanceof RecreateOnResetOperatorCoordinator);
}
Also used : MockOperatorCoordinatorContext(org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) Test(org.junit.Test)

Aggregations

MockOperatorCoordinatorContext (org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext)6 Test (org.junit.Test)5 OperatorCoordinator (org.apache.flink.runtime.operators.coordination.OperatorCoordinator)4 RecreateOnResetOperatorCoordinator (org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator)3 URLClassLoader (java.net.URLClassLoader)2 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 ReaderRegistrationEvent (org.apache.flink.runtime.source.event.ReaderRegistrationEvent)1 Before (org.junit.Before)1