-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Adds Coordination Diagnostics Tests #142709
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
Merged
joshua-adams-1
merged 10 commits into
elastic:main
from
joshua-adams-1:coordination-diagnostics
Mar 10, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a5ca05
Add CoordinationDiagnostics Serializatation Tests
joshua-adams-1 4b1aa3e
Test fix
joshua-adams-1 5b01ec4
Test fix
joshua-adams-1 ce623b4
Add unit tests
joshua-adams-1 d8b61ee
[CI] Auto commit changes from spotless
0274d06
Merge branch 'main' into coordination-diagnostics
joshua-adams-1 0efa9db
Address Comments
joshua-adams-1 8b7c3b6
Merge branch 'coordination-diagnostics' of github.com:joshua-adams-1/…
joshua-adams-1 6d90e86
[CI] Auto commit changes from spotless
e29b0b1
Merge branch 'main' into coordination-diagnostics
joshua-adams-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...lasticsearch/cluster/coordination/CoordinationDiagnosticsDetailsWireSerializingTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.cluster.coordination; | ||
|
|
||
| import org.elasticsearch.cluster.node.DiscoveryNode; | ||
| import org.elasticsearch.cluster.node.DiscoveryNodeUtils; | ||
| import org.elasticsearch.common.UUIDs; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.common.transport.TransportAddress; | ||
| import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.elasticsearch.cluster.coordination.CoordinationDiagnosticsService.CoordinationDiagnosticsDetails; | ||
|
|
||
| /** | ||
| * Wire serialization tests for {@link CoordinationDiagnosticsDetails}. | ||
| */ | ||
| public class CoordinationDiagnosticsDetailsWireSerializingTests extends AbstractWireSerializingTestCase<CoordinationDiagnosticsDetails> { | ||
|
|
||
| @Override | ||
| protected Writeable.Reader<CoordinationDiagnosticsDetails> instanceReader() { | ||
| return CoordinationDiagnosticsDetails::new; | ||
| } | ||
|
|
||
| @Override | ||
| protected CoordinationDiagnosticsDetails createTestInstance() { | ||
| return randomCoordinationDiagnosticsDetails(); | ||
| } | ||
|
|
||
| @Override | ||
| protected CoordinationDiagnosticsDetails mutateInstance(CoordinationDiagnosticsDetails instance) throws IOException { | ||
| // Since CoordinationDiagnosticsDetails is a record, we don't need to check for equality | ||
| return null; | ||
| } | ||
|
|
||
| private DiscoveryNode randomDiscoveryNode() { | ||
| return DiscoveryNodeUtils.builder(UUIDs.randomBase64UUID(random())) | ||
| .name(randomAlphaOfLength(10)) | ||
| .ephemeralId(UUIDs.randomBase64UUID(random())) | ||
| .address(new TransportAddress(TransportAddress.META_ADDRESS, randomIntBetween(1, 65535))) | ||
| .build(); | ||
DiannaHohensee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private CoordinationDiagnosticsDetails randomCoordinationDiagnosticsDetails() { | ||
| DiscoveryNode currentMaster = randomBoolean() ? randomDiscoveryNode() : null; | ||
| List<DiscoveryNode> recentMasters = randomBoolean() ? randomList(0, 5, this::randomDiscoveryNode) : null; | ||
| String remoteExceptionMessage = randomBoolean() ? randomAlphaOfLengthBetween(0, 100) : null; | ||
| String remoteExceptionStackTrace = randomBoolean() ? randomAlphaOfLengthBetween(0, 200) : null; | ||
| Map<String, String> nodeToClusterFormationDescriptionMap = randomNodeToClusterFormationDescriptionMap(); | ||
| return new CoordinationDiagnosticsDetails( | ||
| currentMaster, | ||
| recentMasters, | ||
| remoteExceptionMessage, | ||
| remoteExceptionStackTrace, | ||
| nodeToClusterFormationDescriptionMap | ||
| ); | ||
| } | ||
|
|
||
| private Map<String, String> randomNodeToClusterFormationDescriptionMap() { | ||
| Map<String, String> nodeToClusterFormationDescriptionMap = new HashMap<>(); | ||
| int size = between(0, 5); | ||
| for (int i = 0; i < size; i++) { | ||
| nodeToClusterFormationDescriptionMap.put(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(0, 50)); | ||
| } | ||
| return nodeToClusterFormationDescriptionMap; | ||
| } | ||
| } | ||
83 changes: 83 additions & 0 deletions
83
...elasticsearch/cluster/coordination/CoordinationDiagnosticsResultWireSerializingTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.cluster.coordination; | ||
|
|
||
| import org.elasticsearch.cluster.node.DiscoveryNode; | ||
| import org.elasticsearch.cluster.node.DiscoveryNodeUtils; | ||
| import org.elasticsearch.common.UUIDs; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.common.transport.TransportAddress; | ||
| import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.elasticsearch.cluster.coordination.CoordinationDiagnosticsService.CoordinationDiagnosticsDetails; | ||
| import static org.elasticsearch.cluster.coordination.CoordinationDiagnosticsService.CoordinationDiagnosticsResult; | ||
| import static org.elasticsearch.cluster.coordination.CoordinationDiagnosticsService.CoordinationDiagnosticsStatus; | ||
|
|
||
| /** | ||
| * Wire serialization tests for {@link CoordinationDiagnosticsResult}. | ||
| */ | ||
| public class CoordinationDiagnosticsResultWireSerializingTests extends AbstractWireSerializingTestCase<CoordinationDiagnosticsResult> { | ||
|
|
||
| @Override | ||
| protected Writeable.Reader<CoordinationDiagnosticsResult> instanceReader() { | ||
| return CoordinationDiagnosticsResult::new; | ||
| } | ||
|
|
||
| @Override | ||
| protected CoordinationDiagnosticsResult createTestInstance() { | ||
| CoordinationDiagnosticsStatus status = randomFrom(CoordinationDiagnosticsStatus.values()); | ||
| String summary = randomAlphaOfLengthBetween(0, 200); | ||
| CoordinationDiagnosticsDetails details = randomCoordinationDiagnosticsDetails(); | ||
| return new CoordinationDiagnosticsResult(status, summary, details); | ||
| } | ||
|
|
||
| @Override | ||
| protected CoordinationDiagnosticsResult mutateInstance(CoordinationDiagnosticsResult instance) throws IOException { | ||
| // Since CoordinationDiagnosticsResult is a record, we don't need to check for equality | ||
| return null; | ||
| } | ||
|
|
||
| private DiscoveryNode randomDiscoveryNode() { | ||
| return DiscoveryNodeUtils.builder(UUIDs.randomBase64UUID(random())) | ||
| .name(randomAlphaOfLength(10)) | ||
| .ephemeralId(UUIDs.randomBase64UUID(random())) | ||
| .address(new TransportAddress(TransportAddress.META_ADDRESS, randomIntBetween(1, 65535))) | ||
| .build(); | ||
| } | ||
|
|
||
| private CoordinationDiagnosticsDetails randomCoordinationDiagnosticsDetails() { | ||
| DiscoveryNode currentMaster = randomBoolean() ? randomDiscoveryNode() : null; | ||
| List<DiscoveryNode> recentMasters = randomBoolean() ? randomList(0, 5, this::randomDiscoveryNode) : null; | ||
| String remoteExceptionMessage = randomBoolean() ? randomAlphaOfLengthBetween(0, 100) : null; | ||
| String remoteExceptionStackTrace = randomBoolean() ? randomAlphaOfLengthBetween(0, 200) : null; | ||
| Map<String, String> nodeToClusterFormationDescriptionMap = randomNodeToClusterFormationDescriptionMap(); | ||
| return new CoordinationDiagnosticsDetails( | ||
| currentMaster, | ||
| recentMasters, | ||
| remoteExceptionMessage, | ||
| remoteExceptionStackTrace, | ||
| nodeToClusterFormationDescriptionMap | ||
| ); | ||
| } | ||
|
|
||
| private Map<String, String> randomNodeToClusterFormationDescriptionMap() { | ||
| Map<String, String> nodeToClusterFormationDescriptionMap = new HashMap<>(); | ||
| int size = between(0, 5); | ||
| for (int i = 0; i < size; i++) { | ||
| nodeToClusterFormationDescriptionMap.put(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(0, 50)); | ||
| } | ||
| return nodeToClusterFormationDescriptionMap; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This patch is refactoring the pre-existing test, so this isn't new, but there is a comment (looks like you added a bit ago) that suggests there's no purpose in implementing mutateInstance for records with default equals() implementations.
I wonder if this logic should be removed, but I don't have much of an opinion. I didn't do code sleuthing, but it's possible that these objects were originally classes and later became records -- we've been slowly converting code to records where possible for a while, AIUI.
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.
Good catch! I was writing tests via an LLM and despite specifically requesting it didn't implement
mutateInstancefor records it went and did it anyways! Anyways, I think my job is safe for a while 😆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.
Ha, yeah, it did that to me recently, too. "AI" is a probabilistic stats model, i.e. technically random behavior 😅