Skip to content

[improve][test] Refactor TestPulsarService to PulsarTestContext and add support for starting#19337

Merged
lhotari merged 1 commit into
apache:masterfrom
lhotari:lh-refactor-TestPulsarService
Jan 30, 2023
Merged

[improve][test] Refactor TestPulsarService to PulsarTestContext and add support for starting#19337
lhotari merged 1 commit into
apache:masterfrom
lhotari:lh-refactor-TestPulsarService

Conversation

@lhotari

@lhotari lhotari commented Jan 27, 2023

Copy link
Copy Markdown
Member

Motivation

This is a follow up on previous PRs (#19326, #19323) to refactor Pulsar unit tests to reduce mocking which causes flakiness since Mockito isn't thread safe.

There are 2 types of Pulsar unit tests that use a PulsarService:

  • Some Pulsar unit tests use a PulsarService that isn't started
  • Some Pulsar unit tests start the PulsarService and use less mocking

With the changes in this PR, the test framework will be suitable for use across a broader set of Pulsar unit tests and we can get rid of more of the problematic usages of Mockito.

Modifications

This PR refactors the previous TestPulsarService to PulsarTestContext which is more maintainable.
It supports both modes of PulsarServices, startable and non-startable.
OwnerShipForCurrentServerTestBase is used as piloting the new mode. More tests will be converted after this PR has been merged.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: lhotari#138

…dd support for starting

- Some Pulsar unit tests use a PulsarService that isn't started
- Some Pulsar unit tests start the PulsarService and use less mocking

- Support both modes in PulsarTestContext
  - Refactor OwnerShipForCurrentServerTestBase to use this new mode

@michaeljmarshall michaeljmarshall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall, LGTM. I left some comments/questions.

PulsarTestContext.startableBuilder()
.config(conf);
if (i > 0) {
testContextBuilder.reuseMockBookkeeperAndMetadataStores(pulsarTestContexts.get(0));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we getting the first one here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

PulsarTestContext holds the mock bookkeeper and metadata store (mockzookeeper) references. The "reuseMockBookkeeperAndMetadataStores" can be used to share the mock bookkeeper and zookeeper from another context.

@ToString
@Getter
@Builder(builderClassName = "Builder")
public class PulsarTestContext implements AutoCloseable {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A Javadoc explaining how to use this class would be valuable. Also, are you able to point out what of this class is new? I see that it is pretty similar to the TestPulsarService, and I know your PR description indicates that it is an improvement on TestPulsarService.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree. I can improve the documentation in a follow-up PR that I have in progress.

Comment on lines +50 to +54
/**
* Subclass of PulsarService that is used for some tests.
* This was written as a replacement for the previous Mockito Spy over PulsarService solution which caused
* a flaky test issue https://github.com/apache/pulsar/issues/13620.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see this was copied from TestPulsarService. Is there any new context we need in order to document how to use this class?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll update the docs in a follow-up PR.

@michaeljmarshall michaeljmarshall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks for addressing my questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants