Search in sources :

Example 1 with Strings

use of org.opensearch.common.Strings in project OpenSearch by opensearch-project.

the class IndexNameExpressionResolverTests method testIndexAliases.

public void testIndexAliases() {
    Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test-0").state(State.OPEN).putAlias(AliasMetadata.builder("test-alias-0").filter("{ \"term\": \"foo\"}")).putAlias(AliasMetadata.builder("test-alias-1").filter("{ \"term\": \"foo\"}")).putAlias(AliasMetadata.builder("test-alias-non-filtering")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
    Set<String> resolvedExpressions = indexNameExpressionResolver.resolveExpressions(state, "test-*");
    String[] strings = indexNameExpressionResolver.indexAliases(state, "test-0", x -> true, true, resolvedExpressions);
    Arrays.sort(strings);
    assertArrayEquals(new String[] { "test-alias-0", "test-alias-1", "test-alias-non-filtering" }, strings);
    strings = indexNameExpressionResolver.indexAliases(state, "test-0", x -> x.alias().equals("test-alias-1"), true, resolvedExpressions);
    assertArrayEquals(null, strings);
}
Also used : Matchers.arrayContaining(org.hamcrest.Matchers.arrayContaining) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) Arrays(java.util.Arrays) State(org.opensearch.cluster.metadata.IndexMetadata.State) Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) DocWriteRequest(org.opensearch.action.DocWriteRequest) Version(org.opensearch.Version) IndicesOptions(org.opensearch.action.support.IndicesOptions) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Function(java.util.function.Function) INDEX_HIDDEN_SETTING(org.opensearch.cluster.metadata.IndexMetadata.INDEX_HIDDEN_SETTING) Matchers.arrayContainingInAnyOrder(org.hamcrest.Matchers.arrayContainingInAnyOrder) Strings(org.opensearch.common.Strings) HashSet(java.util.HashSet) Sets.newHashSet(org.opensearch.common.util.set.Sets.newHashSet) IndicesRequest(org.opensearch.action.IndicesRequest) ClusterState(org.opensearch.cluster.ClusterState) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) IndexClosedException(org.opensearch.indices.IndexClosedException) DataStreamTestHelper.createBackingIndex(org.opensearch.cluster.DataStreamTestHelper.createBackingIndex) SearchRequest(org.opensearch.action.search.SearchRequest) EnumSet(java.util.EnumSet) DeleteRequest(org.opensearch.action.delete.DeleteRequest) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Index(org.opensearch.index.Index) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) Collectors(java.util.stream.Collectors) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) InvalidIndexNameException(org.opensearch.indices.InvalidIndexNameException) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) IndexSettings(org.opensearch.index.IndexSettings) ClusterName(org.opensearch.cluster.ClusterName) UpdateRequest(org.opensearch.action.update.UpdateRequest) Matchers.is(org.hamcrest.Matchers.is) IndexRequest(org.opensearch.action.index.IndexRequest) Comparator(java.util.Comparator) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.endsWith(org.hamcrest.Matchers.endsWith) DataStreamTestHelper.createTimestampField(org.opensearch.cluster.DataStreamTestHelper.createTimestampField) SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY(org.opensearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY) ClusterState(org.opensearch.cluster.ClusterState) ClusterName(org.opensearch.cluster.ClusterName) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 2 with Strings

use of org.opensearch.common.Strings in project OpenSearch by opensearch-project.

the class NumberFieldMapperTests method testOutOfRangeValues.

