use of org.opensearch.action.admin.indices.stats.CommonStatsFlags.Flag in project OpenSearch by opensearch-project.
the class IndexStatsIT method testEncodeDecodeCommonStats.
public void testEncodeDecodeCommonStats() throws IOException {
CommonStatsFlags flags = new CommonStatsFlags();
Flag[] values = CommonStatsFlags.Flag.values();
assertThat(flags.anySet(), equalTo(true));
for (Flag flag : values) {
flags.set(flag, false);
}
assertThat(flags.anySet(), equalTo(false));
for (Flag flag : values) {
flags.set(flag, true);
}
assertThat(flags.anySet(), equalTo(true));
Random random = random();
flags.set(values[random.nextInt(values.length)], false);
assertThat(flags.anySet(), equalTo(true));
{
BytesStreamOutput out = new BytesStreamOutput();
flags.writeTo(out);
out.close();
BytesReference bytes = out.bytes();
CommonStatsFlags readStats = new CommonStatsFlags(bytes.streamInput());
for (Flag flag : values) {
assertThat(flags.isSet(flag), equalTo(readStats.isSet(flag)));
}
}
{
for (Flag flag : values) {
flags.set(flag, random.nextBoolean());
}
BytesStreamOutput out = new BytesStreamOutput();
flags.writeTo(out);
out.close();
BytesReference bytes = out.bytes();
CommonStatsFlags readStats = new CommonStatsFlags(bytes.streamInput());
for (Flag flag : values) {
assertThat(flags.isSet(flag), equalTo(readStats.isSet(flag)));
}
}
}
use of org.opensearch.action.admin.indices.stats.CommonStatsFlags.Flag in project OpenSearch by opensearch-project.
the class IndexStatsIT method testAllFlags.
public void testAllFlags() throws Exception {
// rely on 1 replica for this tests
assertAcked(prepareCreate("test_index"));
createIndex("test_index_2");
ensureGreen();
client().prepareIndex("test_index").setId(Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test_index").setId(Integer.toString(2)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test_index_2").setId(Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
Flag[] values = CommonStatsFlags.Flag.values();
for (Flag flag : values) {
set(flag, builder, false);
}
IndicesStatsResponse stats = builder.execute().actionGet();
for (Flag flag : values) {
assertThat(isSet(flag, stats.getPrimaries()), equalTo(false));
assertThat(isSet(flag, stats.getTotal()), equalTo(false));
}
for (Flag flag : values) {
set(flag, builder, true);
}
stats = builder.execute().actionGet();
for (Flag flag : values) {
assertThat(isSet(flag, stats.getPrimaries()), equalTo(true));
assertThat(isSet(flag, stats.getTotal()), equalTo(true));
}
Random random = random();
EnumSet<Flag> flags = EnumSet.noneOf(Flag.class);
for (Flag flag : values) {
if (random.nextBoolean()) {
flags.add(flag);
}
}
for (Flag flag : values) {
// clear all
set(flag, builder, false);
}
for (Flag flag : flags) {
// set the flags
set(flag, builder, true);
}
stats = builder.execute().actionGet();
for (Flag flag : flags) {
// check the flags
assertThat(isSet(flag, stats.getPrimaries()), equalTo(true));
assertThat(isSet(flag, stats.getTotal()), equalTo(true));
}
for (Flag flag : EnumSet.complementOf(flags)) {
// check the complement
assertThat(isSet(flag, stats.getPrimaries()), equalTo(false));
assertThat(isSet(flag, stats.getTotal()), equalTo(false));
}
}
Aggregations