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

Speed up integration tests. #2288

Merged
merged 3 commits into from
Dec 19, 2018

Conversation

big-andy-coates
Copy link
Contributor

@big-andy-coates big-andy-coates commented Dec 18, 2018

Description

Our integration tests were taking up 3/4s of our build time. So I spent a little time speeding them up.

  • Kafka clusters are now mostly per-class, rather than per-test.
  • I've found and fixed tests that incorrectly waiting for more messages than were being published.
  • I've added ConsumerGroupTestUtil to help tests to have unique consumer groups per test, so tests don't interact with each other.
  • I've added TopicTestUtil to help tests to have unique topic names per test.
  • I've added KsqlIndentifierTestUtil to help tests tp have unique KSQL identifiers, (think steam/table names), per test.
  • I've make IntergrationTestHarness a JUnit rule, so it can be used with @ClassRule.
  • I've make a TestKsqlContext, which is a JUnit rule, to simplify interacting with the KsqlContext.
  • I've added ConsumerTestUtil, which has lots of handy methods for consuming messages from Kafka and asserting if too few or too many are consumed.
  • I've refactored the integration tests to make use of the above new functionality.

So now, to have an integration test, all you really need is something like:

public class MyIntTest {

  private static final OrderDataProvider DATA_PROVIDER = new OrderDataProvider();

  @ClassRule
  public static final IntegrationTestHarness TEST_HARNESS = IntegrationTestHarness.build();

  @Rule
  public final TestKsqlContext ksqlContext = TEST_HARNESS.buildKsqlContext();

  private String sourceTopic;
  private String resultStream;

  @Before
  public void setUp() throws Exception {
    sourceTopic = TopicTestUtil.uniqueTopicName("source");
    resultStream = KsqlIdentifierTestUtil.uniqueIdentifierName("OUTPUT");

    TEST_HARNESS.produceRows(sourceTopic, DATA_PROVIDER, AVRO);
  }

  @Test
  public void should() {
    // Given:
    ksqlContext
        .sql("CREATE STREAM FOO WITH(KAFKA_TOPIC='" + sourceTopic + "', VALUE_FORMAT='AVRO');");

    // When:
    ksqlContext.sql("CREATE STREAM " + resultStream + " AS SELECT * FROM FOO;");

    // Then:
    TEST_HARNESS.verifyAvailableRows(resultStream, DATA_PROVIDER.data().size(), AVRO, DATA_PROVIDER.schema());
  }
}

The result of this work has brought build times mvn clean install down from something like:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21:37 min
[INFO] Finished at: 2018-12-18T16:03:45Z
[INFO] ------------------------------------------------------------------------

To

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 09:58 min
[INFO] Finished at: 2018-12-18T16:21:08Z
[INFO] ------------------------------------------------------------------------

Happy days.

note: One of the tests remains unstable. (The Window one I think). This still needs investigating.

Testing done

Test only change.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@big-andy-coates big-andy-coates requested a review from a team as a code owner December 18, 2018 16:52
Copy link
Contributor

@apurvam apurvam left a comment

Choose a reason for hiding this comment

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

great PR @big-andy-coates .. Will definitely boost productivity once merged.

I left a couple of comments, but this looks great besides those.

public MetaStore getMetaStore() {
return ksqlEngine.getMetaStore();
}

/**
* Execute the ksql statement in this context.
*/
public void sql(final String sql) {
sql(sql, Collections.emptyMap());
public List<QueryMetadata> sql(final String sql) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know we don't support embedded mode, but KsqlContext is the way to use embedded mode, right? If so, won't this break existing embedded mode users, especially if the rely on the return value being void, like:

   void someFunction() {
      return ksqlContext.sql(myQuery);
   }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't follow.

First off, I didn't think we'd really supported embedded mode as such. It's not documented anywhere that I'm aware of.

Second, how would they be relying on it returning void? Last time I checked:

void someFunction() {
      return ksqlContext.sql(myQuery);
   }

Will result in a compilation error, even if sql returns void.

I think you've been a manager too long!

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding return void types, that is my C++ instinct talking. This is in fact valid C++, but not valid Java:

void myFunction() {
  return;
}

void someOtherFunction() {
  return myFunction();
}

int main() {
  someOtherFunction();
  return 0;
}

Also, while we haven't officially advertised embedded mode, we have unofficially recommended it as an option people can use and pointed to internal integration tests as examples to follow.

If we are going to break it, I think it is definitely worth adding a release note to that effect at the very least.

However, given the above, I am not sure that this change breaks anything.

@big-andy-coates big-andy-coates requested a review from a team December 19, 2018 15:03
Copy link
Contributor

@apurvam apurvam left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@big-andy-coates
Copy link
Contributor Author

Test only change, so merging with one review...

@big-andy-coates big-andy-coates merged commit 27fa002 into confluentinc:master Dec 19, 2018
@big-andy-coates big-andy-coates deleted the int_tests branch December 19, 2018 23:58
hasnat added a commit to hasnat/ksql that referenced this pull request Dec 23, 2018
* fork/master: (107 commits)
  copy-edited (confluentinc#2299)
  copy-edited (confluentinc#2299)
  remove unused map from command store `getRestoreCommands` (confluentinc#2296)
  Speed up integration tests. (confluentinc#2288)
  Move KSQL Clickstream demo to Examples repo (confluentinc#2270)
  Bump Confluent to 5.1.1-SNAPSHOT, Kafka to 2.1.1-SNAPSHOT
  Set Confluent to 5.1.0, Kafka to 2.1.0-cp1.
  Add ServiceContext (confluentinc#2243)
  Update to use CCL (confluentinc#2278)
  Remove redundant intro sentence in README.md (confluentinc#2277)
  Switch to use CCL (confluentinc#2275)
  Update readme for CCL (confluentinc#2276)
  Minor: add Hamcrest matchers for KsqlRestException and KsqlErrorMessage (confluentinc#2273)
  Update per relicensing (confluentinc#2274)
  CP-584: 5.1.0 changelog (confluentinc#2267)
  add null checks to min, max, and count aggregates; call Math.min/max for consistency (confluentinc#2246)
  Return and accept command topic offsets via REST API (confluentinc#2159)
  MINOR: Fix bug encountered when restoring RUN SCRIPT command. (again) (confluentinc#2265)
  More improvements to the way the CLI handles inline comments in multi-line statements. (confluentinc#2241)
  Fix issue where Avro subject does not exist (confluentinc#2260)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants