use of org.apache.flink.streaming.connectors.kinesis.testutils.TestableKinesisDataFetcherForShardConsumerException in project flink by apache.
the class KinesisDataFetcherTest method testOriginalExceptionIsPreservedWhenInterruptedDuringShutdown.
@Test
public void testOriginalExceptionIsPreservedWhenInterruptedDuringShutdown() throws Exception {
String stream = "fakeStream";
Map<String, List<BlockingQueue<String>>> streamsToShardQueues = new HashMap<>();
LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>(10);
queue.put("item1");
streamsToShardQueues.put(stream, singletonList(queue));
AlwaysThrowsDeserializationSchema deserializationSchema = new AlwaysThrowsDeserializationSchema();
KinesisProxyInterface fakeKinesis = FakeKinesisBehavioursFactory.blockingQueueGetRecords(streamsToShardQueues);
TestableKinesisDataFetcherForShardConsumerException<String> fetcher = new TestableKinesisDataFetcherForShardConsumerException<>(singletonList(stream), new TestSourceContext<>(), TestUtils.getStandardProperties(), new KinesisDeserializationSchemaWrapper<>(deserializationSchema), 10, 2, new AtomicReference<>(), new LinkedList<>(), new HashMap<>(), fakeKinesis, (sequence, properties, metricGroup, streamShardHandle) -> mock(RecordPublisher.class));
DummyFlinkKinesisConsumer<String> consumer = new DummyFlinkKinesisConsumer<>(TestUtils.getStandardProperties(), fetcher, 1, 0);
CheckedThread consumerThread = new CheckedThread("FlinkKinesisConsumer") {
@Override
public void go() throws Exception {
consumer.run(new TestSourceContext<>());
}
};
consumerThread.start();
fetcher.waitUntilRun();
// ShardConsumer exception (from deserializer) will result in fetcher being shut down.
fetcher.waitUntilShutdown(20, TimeUnit.SECONDS);
// Ensure that KinesisDataFetcher has exited its while(running) loop and is inside its
// awaitTermination()
// method before we interrupt its thread, so that our interrupt doesn't get absorbed by any
// other mechanism.
fetcher.waitUntilAwaitTermination(20, TimeUnit.SECONDS);
// Interrupt the thread so that KinesisDataFetcher#awaitTermination() will throw
// InterruptedException.
consumerThread.interrupt();
try {
consumerThread.sync();
} catch (InterruptedException e) {
fail("Expected exception from deserializer, but got InterruptedException, probably from " + "KinesisDataFetcher, which obscures the cause of the failure. " + e);
} catch (RuntimeException e) {
if (!e.getMessage().equals(AlwaysThrowsDeserializationSchema.EXCEPTION_MESSAGE)) {
fail("Expected exception from deserializer, but got: " + e);
}
} catch (Exception e) {
fail("Expected exception from deserializer, but got: " + e);
}
assertTrue("Expected Fetcher to have been interrupted. This test didn't accomplish its goal.", fetcher.wasInterrupted);
}
Aggregations