Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelandis committed Sep 30, 2024
1 parent c428123 commit a7f036d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,17 +477,23 @@ public void testDeprecationWarnMessagesCanBeIndexed() throws Exception {

}

//TODO: check headers too!
public void testDeprecateAndKeep() throws Exception {
final Request request = new Request("GET", "/_test_cluster/deprecated_but_dont_remove");
request.setEntity(buildSettingsRequest(Collections.singletonList(TEST_NOT_DEPRECATED_SETTING), "settings"));
performScopedRequest(request);
Response response = performScopedRequest(request);

final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
assertThat(
extractWarningValuesFromWarningHeaders(deprecatedWarnings),
containsInAnyOrder("[/_test_cluster/deprecated_but_dont_remove] is deprecated, but no plans to remove quite yet")
);

assertBusy(() -> {
List<Map<String, Object>> documents = DeprecationTestUtils.getIndexedDeprecations(client(), xOpaqueId());

logger.warn(documents);

//only assert the relevant fields: level, message, and category
// only assert the relevant fields: level, message, and category
assertThat(
documents,
containsInAnyOrder(
Expand All @@ -504,7 +510,13 @@ public void testDeprecateAndKeep() throws Exception {
public void testReplacesInCurrentVersion() throws Exception {
final Request request = new Request("GET", "/_test_cluster/old_name1"); // deprecated in current version
request.setEntity(buildSettingsRequest(Collections.singletonList(TEST_NOT_DEPRECATED_SETTING), "settings"));
performScopedRequest(request);
Response response = performScopedRequest(request);

final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
assertThat(
extractWarningValuesFromWarningHeaders(deprecatedWarnings),
containsInAnyOrder("[GET /_test_cluster/old_name1] is deprecated! Use [GET /_test_cluster/new_name1] instead.")
);

assertBusy(() -> {
List<Map<String, Object>> documents = DeprecationTestUtils.getIndexedDeprecations(client(), xOpaqueId());
Expand All @@ -526,24 +538,30 @@ public void testReplacesInCurrentVersion() throws Exception {
}

public void testReplacesInCompatibleVersion() throws Exception {
final Request request = new Request("GET", "/_test_cluster/old_name2"); //deprecated in minimum supported version
final Request request = new Request("GET", "/_test_cluster/old_name2"); // deprecated in minimum supported version
request.setEntity(buildSettingsRequest(Collections.singletonList(TEST_DEPRECATED_SETTING_TRUE1), "deprecated_settings"));
final RequestOptions compatibleOptions = request.getOptions()
.toBuilder()
.addHeader("Accept", "application/vnd.elasticsearch+json;compatible-with=" + RestApiVersion.minimumSupported().major)
.addHeader("Content-Type", "application/vnd.elasticsearch+json;compatible-with=" + RestApiVersion.minimumSupported().major)
.build();
request.setOptions(compatibleOptions);
performScopedRequest(request);

//check for 2 headers
Response response = performScopedRequest(request);

final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
assertThat(
extractWarningValuesFromWarningHeaders(deprecatedWarnings),
containsInAnyOrder(
"[GET /_test_cluster/old_name2] is deprecated! Use [GET /_test_cluster/new_name2] instead.",
"You are using a compatible API for this request"
)
);
assertBusy(() -> {
List<Map<String, Object>> documents = DeprecationTestUtils.getIndexedDeprecations(client(), xOpaqueId());

logger.warn(documents);

//only assert the relevant fields: level, message, and category
// only assert the relevant fields: level, message, and category
assertThat(
documents,
containsInAnyOrder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,19 @@ public List<Route> routes() {
Route.builder(GET, "/_test_cluster/deprecated_settings")
.deprecatedForRemoval(DEPRECATED_ENDPOINT, RestApiVersion.current())
.build(),
//TODO: s/deprecated/deprecatedForRemoval when removing `deprecated` method
// TODO: s/deprecated/deprecatedForRemoval when removing `deprecated` method
Route.builder(POST, "/_test_cluster/deprecated_settings").deprecated(DEPRECATED_ENDPOINT, RestApiVersion.current()).build(),
Route.builder(GET, "/_test_cluster/compat_only")
.deprecatedForRemoval(DEPRECATED_ENDPOINT, RestApiVersion.minimumSupported()).build(),
.deprecatedForRemoval(DEPRECATED_ENDPOINT, RestApiVersion.minimumSupported())
.build(),
Route.builder(GET, "/_test_cluster/only_deprecated_setting").build(),
Route.builder(GET, "/_test_cluster/deprecated_but_dont_remove")
.deprecateAndKeep("[/_test_cluster/deprecated_but_dont_remove] is deprecated, but no plans to remove quite yet").build(),
Route.builder(GET, "/_test_cluster/new_name1")
.replaces(GET, "/_test_cluster/old_name1", RestApiVersion.current()).build(),
.deprecateAndKeep("[/_test_cluster/deprecated_but_dont_remove] is deprecated, but no plans to remove quite yet")
.build(),
Route.builder(GET, "/_test_cluster/new_name1").replaces(GET, "/_test_cluster/old_name1", RestApiVersion.current()).build(),
Route.builder(GET, "/_test_cluster/new_name2")
.replaces(GET, "/_test_cluster/old_name2", RestApiVersion.minimumSupported()).build()
.replaces(GET, "/_test_cluster/old_name2", RestApiVersion.minimumSupported())
.build()

);
}
Expand Down

0 comments on commit a7f036d

Please sign in to comment.