@Test public void fail_if_bad_query_with_basic_profiling() { IndexRequestBuilder requestBuilder = es.client().prepareIndex(new IndexType("unknownIndex", "unknownType")); try { requestBuilder.get(); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class); assertThat(e.getMessage()).contains("Fail to execute ES index request for key 'null' on index 'unknownIndex' on type 'unknownType'"); } }
@Test public void execute_should_throw_an_unsupported_operation_exception() { try { es.client().prepareRefresh(FakeIndexDefinition.INDEX).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 execute_should_throw_an_unsupported_operation_exception() { try { es.client().prepareClusterStats().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_string_timeout_is_not_yet_implemented() { try { es.client().prepareState().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().prepareState().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_string_timeout_is_not_yet_implemented() { try { es.client().prepareSearchScroll("scrollId").get("1"); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@Override protected void after() { if (isCustom) { // delete non-core indices String[] existingIndices = SHARED_NODE.client().admin().indices().prepareGetIndex().get().getIndices(); Stream.of(existingIndices) .filter(i -> !CORE_INDICES_NAMES.contains(i)) .forEach(EsTester::deleteIndexIfExists); } BulkIndexer.delete(client(), new IndexType("_all", ""), client().prepareSearch("_all").setQuery(matchAllQuery())); }
@Test public void get_with_time_value_timeout_is_not_yet_implemented() { try { es.client().prepareSearch(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1)); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@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); ClearIndicesCacheRequestBuilder requestBuilder = es.client().prepareClearCache(); requestBuilder.get(); assertThat(logTester.logs()).hasSize(1); }
@Test public void stats() { ClusterStatsRequestBuilder requestBuilder = es.client().prepareClusterStats(); requestBuilder.get(); }
@Test public void state() { ClusterStateRequestBuilder requestBuilder = es.client().prepareState(); requestBuilder.get(); }
@Test public void no_trace_logs() { logTester.setLevel(LoggerLevel.DEBUG); ClearIndicesCacheRequestBuilder requestBuilder = es.client().prepareClearCache(); requestBuilder.get(); assertThat(logTester.logs()).isEmpty(); }
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); CreateIndexRequestBuilder requestBuilder = es.client().prepareCreate(generateNewIndexName()); requestBuilder.get(); assertThat(logTester.logs()).hasSize(1); }
@Test public void index_documents() { BulkIndexer indexer = new BulkIndexer(es.client(), INDEX_TYPE_FAKE, Size.REGULAR); indexer.start(); indexer.add(newIndexRequest(42)); indexer.add(newIndexRequest(78)); // request is not sent yet assertThat(count()).isEqualTo(0); // send remaining requests indexer.stop(); assertThat(count()).isEqualTo(2); }
private void assertThatComponentHasName(ComponentDto component, String expectedName) { SearchHit[] hits = es.client() .prepareSearch(INDEX_TYPE_COMPONENT) .setQuery(matchQuery(SORTABLE_ANALYZER.subField(FIELD_NAME), expectedName)) .get() .getHits() .getHits(); assertThat(hits) .extracting(SearchHit::getId) .contains(component.uuid()); } }
@Test public void index_with_index_type_and_id() { IndexResponse response = es.client().prepareIndex(FakeIndexDefinition.INDEX_TYPE_FAKE) .setSource(FakeIndexDefinition.newDoc(42).getFields()) .get(); assertThat(response.getResult()).isSameAs(Result.CREATED); }
protected PermissionUpdater newPermissionUpdater() { return new PermissionUpdater( new ProjectIndexersImpl(new PermissionIndexer(db.getDbClient(), es.client())), new UserPermissionChanger(db.getDbClient()), new GroupPermissionChanger(db.getDbClient())); }