Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-5671 Followup: Remove reflections in unit test classes #3603

Closed

Conversation

guozhangwang
Copy link
Contributor

@guozhangwang guozhangwang commented Aug 1, 2017

  1. Remove rest deprecation warnings in streams:jar.

  2. Consolidate all unit test classes' reflections to access internal topology builder from packages other than o.a.k.streams. We need to refactor the hierarchies of StreamTask, StreamThread and KafkaStreams to remove these hacky reflections.

  3. Minor fixes such as reference path, etc.

  4. Minor edits on web docs for the describe function under developer-guide.

@guozhangwang
Copy link
Contributor Author

@dguy @bbejeck @mjsax to review.

@asfgit
Copy link

asfgit commented Aug 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6453/
Test FAILed (JDK 7 and Scala 2.11).

@asfgit
Copy link

asfgit commented Aug 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6438/
Test FAILed (JDK 8 and Scala 2.12).

@asfgit
Copy link

asfgit commented Aug 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6458/
Test PASSed (JDK 7 and Scala 2.11).

@asfgit
Copy link

asfgit commented Aug 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6443/
Test PASSed (JDK 8 and Scala 2.12).

@@ -51,17 +50,17 @@
* @deprecated Use {@link org.apache.kafka.streams.StreamsBuilder StreamsBuilder} instead
*/
@Deprecated
public class KStreamBuilder extends TopologyBuilder {
public class KStreamBuilder extends org.apache.kafka.streams.processor.TopologyBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid importing the org.apache.kafka.streams.processor.TopologyBuilder which will introduce a WARNING during compilation; instead we will explicitly refer to the class within the class whenever we have to.

*/
@SuppressWarnings("deprecation")
@Override
public StateStore getStateStore(final String name) {
if (currentNode() == null) {
throw new TopologyBuilderException("Accessing from an unknown node");
throw new org.apache.kafka.streams.errors.TopologyBuilderException("Accessing from an unknown node");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto above.

@@ -78,4 +72,24 @@ public static Properties minimalStreamsConfig() {
return results;
}

// TODO: these three static functions are added because some non-TopologyBuilder unit tests need to access the internal topology builder,
// which is usually a bad sign of design patterns between TopologyBuilder and StreamThread. We need to consider getting rid of them later
public static InternalTopologyBuilder internalTopologyBuilder(final StreamsBuilder streamsBuilder) throws NoSuchFieldException, IllegalAccessException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and the next method. Can we wrap them with:

try {
.../
}catch(final Exception e) {
  throw new RuntimeException(e);
}

We can then get rig of the throws Exception from all the tests and from the KStreamTestDriver

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to use reflection? Can we not add a test class in the same package that exposes a package private field as public? When exploring the codebase is very useful to be able to see callers and reflection kills that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijuma that is possible. We'd need a couple of test helper classes in the appropriate packages, one for StreamBuilder and one for InternalStreamsBuilder. We'd also need to make internalTopologyBuilder on StreamsBuilder package private.

@guozhangwang
Copy link
Contributor Author

@dguy Comments addressed, could you review again?

@asfgit
Copy link

asfgit commented Aug 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6460/
Test FAILed (JDK 8 and Scala 2.12).

@asfgit
Copy link

asfgit commented Aug 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6475/
Test PASSed (JDK 7 and Scala 2.11).

@bbejeck
Copy link
Contributor

bbejeck commented Aug 1, 2017

@guozhangwang @dguy: sorry I'm a little late with this but I was thinking instead of a static helper class we used a wrapper class instead, something like:

 package org.apache.kafka.streams;

 public final class TestingStreamsBuilderWrapper extends StreamsBuilder {

    private final StreamsBuilder delegate;

    public TestingStreamsBuilderWrapper(StreamsBuilder delegate) {
        this.delegate = delegate;
    }

    public InternalTopologyBuilder getInternalTopologyBuilder() {
         return delegate.internalTopologyBuilder;
    }

    public InternalStreamsBuilder getInternalStreamsBuilder() {
        return delegate.internalStreamsBuilder;
    }

IMHO using this as a drop in replacement for StreamsBuilder might make the current tests easier to follow and subsequent tests easier to write.

@guozhangwang
Copy link
Contributor Author

retest this please.

@guozhangwang
Copy link
Contributor Author

@bbejeck The issue is that internalTopologyBuilder is a package-private field of InternalStreamsBuilder and internalStreamsBuilder is a package-private field of StreamsBuilder, which are in o.a.k.streams.kstream.internals and o.a.k.streams respectively. So if your helper class in only in o.a.k.streams it will not be able to access the first field.

@bbejeck
Copy link
Contributor

bbejeck commented Aug 1, 2017

@guozhangwang that's right, we'd need to add an additional helper class, let me know if you think the idea has legs, otherwise I'll just leave it as is.

@asfgit
Copy link

asfgit commented Aug 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6481/
Test PASSed (JDK 7 and Scala 2.11).

@guozhangwang
Copy link
Contributor Author

@bbejeck In my latest commit I'm doing similar things but in an existing class than adding additional helper classes. LMK if you find that's good enough.

@asfgit
Copy link

asfgit commented Aug 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6466/
Test PASSed (JDK 8 and Scala 2.12).

@asfgit
Copy link

asfgit commented Aug 2, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6486/
Test FAILed (JDK 7 and Scala 2.11).

@asfgit
Copy link

asfgit commented Aug 2, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6471/
Test FAILed (JDK 8 and Scala 2.12).

Copy link
Contributor

@dguy dguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @guozhangwang, LGTM.
I wonder if we should move the utility methods to get the InternalTopologyBuilder etc onto XXUtils classes rather than having them on specific Test classes? I don't have a strong opinion on this, so i'll leave it up to you to decide. Feel free to merge as is

@dguy
Copy link
Contributor

dguy commented Aug 2, 2017

@bbejeck that is what i was thinking, but we need to have at least a couple of helper classes in the appropriate packages (which is fine). I'm ok with how it is, though. TBH i'm not a big fan of either approach, but it is where we are at for the time being.

@dguy
Copy link
Contributor

dguy commented Aug 2, 2017

retest this please

@asfgit
Copy link

asfgit commented Aug 2, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/6493/
Test PASSed (JDK 7 and Scala 2.11).

@asfgit
Copy link

asfgit commented Aug 2, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/6478/
Test PASSed (JDK 8 and Scala 2.12).

@bbejeck
Copy link
Contributor

bbejeck commented Aug 2, 2017

@guozhangwang yeah that works for me.

LGTM

@bbejeck
Copy link
Contributor

bbejeck commented Aug 2, 2017

@dguy agreed on both approaches, but for now we're not relying on reflection which is the important part IMHO.

@guozhangwang
Copy link
Contributor Author

I think it is okay to keep it in the specific test class than creating two more XXTestUtil classes.

@guozhangwang
Copy link
Contributor Author

Merged to trunk.

@asfgit asfgit closed this in 125d69c Aug 2, 2017
@guozhangwang guozhangwang deleted the K5671-followup-comments branch November 6, 2017 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants