@Test
  public void testCloseIndexNoAcknowledgement() {
    createIndex("test");
    ensureGreen();

    CloseIndexResponse closeIndexResponse =
        client().admin().indices().prepareClose("test").setTimeout("0s").get();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(false));
  }
  public void testOpenIndexNoAcknowledgement() {
    createIndex("test");
    ensureGreen();
    removePublishTimeout();
    CloseIndexResponse closeIndexResponse =
        client().admin().indices().prepareClose("test").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));

    OpenIndexResponse openIndexResponse =
        client().admin().indices().prepareOpen("test").setTimeout("0s").get();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(false));
    ensureGreen(
        "test"); // make sure that recovery from disk has completed, so that check index doesn't
                 // fail.
  }
  public void testSimpleOpenClose() {
    logger.info("--> creating test index");
    createIndex("test");

    logger.info("--> waiting for green status");
    ensureGreen();

    NumShards numShards = getNumShards("test");

    ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
    assertThat(
        stateResponse.getState().metaData().index("test").getState(),
        equalTo(IndexMetaData.State.OPEN));
    assertThat(
        stateResponse.getState().routingTable().index("test").shards().size(),
        equalTo(numShards.numPrimaries));
    assertThat(
        stateResponse
            .getState()
            .routingTable()
            .index("test")
            .shardsWithState(ShardRoutingState.STARTED)
            .size(),
        equalTo(numShards.totalNumShards));

    logger.info("--> indexing a simple document");
    client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();

    logger.info("--> closing test index...");
    CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").get();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));

    stateResponse = client().admin().cluster().prepareState().get();
    assertThat(
        stateResponse.getState().metaData().index("test").getState(),
        equalTo(IndexMetaData.State.CLOSE));
    assertThat(stateResponse.getState().routingTable().index("test"), nullValue());

    logger.info("--> trying to index into a closed index ...");
    try {
      client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
      fail();
    } catch (IndexClosedException e) {
      // all is well
    }

    logger.info("--> opening index...");
    OpenIndexResponse openIndexResponse = client().admin().indices().prepareOpen("test").get();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));

    logger.info("--> waiting for green status");
    ensureGreen();

    stateResponse = client().admin().cluster().prepareState().get();
    assertThat(
        stateResponse.getState().metaData().index("test").getState(),
        equalTo(IndexMetaData.State.OPEN));

    assertThat(
        stateResponse.getState().routingTable().index("test").shards().size(),
        equalTo(numShards.numPrimaries));
    assertThat(
        stateResponse
            .getState()
            .routingTable()
            .index("test")
            .shardsWithState(ShardRoutingState.STARTED)
            .size(),
        equalTo(numShards.totalNumShards));

    logger.info("--> indexing a simple document");
    client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
  }