GitHub user tzulitai opened a pull request:
https://github.com/apache/flink/pull/5188
[FLINK-8296] [kafka] Rework FlinkKafkaConsumerBaseTest to not rely on Java
reflection
## What is the purpose of the change
Prior to this PR, reflection was mainly used to inject mocks into private
fields of the `FlinkKafkaConsumerBase`, without the need to fully execute all
operator life cycle methods.
This was done using the `FlinkKafkaConsumerBaseTest::getConsumer(...)`
method (have been removed by this PR). This, however, caused the unit tests to
be too implementation-specific and hard to extend.
This PR reworks the `FlinkKafkaConsumerBaseTest` to remove the
reflection-based `FlinkKafkaConsumerBaseTest::getConsumer(...)` method.
All tests now instantiate the `DummyFlinkKafkaConsumer` normally, and let
all tests properly execute all operator life cycle methods regardless of the
tested logic.
## Brief change log
- Remove reflection-relying `FlinkKafkaConsumerBaseTest::getConsumer(...)`
method.
- Generalize the `DummyFlinkKafkaConsumer` class
- Introduce the `FlinkKafkaConsumerBaseTest::setupConsumer(...)` method
that iterates through all normal operator life cycle methods.
- The test pattern for all unit tests in the `FlinkKafkaConsumerBaseTest`
is now: 1) instantiate a `DummyFlinkKafkaConsumer`, and 2) call
`setupConsumer(dummyConsumer)` to make sure the consumer goes through all life
cycle methods, and instance fields are properly instantiated (instead of
relying on reflection like before).
## Verifying this change
Test coverage of the reworked `FlinkKafkaConsumerBaseTest` has not been
touched.
That unit test verifies this change.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? n/a
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/tzulitai/flink FLINK-8296
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/flink/pull/5188.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #5188
commit 620d500b1a14f8f5016e56fdc3d65d853ce8848d
Author: Tzu-Li (Gordon) Tai
Date: 2017-12-20T00:10:44Z
[FLINK-8296] [kafka] Rework FlinkKafkaConsumerBaseTest to not rely on Java
reflection
Reflection was mainly used to inject mocks into private fields of the
FlinkKafkaConsumerBase, without the need to fully execute all operator
life cycle methods. This, however, caused the unit tests to be too
implementation-specific.
This commit reworks the FlinkKafkaConsumerBaseTest to remove test
consumer instantiation methods that rely on reflection for dependency
injection. All tests now instantiate dummy test consumers normally, and
let all tests properly execute all operator life cycle methods
regardless of the tested logic.
---