private void setMetadata(String id, String value) { esClient.prepareIndex(MetadataIndexDefinition.INDEX_TYPE_METADATA) .setId(id) .setSource(MetadataIndexDefinition.FIELD_VALUE, value) .setRefreshPolicy(REFRESH_IMMEDIATE) .get(); } }
@Test public void do_not_support_execute_method() { try { es.client().prepareIndex(FakeIndexDefinition.INDEX_TYPE_FAKE).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 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 fail_if_bad_query() { 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 get_with_string_timeout_is_not_yet_implemented() { try { es.client().prepareIndex(FakeIndexDefinition.INDEX_TYPE_FAKE).get("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().prepareIndex(FakeIndexDefinition.INDEX_TYPE_FAKE).get(TimeValue.timeValueMinutes(1)); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
private void addToIndex(String projectUuid, String name) { esClient.prepareIndex(INDEX_TYPE_FOO) .setRouting(projectUuid) .setParent(projectUuid) .setSource(ImmutableMap.of( FooIndexDefinition.FIELD_NAME, name, FooIndexDefinition.FIELD_PROJECT_UUID, projectUuid)) .get(); }
private IndexRequest newIndexRequest(IssueDoc issue) { String projectUuid = issue.projectUuid(); return esClient.prepareIndex(INDEX_TYPE_ISSUE) .setId(issue.key()) .setRouting(projectUuid) .setParent(projectUuid) .setSource(issue.getFields()) .request(); }
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); IndexResponse response = es.client().prepareIndex(FakeIndexDefinition.INDEX_TYPE_FAKE) .setSource(FakeIndexDefinition.newDoc(42).getFields()) .get(); assertThat(response.getResult()).isSameAs(Result.CREATED); assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1); }
@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); }
@Test public void recreate_index_on_definition_changes() { // v1 startNewCreator(new FakeIndexDefinition()); IndexType fakeIndexType = new IndexType("fakes", "fake"); String id = "1"; es.client().prepareIndex(fakeIndexType).setId(id).setSource(new FakeDoc().getFields()).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isTrue(); // v2 startNewCreator(new FakeIndexDefinitionV2()); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings(); MappingMetaData mapping = mappings.get("fakes").get("fake"); assertThat(countMappingFields(mapping)).isEqualTo(3); assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date"); assertThat(field(mapping, "newField").get("type")).isEqualTo("integer"); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isFalse(); }
@Test public void do_not_recreate_index_on_unchanged_definition() { // v1 startNewCreator(new FakeIndexDefinition()); IndexType fakeIndexType = new IndexType("fakes", "fake"); String id = "1"; es.client().prepareIndex(fakeIndexType).setId(id).setSource(new FakeDoc().getFields()).setRefreshPolicy(IMMEDIATE).get(); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isTrue(); // v1 startNewCreator(new FakeIndexDefinition()); assertThat(es.client().prepareGet(fakeIndexType, id).get().isExists()).isTrue(); }
private void setMetadata(String id, String value) { esClient.prepareIndex(MetadataIndexDefinition.INDEX_TYPE_METADATA) .setId(id) .setSource(MetadataIndexDefinition.FIELD_VALUE, value) .setRefreshPolicy(REFRESH_IMMEDIATE) .get(); } }
private IndexRequest newIndexRequest(IssueDoc issue) { String projectUuid = issue.projectUuid(); return esClient.prepareIndex(INDEX_TYPE_ISSUE) .setId(issue.key()) .setRouting(projectUuid) .setParent(projectUuid) .setSource(issue.getFields()) .request(); }