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();
}
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());
}
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();
}
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();
}
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);
}
Aggregations