public void testOutOfRangeValues() throws IOException {
    final List<OutOfRangeSpec> inputs = Arrays.asList(OutOfRangeSpec.of(NumberType.BYTE, "128", "is out of range for a byte"), OutOfRangeSpec.of(NumberType.SHORT, "32768", "is out of range for a short"), OutOfRangeSpec.of(NumberType.INTEGER, "2147483648", "is out of range for an integer"), OutOfRangeSpec.of(NumberType.LONG, "9223372036854775808", "out of range for a long"), OutOfRangeSpec.of(NumberType.LONG, "1e999999999", "out of range for a long"), OutOfRangeSpec.of(NumberType.BYTE, "-129", "is out of range for a byte"), OutOfRangeSpec.of(NumberType.SHORT, "-32769", "is out of range for a short"), OutOfRangeSpec.of(NumberType.INTEGER, "-2147483649", "is out of range for an integer"), OutOfRangeSpec.of(NumberType.LONG, "-9223372036854775809", "out of range for a long"), OutOfRangeSpec.of(NumberType.LONG, "-1e999999999", "out of range for a long"), OutOfRangeSpec.of(NumberType.BYTE, 128, "is out of range for a byte"), OutOfRangeSpec.of(NumberType.SHORT, 32768, "out of range of Java short"), OutOfRangeSpec.of(NumberType.INTEGER, 2147483648L, " out of range of int"), OutOfRangeSpec.of(NumberType.LONG, new BigInteger("9223372036854775808"), "out of range of long"), OutOfRangeSpec.of(NumberType.BYTE, -129, "is out of range for a byte"), OutOfRangeSpec.of(NumberType.SHORT, -32769, "out of range of Java short"), OutOfRangeSpec.of(NumberType.INTEGER, -2147483649L, " out of range of int"), OutOfRangeSpec.of(NumberType.LONG, new BigInteger("-9223372036854775809"), "out of range of long"), OutOfRangeSpec.of(NumberType.HALF_FLOAT, "65520", "[half_float] supports only finite values"), OutOfRangeSpec.of(NumberType.FLOAT, "3.4028235E39", "[float] supports only finite values"), OutOfRangeSpec.of(NumberType.DOUBLE, "1.7976931348623157E309", "[double] supports only finite values"), OutOfRangeSpec.of(NumberType.HALF_FLOAT, "-65520", "[half_float] supports only finite values"), OutOfRangeSpec.of(NumberType.FLOAT, "-3.4028235E39", "[float] supports only finite values"), OutOfRangeSpec.of(NumberType.DOUBLE, "-1.7976931348623157E309", "[double] supports only finite values"), OutOfRangeSpec.of(NumberType.HALF_FLOAT, Float.NaN, "[half_float] supports only finite values"), OutOfRangeSpec.of(NumberType.FLOAT, Float.NaN, "[float] supports only finite values"), OutOfRangeSpec.of(NumberType.DOUBLE, Double.NaN, "[double] supports only finite values"), OutOfRangeSpec.of(NumberType.HALF_FLOAT, Float.POSITIVE_INFINITY, "[half_float] supports only finite values"), OutOfRangeSpec.of(NumberType.FLOAT, Float.POSITIVE_INFINITY, "[float] supports only finite values"), OutOfRangeSpec.of(NumberType.DOUBLE, Double.POSITIVE_INFINITY, "[double] supports only finite values"), OutOfRangeSpec.of(NumberType.HALF_FLOAT, Float.NEGATIVE_INFINITY, "[half_float] supports only finite values"), OutOfRangeSpec.of(NumberType.FLOAT, Float.NEGATIVE_INFINITY, "[float] supports only finite values"), OutOfRangeSpec.of(NumberType.DOUBLE, Double.NEGATIVE_INFINITY, "[double] supports only finite values"));
    for (OutOfRangeSpec item : inputs) {
        DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", item.type.typeName())));
        try {
            mapper.parse(source(item::write));
            fail("Mapper parsing exception expected for [" + item.type + "] with value [" + item.value + "]");
        } catch (MapperParsingException e) {
            assertThat("Incorrect error message for [" + item.type + "] with value [" + item.value + "]", e.getCause().getMessage(), containsString(item.message));
        }
    }
    // the following two strings are in-range for a long after coercion
    DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "long")));
    ParsedDocument doc = mapper.parse(source(b -> b.field("field", "9223372036854775807.9")));
    assertThat(doc.rootDoc().getFields("field"), arrayWithSize(2));
    doc = mapper.parse(source(b -> b.field("field", "-9223372036854775808.9")));
    assertThat(doc.rootDoc().getFields("field"), arrayWithSize(2));
}
Also used : Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) Arrays(java.util.Arrays) IndexableField(org.apache.lucene.index.IndexableField) Set(java.util.Set) IOException(java.io.IOException) Strings(org.opensearch.common.Strings) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) List(java.util.List) OutOfRangeSpec(org.opensearch.index.mapper.NumberFieldTypeTests.OutOfRangeSpec) DocValuesType(org.apache.lucene.index.DocValuesType) BytesArray(org.opensearch.common.bytes.BytesArray) NumberType(org.opensearch.index.mapper.NumberFieldMapper.NumberType) XContentType(org.opensearch.common.xcontent.XContentType) BigInteger(java.math.BigInteger) Matchers.containsString(org.hamcrest.Matchers.containsString) TermVectorsService(org.opensearch.index.termvectors.TermVectorsService) BigInteger(java.math.BigInteger) OutOfRangeSpec(org.opensearch.index.mapper.NumberFieldTypeTests.OutOfRangeSpec)

Aggregations

Arrays (java.util.Arrays)2 List (java.util.List)2 Set (java.util.Set)2 Matchers.arrayWithSize (org.hamcrest.Matchers.arrayWithSize)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Strings (org.opensearch.common.Strings)2 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 DocValuesType (org.apache.lucene.index.DocValuesType)1 IndexableField (org.apache.lucene.index.IndexableField)1 Matchers.arrayContaining (org.hamcrest.Matchers.arrayContaining)1 Matchers.arrayContainingInAnyOrder (org.hamcrest.Matchers.arrayContainingInAnyOrder)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 Matchers.empty (org.hamcrest.Matchers.empty)1