Search in sources :

Example 1 with WarningsHandler

use of org.opensearch.client.WarningsHandler in project OpenSearch by opensearch-project.

the class VersionSensitiveWarningsHandlerTests method testSameVersionCluster.

public void testSameVersionCluster() throws IOException {
    Set<Version> nodeVersions = new HashSet<>();
    nodeVersions.add(Version.CURRENT);
    WarningsHandler handler = expectVersionSpecificWarnings(nodeVersions, (v) -> {
        v.current("expectedCurrent1");
    });
    assertFalse(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1")));
    assertTrue(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1", "unexpected")));
    assertFalse(handler.warningsShouldFailRequest(Collections.emptyList()));
}
Also used : Version(org.opensearch.Version) WarningsHandler(org.opensearch.client.WarningsHandler) VersionSensitiveWarningsHandler(org.opensearch.test.rest.OpenSearchRestTestCase.VersionSensitiveWarningsHandler) HashSet(java.util.HashSet)

Example 2 with WarningsHandler

use of org.opensearch.client.WarningsHandler in project OpenSearch by opensearch-project.

the class VersionSensitiveWarningsHandlerTests method testMixedVersionCluster.

public void testMixedVersionCluster() throws IOException {
    Set<Version> nodeVersions = new HashSet<>();
    nodeVersions.add(Version.CURRENT);
    nodeVersions.add(Version.CURRENT.minimumIndexCompatibilityVersion());
    WarningsHandler handler = expectVersionSpecificWarnings(nodeVersions, (v) -> {
        v.current("expectedCurrent1");
        v.compatible("Expected legacy warning");
    });
    assertFalse(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1")));
    assertFalse(handler.warningsShouldFailRequest(Arrays.asList("Expected legacy warning")));
    assertFalse(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1", "Expected legacy warning")));
    assertTrue(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1", "Unexpected legacy warning")));
    assertTrue(handler.warningsShouldFailRequest(Arrays.asList("Unexpected legacy warning")));
    assertFalse(handler.warningsShouldFailRequest(Collections.emptyList()));
}
Also used : Version(org.opensearch.Version) WarningsHandler(org.opensearch.client.WarningsHandler) VersionSensitiveWarningsHandler(org.opensearch.test.rest.OpenSearchRestTestCase.VersionSensitiveWarningsHandler) HashSet(java.util.HashSet)

Example 3 with WarningsHandler

use of org.opensearch.client.WarningsHandler in project OpenSearch by opensearch-project.

the class OpenSearchRestTestCase method allowTypesRemovalWarnings.

/**
 * Creates RequestOptions designed to ignore [types removal] warnings but nothing else
 * @deprecated this method is only required while we deprecate types and can be removed in 8.0
 */
@Deprecated
public static RequestOptions allowTypesRemovalWarnings() {
    Builder builder = RequestOptions.DEFAULT.toBuilder();
    builder.setWarningsHandler(new WarningsHandler() {

        @Override
        public boolean warningsShouldFailRequest(List<String> warnings) {
            for (String warning : warnings) {
                if (warning.startsWith("[types removal]") == false) {
                    // Something other than a types removal message - return true
                    return true;
                }
            }
            return false;
        }
    });
    return builder.build();
}
Also used : RestClientBuilder(org.opensearch.client.RestClientBuilder) Builder(org.opensearch.client.RequestOptions.Builder) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) WarningsHandler(org.opensearch.client.WarningsHandler)

Aggregations

WarningsHandler (org.opensearch.client.WarningsHandler)3 HashSet (java.util.HashSet)2 Version (org.opensearch.Version)2 VersionSensitiveWarningsHandler (org.opensearch.test.rest.OpenSearchRestTestCase.VersionSensitiveWarningsHandler)2 Builder (org.opensearch.client.RequestOptions.Builder)1 RestClientBuilder (org.opensearch.client.RestClientBuilder)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1