Ejemplo n.º 1
0
  @Test
  public void testDeleteWarmerAcknowledgement() {
    createIndex("test");
    index("test", "type", "1", "f", 1);

    assertAcked(
        client()
            .admin()
            .indices()
            .preparePutWarmer("custom_warmer")
            .setSearchRequest(
                client()
                    .prepareSearch("test")
                    .setTypes("test")
                    .setQuery(QueryBuilders.matchAllQuery())));

    assertAcked(
        client()
            .admin()
            .indices()
            .prepareDeleteWarmer()
            .setIndices("test")
            .setNames("custom_warmer"));

    for (Client client : clients()) {
      GetWarmersResponse getWarmersResponse =
          client.admin().indices().prepareGetWarmers().setLocal(true).get();
      assertThat(getWarmersResponse.warmers().size(), equalTo(0));
    }
  }
  @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);
      }
    }
  }
Ejemplo n.º 3
0
  @Test
  public void testPutWarmerAcknowledgement() {
    createIndex("test");
    // make sure one shard is started so the search during put warmer will not fail
    index("test", "type", "1", "f", 1);

    assertAcked(
        client()
            .admin()
            .indices()
            .preparePutWarmer("custom_warmer")
            .setSearchRequest(
                client()
                    .prepareSearch("test")
                    .setTypes("test")
                    .setQuery(QueryBuilders.matchAllQuery())));

    for (Client client : clients()) {
      GetWarmersResponse getWarmersResponse =
          client.admin().indices().prepareGetWarmers().setLocal(true).get();
      assertThat(getWarmersResponse.warmers().size(), equalTo(1));
      ObjectObjectCursor<String, List<IndexWarmersMetaData.Entry>> entry =
          getWarmersResponse.warmers().iterator().next();
      assertThat(entry.key, equalTo("test"));
      assertThat(entry.value.size(), equalTo(1));
      assertThat(entry.value.get(0).name(), equalTo("custom_warmer"));
    }
  }
Ejemplo n.º 4
0
  @Test
  public void testCloseIndexNoAcknowledgement() {
    createIndex("test");
    ensureGreen();

    CloseIndexResponse closeIndexResponse =
        client().admin().indices().prepareClose("test").setTimeout("0s").get();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(false));
  }
Ejemplo n.º 5
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));
    }
  }
Ejemplo n.º 6
0
 @Test
 public void testUpdateSettingsNoAcknowledgement() {
   createIndex("test");
   UpdateSettingsResponse updateSettingsResponse =
       client()
           .admin()
           .indices()
           .prepareUpdateSettings("test")
           .setTimeout("0s")
           .setSettings(Settings.builder().put("refresh_interval", 9999, TimeUnit.MILLISECONDS))
           .get();
   assertThat(updateSettingsResponse.isAcknowledged(), equalTo(false));
 }
Ejemplo n.º 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();
  }
Ejemplo n.º 8
0
  @Test
  public void testIndicesAliasesNoAcknowledgement() {
    createIndex("test");

    IndicesAliasesResponse indicesAliasesResponse =
        client()
            .admin()
            .indices()
            .prepareAliases()
            .addAlias("test", "alias")
            .setTimeout("0s")
            .get();
    assertThat(indicesAliasesResponse.isAcknowledged(), equalTo(false));
  }
Ejemplo n.º 9
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));
  }
Ejemplo n.º 10
0
  @Test
  public void testPutWarmerNoAcknowledgement() throws InterruptedException {
    createIndex("test");
    // make sure one shard is started so the search during put warmer will not fail
    index("test", "type", "1", "f", 1);

    PutWarmerResponse putWarmerResponse =
        client()
            .admin()
            .indices()
            .preparePutWarmer("custom_warmer")
            .setTimeout("0s")
            .setSearchRequest(
                client()
                    .prepareSearch("test")
                    .setTypes("test")
                    .setQuery(QueryBuilders.matchAllQuery()))
            .get();
    assertThat(putWarmerResponse.isAcknowledged(), equalTo(false));
    /* Since we don't wait for the ack here we have to wait until the search request has been executed from the master
     * otherwise the test infra might have already deleted the index and the search request fails on all shards causing
     * the test to fail too. We simply wait until the the warmer has been installed and also clean it up afterwards.*/
    assertTrue(
        awaitBusy(
            new Predicate<Object>() {
              @Override
              public boolean apply(Object input) {
                for (Client client : clients()) {
                  GetWarmersResponse getWarmersResponse =
                      client.admin().indices().prepareGetWarmers().setLocal(true).get();
                  if (getWarmersResponse.warmers().size() != 1) {
                    return false;
                  }
                }
                return true;
              }
            }));
    assertAcked(
        client()
            .admin()
            .indices()
            .prepareDeleteWarmer()
            .setIndices("test")
            .setNames("custom_warmer"));
  }
Ejemplo n.º 11
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());
    }
  }
