Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jooby.elasticsearch;

import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.jooby.test.ServerFeature;
import org.junit.Test;

Expand All @@ -11,6 +12,7 @@ public class ElasticsearchClientAPIFeature extends ServerFeature {
use(new Elasticsearch());

get("/", req -> req.require(RestClient.class).getClass().getName());
get("/hlrc", req -> req.require(RestHighLevelClient.class).getClass().getName());

}

Expand All @@ -19,6 +21,9 @@ public void boot() throws Exception {
request()
.get("/")
.expect("org.elasticsearch.client.RestClient");
request()
.get("/hlrc")
.expect("org.elasticsearch.client.RestHighLevelClient");
}

}
2 changes: 1 addition & 1 deletion modules/jooby-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<ebean-maven-plugin.version>11.11.2</ebean-maven-plugin.version>
<ebean.version>11.18.2</ebean.version>
<ehcache.version>2.10.5</ehcache.version>
<elasticsearch>5.5.3</elasticsearch>
<elasticsearch.version>7.2.0</elasticsearch.version>
<flyway.version>5.1.3</flyway.version>
<freemarker.version>2.3.28</freemarker.version>
<frontend-plugin-core.version>1.6</frontend-plugin-core.version>
Expand Down
2 changes: 1 addition & 1 deletion modules/jooby-elasticsearch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<!-- Elasticsearch -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>rest</artifactId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>

<!-- Test dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.jooby.Env;
import org.jooby.Jooby;

Expand All @@ -219,7 +220,7 @@
* Full text search and analytics via <a href="https://github.com/elastic/elasticsearch">Elastic
* Search</a>.
* </p>
* Provides a RESTFul client.
* Provides a high and low level Elasticsearch REST client.
*
* <h1>usage</h1>
*
Expand All @@ -231,17 +232,20 @@

* <h1>client API</h1>
* <p>
* The module exposes a {@link RestClient} instance
* The module exposes a {@link RestHighLevelClient} and a low-level {@link RestClient} instance
* </p>
*
* <pre>{@code
*
* put("/:id", req -> {
* // index a document
* RestClient client = req.require(RestClient.class);
* StringEntity data = new StringEntity("{\"foo\":\"bar\"}");
* return client.performRequest("PUT", "/twitter/tweet/" + req.param("id").value(), Collections.emptyMap(), data)
* .getEntity().getContent();
* IndexRequest indexRequest = new IndexRequest("posts")
* .id("1")
* .source("user", "kimchy",
* "postDate", new Date(),
* "message", "trying out Elasticsearch");
* RestHighLevelClient client = req.require(RestHighLevelClient .class);
* return client.index(request, RequestOptions.DEFAULT).toString();
* });
*
* }</pre>
Expand All @@ -264,10 +268,13 @@ public Elasticsearch(final String ... hosts) {
@Override
public void configure(final Env env, final Config config, final Binder binder) {
HttpHost[] httpHosts = Arrays.stream(hosts).map(HttpHost::create).toArray(HttpHost[]::new);
RestClient restClient = RestClient.builder(httpHosts).build();
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(httpHosts));
RestClient restClient = restHighLevelClient.getLowLevelClient();

binder.bind(RestClient.class).toInstance(restClient);
binder.bind(RestHighLevelClient.class).toInstance(restHighLevelClient);

env.onStop(restClient::close);
env.onStop(restHighLevelClient::close);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.typesafe.config.ConfigFactory;
import static org.easymock.EasyMock.expect;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.jooby.Env;
import org.jooby.test.MockUnit;
import org.jooby.funzy.Throwing;
Expand All @@ -32,16 +33,21 @@ public class ElasticsearchTest {
private MockUnit.Block nb = unit -> {
RestClient client = unit.mock(RestClient.class);
unit.registerMock(RestClient.class, client);
RestHighLevelClient restHighLevelClient = unit.mock(RestHighLevelClient.class);
unit.registerMock(RestHighLevelClient.class, restHighLevelClient);
};

@SuppressWarnings("unchecked")
private MockUnit.Block bindings = unit -> {
AnnotatedBindingBuilder<RestClient> abbclient = unit.mock(AnnotatedBindingBuilder.class);
abbclient.toInstance(unit.capture(RestClient.class));
//abbclient.toInstance(anyObject(RestClient.class));

AnnotatedBindingBuilder<RestHighLevelClient> defclient = unit.mock(AnnotatedBindingBuilder.class);
defclient.toInstance(unit.capture(RestHighLevelClient.class));

Binder binder = unit.get(Binder.class);
expect(binder.bind(RestClient.class)).andReturn(abbclient);
expect(binder.bind(RestHighLevelClient.class)).andReturn(defclient);
};

@Test
Expand All @@ -57,6 +63,9 @@ public void defaults() throws Exception {
List<RestClient> captured = unit.captured(RestClient.class);
assert captured.size() == 1;

List<RestHighLevelClient> capturedHighLevelRestClient = unit.captured(RestHighLevelClient.class);
assert capturedHighLevelRestClient.size() == 1;

List<Throwing.Runnable> callbacks = unit.captured(Throwing.Runnable.class);
callbacks.get(0).run();
});
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,8 @@
<!-- Elasticsearch -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>rest</artifactId>
<version>${elasticsearch}</version>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>${elasticsearch.version}</version>
</dependency>

<!-- CDI Api; https://hibernate.atlassian.net/browse/HHH-11370 -->
Expand Down Expand Up @@ -3181,7 +3181,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
<ebean-maven-plugin.version>11.11.2</ebean-maven-plugin.version>
<ebean.version>11.18.2</ebean.version>
<ehcache.version>2.10.5</ehcache.version>
<elasticsearch>5.5.3</elasticsearch>
<elasticsearch.version>7.2.0</elasticsearch.version>
<flyway.version>5.1.3</flyway.version>
<freemarker.version>2.3.28</freemarker.version>
<frontend-plugin-core.version>1.6</frontend-plugin-core.version>
Expand Down