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

Added more unit tests to the JavaInstanceTest class #10369

Merged
merged 2 commits into from
May 14, 2021

Conversation

david-streamlio
Copy link
Contributor

Motivation

Adding some more unit tests for the JavaInstance class, and doing a sanity check to see if a simple PR is able to build successfully in the OSS environment.

Modifications

Added more unit tests for the JavaInstanceTest class, that's it, nothing else.

Verifying this change

This change is the addition of new unit tests to an existing Test class

Does this pull request potentially affect one of the following parts:

No

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (not applicable)
  • If a feature is not applicable for documentation, explain why? I am just adding new unit tests

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

I like like approach of adding tests before changing the behaviour.
Great idea!

I left some feedback PTAL

String testString = "ABC123";
CompletableFuture<JavaExecutionResult> result = instance.handleMessage(mock(Record.class), testString);
assertNull(result.get().getResult());
assertNotNull(result.get().getUserException());
Copy link
Contributor

Choose a reason for hiding this comment

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

What about using assertSame? And test about the absence or presence of wrapper?

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 have updated the code to use assertSame

CompletableFuture<String> result = new CompletableFuture<>();
executor.submit(() -> {
try {
Thread.sleep(500);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need this sleep?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just being consistent with the behavior of the other Async function tests

String testString = "ABC123";
CompletableFuture<JavaExecutionResult> result = instance.handleMessage(mock(Record.class), testString);
assertNull(result.get().getResult());
// TODO Change this
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not leave TODOs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

log.info("input string: {}", input);
CompletableFuture<String> result = new CompletableFuture<>();
executor.submit(() -> {
result.completeExceptionally(new InterruptedException(""));
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably this is not the best way to simulate this.
You may set Thread.currentThread().interrupt() or better, call Thread.interrupt.
But I am not sure it is worth to make it so complicated WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The call to completeExceptionally is required in order for the test to complete, any other approach, such as just throwing and exception results in the test hanging.

@jerrypeng jerrypeng dismissed eolivelli’s stale review May 14, 2021 16:47

review is stale for a while

@jerrypeng jerrypeng merged commit c4098d6 into apache:master May 14, 2021
codelipenghui pushed a commit that referenced this pull request May 21, 2021
@codelipenghui
Copy link
Contributor

Depends by #10618, cherry-pick this PR to branch-2.7

eolivelli pushed a commit to datastax/pulsar that referenced this pull request May 21, 2021
(cherry picked from commit c4098d6)
(cherry picked from commit 881d94a)
eolivelli pushed a commit to datastax/pulsar that referenced this pull request May 21, 2021
(cherry picked from commit c4098d6)
(cherry picked from commit 881d94a)
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.

None yet

5 participants