Ejemplo n.º 12
0
  @Test
  public void testIndicesAliasesAcknowledgement() {
    createIndex("test");

    // testing acknowledgement when trying to submit an existing alias too
    // in that case it would not make any change, but we are sure about the cluster state
    // as the previous operation was acknowledged
    for (int i = 0; i < 2; i++) {
      assertAcked(client().admin().indices().prepareAliases().addAlias("test", "alias"));

      for (Client client : clients()) {
        AliasMetaData aliasMetaData =
            ((AliasOrIndex.Alias)
                    getLocalClusterState(client).metaData().getAliasAndIndexLookup().get("alias"))
                .getFirstAliasMetaData();
        assertThat(aliasMetaData.alias(), equalTo("alias"));
      }
    }
  }
Ejemplo n.º 13
0
  @Test
  public void testDeleteWarmerNoAcknowledgement() throws InterruptedException {
    createIndex("test");
    index("test", "type", "1", "f", 1);

    assertAcked(
        client()
            .admin()
            .indices()
            .preparePutWarmer("custom_warmer")
            .setSearchRequest(
                client()
                    .prepareSearch("test")
                    .setTypes("test")
                    .setQuery(QueryBuilders.matchAllQuery())));

    DeleteWarmerResponse deleteWarmerResponse =
        client()
            .admin()
            .indices()
            .prepareDeleteWarmer()
            .setIndices("test")
            .setNames("custom_warmer")
            .setTimeout("0s")
            .get();
    assertFalse(deleteWarmerResponse.isAcknowledged());
    assertTrue(
        awaitBusy(
            new Predicate<Object>() { // wait until they are all deleted
              @Override
              public boolean apply(Object input) {
                for (Client client : clients()) {
                  GetWarmersResponse getWarmersResponse =
                      client.admin().indices().prepareGetWarmers().setLocal(true).get();
                  if (getWarmersResponse.warmers().size() > 0) {
                    return false;
                  }
                }
                return true;
              }
            }));
  }
Ejemplo n.º 14
0
  @Test
  public void testUpdateSettingsAcknowledgement() {
    createIndex("test");

    assertAcked(
        client()
            .admin()
            .indices()
            .prepareUpdateSettings("test")
            .setSettings(Settings.builder().put("refresh_interval", 9999, TimeUnit.MILLISECONDS)));

    for (Client client : clients()) {
      String refreshInterval =
          getLocalClusterState(client)
              .metaData()
              .index("test")
              .settings()
              .get("index.refresh_interval");
      assertThat(refreshInterval, equalTo("9999ms"));
    }
  }
  @Test
  public void updateMappingConcurrently() throws Throwable {
    createIndex("test1", "test2");

    // This is important. The test assumes all nodes are aware of all indices. Due to initializing
    // shard throttling
    // not all shards are allocated with the initial create index. Wait for it..
    ensureYellow();

    final Throwable[] threadException = new Throwable[1];
    final AtomicBoolean stop = new AtomicBoolean(false);
    Thread[] threads = new Thread[3];
    final CyclicBarrier barrier = new CyclicBarrier(threads.length);
    final ArrayList<Client> clientArray = new ArrayList<>();
    for (Client c : clients()) {
      clientArray.add(c);
    }

    for (int j = 0; j < threads.length; j++) {
      threads[j] =
          new Thread(
              new Runnable() {
                @SuppressWarnings("unchecked")
                @Override
                public void run() {
                  try {
                    barrier.await();

                    for (int i = 0; i < 100; i++) {
                      if (stop.get()) {
                        return;
                      }

                      Client client1 = clientArray.get(i % clientArray.size());
                      Client client2 = clientArray.get((i + 1) % clientArray.size());
                      String indexName = i % 2 == 0 ? "test2" : "test1";
                      String typeName = "type" + (i % 10);
                      String fieldName = Thread.currentThread().getName() + "_" + i;

                      PutMappingResponse response =
                          client1
                              .admin()
                              .indices()
                              .preparePutMapping(indexName)
                              .setType(typeName)
                              .setSource(
                                  JsonXContent.contentBuilder()
                                      .startObject()
                                      .startObject(typeName)
                                      .startObject("properties")
                                      .startObject(fieldName)
                                      .field("type", "string")
                                      .endObject()
                                      .endObject()
                                      .endObject()
                                      .endObject())
                              .get();

                      assertThat(response.isAcknowledged(), equalTo(true));
                      GetMappingsResponse getMappingResponse =
                          client2.admin().indices().prepareGetMappings(indexName).get();
                      ImmutableOpenMap<String, MappingMetaData> mappings =
                          getMappingResponse.getMappings().get(indexName);
                      assertThat(mappings.containsKey(typeName), equalTo(true));
                      assertThat(
                          ((Map<String, Object>)
                                  mappings.get(typeName).getSourceAsMap().get("properties"))
                              .keySet(),
                          Matchers.hasItem(fieldName));
                    }
                  } catch (Throwable t) {
                    threadException[0] = t;
                    stop.set(true);
                  }
                }
              });

      threads[j].setName("t_" + j);
      threads[j].start();
    }

    for (Thread t : threads) t.join();

    if (threadException[0] != null) {
      throw threadException[0];
    }
  }