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);
}
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));
}
Aggregations