コード例 #1
0
 private static void set(Flag flag, IndicesStatsRequestBuilder builder, boolean set) {
   switch (flag) {
     case Docs:
       builder.setDocs(set);
       break;
     case FieldData:
       builder.setFieldData(set);
       break;
     case FilterCache:
       builder.setFilterCache(set);
       break;
     case Flush:
       builder.setFlush(set);
       break;
     case Get:
       builder.setGet(set);
       break;
     case IdCache:
       builder.setIdCache(set);
       break;
     case Indexing:
       builder.setIndexing(set);
       break;
     case Merge:
       builder.setMerge(set);
       break;
     case Refresh:
       builder.setRefresh(set);
       break;
     case Search:
       builder.setSearch(set);
       break;
     case Store:
       builder.setStore(set);
       break;
     case Warmer:
       builder.setWarmer(set);
       break;
     case Percolate:
       builder.setPercolate(set);
       break;
     case Completion:
       builder.setCompletion(set);
       break;
     default:
       assert false : "new flag? " + flag;
       break;
   }
 }
コード例 #2
0
  @Test
  public void testAllFlags() throws Exception {
    // rely on 1 replica for this tests
    createIndex("test1");
    createIndex("test2");

    ClusterHealthResponse clusterHealthResponse =
        client()
            .admin()
            .cluster()
            .prepareHealth()
            .setWaitForEvents(Priority.LANGUID)
            .setWaitForGreenStatus()
            .execute()
            .actionGet();
    assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));

    client()
        .prepareIndex("test1", "type1", Integer.toString(1))
        .setSource("field", "value")
        .execute()
        .actionGet();
    client()
        .prepareIndex("test1", "type2", Integer.toString(1))
        .setSource("field", "value")
        .execute()
        .actionGet();
    client()
        .prepareIndex("test2", "type", 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 = getRandom();
    EnumSet<Flag> flags = EnumSet.noneOf(Flag.class);
    for (Flag flag : values) {
      if (random.nextBoolean()) {
        flags.add(flag);
      }
    }

    for (Flag flag : values) {
      set(flag, builder, false); // clear all
    }

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