-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Test for cancelled task in TransportSnapshotsStatusAction.buildResponse()
#126740
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
Conversation
…se() Testing for cancellation in buildResponse() avoids a lot of unnecessary processing in scenarios with many shards. Closes ES-10981.
Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I just have some superficial nits.
...elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusActionTests.java
Show resolved
Hide resolved
...elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusActionTests.java
Outdated
Show resolved
Hide resolved
...elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusActionTests.java
Outdated
Show resolved
Hide resolved
...elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusActionTests.java
Outdated
Show resolved
Hide resolved
assertNotNull(rsp); | ||
final var snapshotStatuses = rsp.getSnapshots(); | ||
assertNotNull(snapshotStatuses); | ||
assertEquals(1, snapshotStatuses.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the assertEquals
and assertTrue
, could you add debug info strings with some more information? There are versions of the methods that take a string as the first parameter. It should help with debugability. Otherwise I think this line failing would tell us that 1 doesn't equal 2, say, but not what the extra snapshot statuses are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we need some new toString
methods in order for the debug strings to be useful.
assertEquals(expectedState, snapshotStatus.getState()); | ||
final var snapshotStatusShards = snapshotStatus.getShards(); | ||
assertNotNull(snapshotStatusShards); | ||
assertEquals(1, snapshotStatusShards.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug string pls.
final var snapshotStatusIndices = snapshotStatus.getIndices(); | ||
assertNotNull(snapshotStatusIndices); | ||
assertEquals( | ||
"expected a single entry in snapshotStatusIndices instead of " + snapshotStatusIndices, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think I see a wrinkle I didn't anticipate. IIUC, SnapshotIndexStatus
doesn't have a toString
method defined, so it'll print out a class name + hash code? Not ideal.
SnapshotStatus
has a toString
method that takes advantage of the chunking interface, variations of which SnapshotIndexStatus
and SnapshotIndexShardStatus
also implement. So it might be easy to write something similar for them, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added toString()
methods for the relevant classes. The Strings.toString()
that takes a ChunkedToXContent
is deprecated. This form is the one that SnapshotStatus
is currently calling. In SnapshotStatusResponse
I used Strings.toString(ChunkedToXContent.wrapAsToXContent(this), true, true)
directly since the assumption is we are calling toString()
in scenarios where it would be reasonable to fully serialize to a String
. I also set the human
parameter to true
in all the new toString()
methods since toString()
is meant to be human readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Testing for cancellation in
buildResponse()
can avoid extra unnecessary processing in scenarios with many shards.Closes ES-10981.
This PR adds a
TransportSnapshotsStatusActionTests
unit test file to test this new functionality directly versus trying to modifying a higher level test likeSnapshotStatusApisIT
. The test code added is minimal, just focusing on the changes introduced in this PR.