@Test public void to_string() { assertThat(es.client().prepareIndicesExist(FakeIndexDefinition.INDEX).toString()).isEqualTo("ES indices exists request on indices 'fakes'"); }
@Test public void fail_to_exists() { try { es.client().prepareIndicesExist().get(); // expected to fail because elasticsearch is not correctly configured, but that does not matter fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class); assertThat(e.getMessage()).contains("Fail to execute ES indices exists request"); } }
@Test public void exists() { assertThat(es.client().prepareIndicesExist(FakeIndexDefinition.INDEX).get().isExists()).isTrue(); assertThat(es.client().prepareIndicesExist("unknown").get().isExists()).isFalse(); }
@Test public void get_with_string_timeout_is_not_yet_implemented() { try { es.client().prepareIndicesExist().get("1"); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@Test public void execute_should_throw_an_unsupported_operation_exception() { try { es.client().prepareIndicesExist().execute(); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous"); } }
@Test public void get_with_time_value_timeout_is_not_yet_implemented() { try { es.client().prepareIndicesExist().get(TimeValue.timeValueMinutes(1)); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); es.client().prepareIndicesExist(FakeIndexDefinition.INDEX).get(); assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1); }
@Override public void start() { // create the "metadata" index first if (!client.prepareIndicesExist(MetadataIndexDefinition.INDEX_TYPE_METADATA.getIndex()).get().isExists()) { IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext(); metadataIndexDefinition.define(context); NewIndex index = context.getIndices().values().iterator().next(); createIndex(new Index(index), false); } checkDbCompatibility(definitions.getIndices().values()); // create indices that do not exist or that have a new definition (different mapping, cluster enabled, ...) for (Index index : definitions.getIndices().values()) { boolean exists = client.prepareIndicesExist(index.getName()).get().isExists(); if (exists && !index.getName().equals(MetadataIndexDefinition.INDEX_TYPE_METADATA.getIndex()) && hasDefinitionChange(index)) { verifyNotBlueGreenDeployment(index.getName()); LOGGER.info("Delete Elasticsearch index {} (structure changed)", index.getName()); deleteIndex(index.getName()); exists = false; } if (!exists) { createIndex(index, true); } } }
@Test public void proxify_requests() { EsClient underTest = es.client(); assertThat(underTest.nativeClient()).isNotNull(); assertThat(underTest.prepareClusterStats()).isInstanceOf(ProxyClusterStatsRequestBuilder.class); assertThat(underTest.prepareCreate("fakes")).isInstanceOf(ProxyCreateIndexRequestBuilder.class); assertThat(underTest.prepareDelete("fakes", "fake", "my_id")).isInstanceOf(ProxyDeleteRequestBuilder.class); assertThat(underTest.prepareIndicesExist()).isInstanceOf(ProxyIndicesExistsRequestBuilder.class); assertThat(underTest.prepareGet(new IndexType("fakes", "fake"), "1")).isInstanceOf(ProxyGetRequestBuilder.class); assertThat(underTest.prepareHealth()).isInstanceOf(ProxyClusterHealthRequestBuilder.class); assertThat(underTest.prepareNodesStats()).isInstanceOf(ProxyNodesStatsRequestBuilder.class); assertThat(underTest.preparePutMapping()).isInstanceOf(ProxyPutMappingRequestBuilder.class); assertThat(underTest.prepareRefresh()).isInstanceOf(ProxyRefreshRequestBuilder.class); assertThat(underTest.prepareSearch(new IndexType[0])).isInstanceOf(ProxySearchRequestBuilder.class); assertThat(underTest.prepareSearchScroll("1234")).isInstanceOf(ProxySearchScrollRequestBuilder.class); assertThat(underTest.prepareState()).isInstanceOf(ProxyClusterStateRequestBuilder.class); assertThat(underTest.prepareStats()).isInstanceOf(ProxyIndicesStatsRequestBuilder.class); underTest.close(); } }
@Override public void start() { // create the "metadata" index first if (!client.prepareIndicesExist(MetadataIndexDefinition.INDEX_TYPE_METADATA.getIndex()).get().isExists()) { IndexDefinition.IndexDefinitionContext context = new IndexDefinition.IndexDefinitionContext(); metadataIndexDefinition.define(context); NewIndex index = context.getIndices().values().iterator().next(); createIndex(new Index(index), false); } checkDbCompatibility(definitions.getIndices().values()); // create indices that do not exist or that have a new definition (different mapping, cluster enabled, ...) for (Index index : definitions.getIndices().values()) { boolean exists = client.prepareIndicesExist(index.getName()).get().isExists(); if (exists && !index.getName().equals(MetadataIndexDefinition.INDEX_TYPE_METADATA.getIndex()) && hasDefinitionChange(index)) { verifyNotBlueGreenDeployment(index.getName()); LOGGER.info("Delete Elasticsearch index {} (structure changed)", index.getName()); deleteIndex(index.getName()); exists = false; } if (!exists) { createIndex(index, true); } } }