Search in sources :

Example 1 with Flag

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)));
        }
    }
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) Random(java.util.Random) CommonStatsFlags(org.opensearch.action.admin.indices.stats.CommonStatsFlags) Flag(org.opensearch.action.admin.indices.stats.CommonStatsFlags.Flag) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 2 with 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));
    }
}
Also used : IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequestBuilder(org.opensearch.action.admin.indices.stats.IndicesStatsRequestBuilder) Random(java.util.Random) Flag(org.opensearch.action.admin.indices.stats.CommonStatsFlags.Flag)

Aggregations

Random (java.util.Random)2 Flag (org.opensearch.action.admin.indices.stats.CommonStatsFlags.Flag)2 CommonStatsFlags (org.opensearch.action.admin.indices.stats.CommonStatsFlags)1 IndicesStatsRequestBuilder (org.opensearch.action.admin.indices.stats.IndicesStatsRequestBuilder)1 IndicesStatsResponse (org.opensearch.action.admin.indices.stats.IndicesStatsResponse)1 BytesReference (org.opensearch.common.bytes.BytesReference)1 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)1