@Test
  public void testPutMappingsWithBlocks() throws Exception {
    createIndex("test");
    ensureGreen();

    for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE)) {
      try {
        enableIndexBlock("test", block);
        assertAcked(
            client()
                .admin()
                .indices()
                .preparePutMapping("test")
                .setType("doc")
                .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}"));
      } finally {
        disableIndexBlock("test", block);
      }
    }

    for (String block : Arrays.asList(SETTING_READ_ONLY, SETTING_BLOCKS_METADATA)) {
      try {
        enableIndexBlock("test", block);
        assertBlocked(
            client()
                .admin()
                .indices()
                .preparePutMapping("test")
                .setType("doc")
                .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}"));
      } finally {
        disableIndexBlock("test", block);
      }
    }
  }
Beispiel #2
0
  @Test
  public void testClusterRerouteNoAcknowledgementDryRun() throws InterruptedException {
    client()
        .admin()
        .indices()
        .prepareCreate("test")
        .setSettings(
            settingsBuilder()
                .put(
                    SETTING_NUMBER_OF_SHARDS,
                    between(cluster().numDataNodes(), DEFAULT_MAX_NUM_SHARDS))
                .put(SETTING_NUMBER_OF_REPLICAS, 0))
        .get();
    ensureGreen();

    MoveAllocationCommand moveAllocationCommand = getAllocationCommand();

    ClusterRerouteResponse clusterRerouteResponse =
        client()
            .admin()
            .cluster()
            .prepareReroute()
            .setTimeout("0s")
            .setDryRun(true)
            .add(moveAllocationCommand)
            .get();
    // acknowledged anyway as no changes were made
    assertThat(clusterRerouteResponse.isAcknowledged(), equalTo(true));
  }
Beispiel #3
0
  @Test
  public void testCloseIndexNoAcknowledgement() {
    createIndex("test");
    ensureGreen();

    CloseIndexResponse closeIndexResponse =
        client().admin().indices().prepareClose("test").setTimeout("0s").get();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(false));
  }
Beispiel #4
0
  @Test
  public void testCreateIndexNoAcknowledgement() {
    CreateIndexResponse createIndexResponse =
        client().admin().indices().prepareCreate("test").setTimeout("0s").get();
    assertThat(createIndexResponse.isAcknowledged(), equalTo(false));

    // let's wait for green, otherwise there can be issues with after test checks (mock directory
    // wrapper etc.)
    ensureGreen();
  }
Beispiel #5
0
  @Test
  public void testClusterRerouteAcknowledgementDryRun() throws InterruptedException {
    client()
        .admin()
        .indices()
        .prepareCreate("test")
        .setSettings(
            settingsBuilder()
                .put(
                    SETTING_NUMBER_OF_SHARDS,
                    between(cluster().numDataNodes(), DEFAULT_MAX_NUM_SHARDS))
                .put(SETTING_NUMBER_OF_REPLICAS, 0))
        .get();
    ensureGreen();

    MoveAllocationCommand moveAllocationCommand = getAllocationCommand();

    assertAcked(
        client().admin().cluster().prepareReroute().setDryRun(true).add(moveAllocationCommand));

    // testing only on master with the latest cluster state as we didn't make any change thus we
    // cannot guarantee that
    // all nodes hold the same cluster state version. We only know there was no need to change
    // anything, thus no need for ack on this update.
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().get();
    boolean found = false;
    for (ShardRouting shardRouting :
        clusterStateResponse
            .getState()
            .getRoutingNodes()
            .routingNodeIter(moveAllocationCommand.fromNode())) {
      // the shard that we wanted to move is still on the same node, as we had dryRun flag
      if (shardRouting.shardId().equals(moveAllocationCommand.shardId())) {
        assertThat(shardRouting.started(), equalTo(true));
        found = true;
        break;
      }
    }
    assertThat(found, equalTo(true));

    for (ShardRouting shardRouting :
        clusterStateResponse
            .getState()
            .getRoutingNodes()
            .routingNodeIter(moveAllocationCommand.toNode())) {
      if (shardRouting.shardId().equals(moveAllocationCommand.shardId())) {
        fail(
            "shard ["
                + shardRouting
                + "] shouldn't be on node ["
                + moveAllocationCommand.toString()
                + "]");
      }
    }
  }
Beispiel #6
0
  public void testCloseIndexAcknowledgement() {
    createIndex("test");
    ensureGreen();

    assertAcked(client().admin().indices().prepareClose("test"));

    for (Client client : clients()) {
      IndexMetaData indexMetaData = getLocalClusterState(client).metaData().indices().get("test");
      assertThat(indexMetaData.getState(), equalTo(State.CLOSE));
    }
  }
Beispiel #7
0
  @Test
  public void testCreateIndexAcknowledgement() {
    createIndex("test");

    for (Client client : clients()) {
      assertThat(
          getLocalClusterState(client).metaData().indices().containsKey("test"), equalTo(true));
    }

    // let's wait for green, otherwise there can be issues with after test checks (mock directory
    // wrapper etc.)
    // but we do want to check that the new index is on all nodes cluster state even before green
    ensureGreen();
  }
Beispiel #8
0
  @Test
  public void testPutMappingNoAcknowledgement() {
    createIndex("test");
    ensureGreen();

    PutMappingResponse putMappingResponse =
        client()
            .admin()
            .indices()
            .preparePutMapping("test")
            .setType("test")
            .setSource("field", "type=string,index=not_analyzed")
            .setTimeout("0s")
            .get();
    assertThat(putMappingResponse.isAcknowledged(), equalTo(false));
  }
Beispiel #9
0
  @Test
  public void testPutMappingAcknowledgement() {
    createIndex("test");
    ensureGreen();

    assertAcked(
        client()
            .admin()
            .indices()
            .preparePutMapping("test")
            .setType("test")
            .setSource("field", "type=string,index=not_analyzed"));

    for (Client client : clients()) {
      assertThat(
          getLocalClusterState(client).metaData().indices().get("test").mapping("test"),
          notNullValue());
    }
  }
Beispiel #10
0
  @Test
  public void testClusterRerouteAcknowledgement() throws InterruptedException {
    assertAcked(
        prepareCreate("test")
            .setSettings(
                Settings.builder()
                    .put(indexSettings())
                    .put(
                        SETTING_NUMBER_OF_SHARDS,
                        between(cluster().numDataNodes(), DEFAULT_MAX_NUM_SHARDS))
                    .put(SETTING_NUMBER_OF_REPLICAS, 0)));
    ensureGreen();

    MoveAllocationCommand moveAllocationCommand = getAllocationCommand();

    assertAcked(client().admin().cluster().prepareReroute().add(moveAllocationCommand));

    for (Client client : clients()) {
      ClusterState clusterState = getLocalClusterState(client);
      for (ShardRouting shardRouting :
          clusterState.getRoutingNodes().routingNodeIter(moveAllocationCommand.fromNode())) {
        // if the shard that we wanted to move is still on the same node, it must be relocating
        if (shardRouting.shardId().equals(moveAllocationCommand.shardId())) {
          assertThat(shardRouting.relocating(), equalTo(true));
        }
      }

      boolean found = false;
      for (ShardRouting shardRouting :
          clusterState.getRoutingNodes().routingNodeIter(moveAllocationCommand.toNode())) {
        if (shardRouting.shardId().equals(moveAllocationCommand.shardId())) {
          assertThat(
              shardRouting.state(),
              anyOf(equalTo(ShardRoutingState.INITIALIZING), equalTo(ShardRoutingState.STARTED)));
          found = true;
          break;
        }
      }
      assertThat(found, equalTo(true));
    }
  }