Skip to content

Conversation

@zhengruifeng
Copy link
Contributor

What changes were proposed in this pull request?

Why are the changes needed?

Use doReturn() in those rare occasions when you cannot use when(Object)

when is preferred in the official doc https://javadoc.io/static/org.mockito/mockito-core/5.12.0/org/mockito/Mockito.html#when(T)

Does this PR introduce any user-facing change?

no, test-only

How was this patch tested?

ci

Was this patch authored or co-authored using generative AI tooling?

no

@cloud-fan
Copy link
Contributor

The AQE test failure is unrelated, thanks, merging to master/4.1!

@cloud-fan cloud-fan closed this in d14209c Nov 24, 2025
cloud-fan pushed a commit that referenced this pull request Nov 24, 2025
…ite`

### What changes were proposed in this pull request?

### Why are the changes needed?
> Use doReturn() in those rare occasions when you cannot use when(Object)

`when` is preferred in the official doc https://javadoc.io/static/org.mockito/mockito-core/5.12.0/org/mockito/Mockito.html#when(T)

### Does this PR introduce _any_ user-facing change?
no, test-only

### How was this patch tested?
ci

### Was this patch authored or co-authored using generative AI tooling?
no

Closes #53192 from zhengruifeng/spark_54115_test_followup.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit d14209c)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@zhengruifeng zhengruifeng deleted the spark_54115_test_followup branch November 24, 2025 23:07

val sorted = Seq(connectExecuteOp1T, connectExecuteOp2T, task1T, task2T)
.sorted(Utils.invokePrivate(threadInfoOrderingMethod()))
.sorted(Utils.threadInfoOrdering)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... this looks simple, but I was told to prefer using invokePrivate to avoid exposing private methods/fields, not sure which is the best practice for this case.

cc @LuciferYang for more inputs

Copy link
Contributor

Choose a reason for hiding this comment

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

private[spark] is not public.

Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to be a new piece of code from the 4.1 cycle rather than legacy code. If we also consider it acceptable for third-party libraries to use threadInfoOrdering within the spark package, then this modification is acceptable.

Copy link
Contributor

Choose a reason for hiding this comment

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

third-party lib can do whatever they want using reflection, the point is what Spark guarantees/promises. Apparently, there is no compatibility guarantee/promise for private[spark] APIs.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reasoning is correct.

huangxiaopingRD pushed a commit to huangxiaopingRD/spark that referenced this pull request Nov 25, 2025
…ite`

### What changes were proposed in this pull request?

### Why are the changes needed?
> Use doReturn() in those rare occasions when you cannot use when(Object)

`when` is preferred in the official doc https://javadoc.io/static/org.mockito/mockito-core/5.12.0/org/mockito/Mockito.html#when(T)

### Does this PR introduce _any_ user-facing change?
no, test-only

### How was this patch tested?
ci

### Was this patch authored or co-authored using generative AI tooling?
no

Closes apache#53192 from zhengruifeng/spark_54115_test_followup.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants