Skip to content

Commit

Permalink
correctly serializing UpdateSettingsRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
masseyke committed Nov 9, 2023
1 parent ca6a87a commit 237eea2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ static TransportVersion def(int id) {
public static final TransportVersion UNDESIRED_SHARD_ALLOCATIONS_COUNT_ADDED = def(8_530_00_0);
public static final TransportVersion ML_INFERENCE_TASK_SETTINGS_OPTIONAL_ADDED = def(8_531_00_0);
public static final TransportVersion DEPRECATED_COMPONENT_TEMPLATES_ADDED = def(8_532_00_0);
public static final TransportVersion UPDATE_NON_DYNAMIC_SETTINGS_ADDED = def(8_533_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public UpdateSettingsRequest(StreamInput in) throws IOException {
if (in.getTransportVersion().onOrAfter(TransportVersions.V_7_12_0)) {
origin = in.readString();
}
if (in.getTransportVersion().onOrAfter(TransportVersions.UPDATE_NON_DYNAMIC_SETTINGS_ADDED)) {
reopen = in.readBoolean();
}
}

public UpdateSettingsRequest() {}
Expand Down Expand Up @@ -200,6 +203,9 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_12_0)) {
out.writeString(origin);
}
if (out.getTransportVersion().onOrAfter(TransportVersions.UPDATE_NON_DYNAMIC_SETTINGS_ADDED)) {
out.writeBoolean(reopen);
}
}

@Override
Expand Down Expand Up @@ -257,12 +263,13 @@ public boolean equals(Object o) {
&& Objects.equals(settings, that.settings)
&& Objects.equals(indicesOptions, that.indicesOptions)
&& Objects.equals(preserveExisting, that.preserveExisting)
&& Objects.equals(reopen, that.reopen)
&& Arrays.equals(indices, that.indices);
}

@Override
public int hashCode() {
return Objects.hash(masterNodeTimeout, timeout, settings, indicesOptions, preserveExisting, Arrays.hashCode(indices));
return Objects.hash(masterNodeTimeout, timeout, settings, indicesOptions, preserveExisting, reopen, Arrays.hashCode(indices));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected UpdateSettingsRequest mutateInstance(UpdateSettingsRequest request) {
)
);
mutators.add(() -> mutation.setPreserveExisting(request.isPreserveExisting() == false));
mutators.add(() -> mutation.reopen(request.reopen() == false));
randomFrom(mutators).run();
return mutation;
}
Expand All @@ -67,6 +68,7 @@ public static UpdateSettingsRequest createTestItem() {
request.timeout(randomTimeValue());
request.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
request.setPreserveExisting(randomBoolean());
request.reopen(randomBoolean());
return request;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ protected UpdateSettingsRequest createTestInstance() {

private static UpdateSettingsRequest createTestInstance(boolean enclosedSettings) {
UpdateSettingsRequest testRequest = UpdateSettingsRequestSerializationTests.createTestItem();
if (randomBoolean()) {
testRequest.reopen(true);
}
if (enclosedSettings) {
UpdateSettingsRequest requestWithEnclosingSettings = new UpdateSettingsRequest(testRequest.settings()) {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
Expand All @@ -75,6 +78,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}
};
requestWithEnclosingSettings.reopen(testRequest.reopen());
return requestWithEnclosingSettings;
}
return testRequest;
Expand Down

0 comments on commit 237eea2

Please sign in to comment.