use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project jmix by jmix-framework.
the class EntityIndexingTest method indexLongPk.
@Test
@DisplayName("Indexing of entity with Long primary key")
public void indexLongPk() {
TestLongPkEntity entity = metadata.create(TestLongPkEntity.class);
entity.setName("Long PK entity");
dataManager.save(entity);
JsonNode jsonNode = TestJsonUtils.readJsonFromFile("indexing/test_content_long_pk");
TestBulkRequestIndexActionValidationData expectedIndexAction = new TestBulkRequestIndexActionValidationData("search_index_test_longpkentity", idSerialization.idToString(Id.of(entity)), jsonNode);
TestBulkRequestValidationData expectedData = new TestBulkRequestValidationData(Collections.singletonList(expectedIndexAction), Collections.emptyList());
entityIndexer.index(entity);
List<BulkRequest> bulkRequests = bulkRequestsTracker.getBulkRequests();
TestBulkRequestValidationResult result = TestBulkRequestValidator.validate(Collections.singletonList(expectedData), bulkRequests);
Assert.assertFalse(result.toString(), result.hasFailures());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project elasticsearch-suggest-plugin by spinscale.
the class AbstractSuggestTest method indexProducts.
private void indexProducts(List<Map<String, Object>> products, String index, String routing) throws Exception {
long currentCount = getCurrentDocumentCount(index);
BulkRequest bulkRequest = new BulkRequest();
for (Map<String, Object> product : products) {
IndexRequest indexRequest = new IndexRequest(index, "product", (String) product.get("ProductId"));
indexRequest.source(product);
if (Strings.hasLength(routing)) {
indexRequest.routing(routing);
}
bulkRequest.add(indexRequest);
}
bulkRequest.refresh(true);
BulkResponse response = client().bulk(bulkRequest).actionGet();
if (response.hasFailures()) {
fail("Error in creating products: " + response.buildFailureMessage());
}
assertDocumentCountAfterIndexing(index, products.size() + currentCount);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project hazelcast by hazelcast.
the class ElasticSinkBuilderTest method when_writeToFailingSink_then_shouldCloseClient.
@Test
public void when_writeToFailingSink_then_shouldCloseClient() throws IOException {
ClientHolder.elasticClients.clear();
Sink<String> elasticSink = new ElasticSinkBuilder<>().clientFn(() -> {
RestClientBuilder builder = spy(RestClient.builder(HttpHost.create("localhost:9200")));
when(builder.build()).thenAnswer(invocation -> {
Object result = invocation.callRealMethod();
RestClient client = (RestClient) spy(result);
ClientHolder.elasticClients.add(client);
return client;
});
return builder;
}).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((String item) -> new IndexRequest("my-index").source(Collections.emptyMap())).retries(0).build();
p.readFrom(TestSources.items("a", "b", "c")).writeTo(elasticSink);
try {
execute();
} catch (Exception e) {
// ignore - elastic is not running
}
for (RestClient client : ClientHolder.elasticClients) {
verify(client).close();
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project hazelcast by hazelcast.
the class LocalElasticSinkTest method when_writeToSink_then_shouldCloseClient.
@Test
public void when_writeToSink_then_shouldCloseClient() throws IOException {
ClientHolder.elasticClients.clear();
Sink<String> elasticSink = new ElasticSinkBuilder<>().clientFn(() -> {
RestClientBuilder builder = spy(RestClient.builder(HttpHost.create(ElasticSupport.elastic.get().getHttpHostAddress())));
when(builder.build()).thenAnswer(invocation -> {
Object result = invocation.callRealMethod();
RestClient client = (RestClient) spy(result);
ClientHolder.elasticClients.add(client);
return client;
});
return builder;
}).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((String item) -> new IndexRequest("my-index").source(Collections.emptyMap())).build();
Pipeline p = Pipeline.create();
p.readFrom(TestSources.items("a", "b", "c")).writeTo(elasticSink);
hz.getJet().newJob(p).join();
for (RestClient client : ClientHolder.elasticClients) {
verify(client).close();
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project hazelcast by hazelcast.
the class AuthElasticSinksTest method given_clientWithoutAuthentication_whenWriteToElasticSink_thenFailWithAuthenticationException.
@Test
public void given_clientWithoutAuthentication_whenWriteToElasticSink_thenFailWithAuthenticationException() {
ElasticsearchContainer container = ElasticSupport.secureElastic.get();
String containerIp = container.getContainerIpAddress();
Integer port = container.getMappedPort(PORT);
Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(() -> client(containerIp, port)).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((TestItem item) -> new IndexRequest("my-index").source(item.asMap())).retries(0).build();
Pipeline p = Pipeline.create();
p.readFrom(TestSources.items(new TestItem("id", "Frantisek"))).writeTo(elasticSink);
assertThatThrownBy(() -> submitJob(p)).hasRootCauseInstanceOf(ElasticsearchStatusException.class).hasStackTraceContaining("missing authentication credentials");
}
Aggregations