Remove createSampleDocument method and use the sync'ed index method

This commit is contained in:
David Pilato 2017-02-20 10:33:19 +01:00
parent 0ee74f9c28
commit bf8241eec5
1 changed files with 5 additions and 15 deletions

View File

@ -60,7 +60,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
{ {
// Testing deletion // Testing deletion
String docId = "id"; String docId = "id";
createSampleDocument(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar"))); highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")));
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId); DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId);
if (randomBoolean()) { if (randomBoolean()) {
deleteRequest.version(1L); deleteRequest.version(1L);
@ -74,7 +74,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
{ {
// Testing version conflict // Testing version conflict
String docId = "version_conflict"; String docId = "version_conflict";
createSampleDocument(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar"))); highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")));
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).version(2); DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).version(2);
ElasticsearchException exception = expectThrows(ElasticsearchException.class, ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync)); () -> execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync));
@ -87,7 +87,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
{ {
// Testing version type // Testing version type
String docId = "version_type"; String docId = "version_type";
createSampleDocument(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")) highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar"))
.versionType(VersionType.EXTERNAL).version(12)); .versionType(VersionType.EXTERNAL).version(12));
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).versionType(VersionType.EXTERNAL).version(13); DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).versionType(VersionType.EXTERNAL).version(13);
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
@ -99,7 +99,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
{ {
// Testing version type with a wrong version // Testing version type with a wrong version
String docId = "wrong_version"; String docId = "wrong_version";
createSampleDocument(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")) highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar"))
.versionType(VersionType.EXTERNAL).version(12)); .versionType(VersionType.EXTERNAL).version(12));
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> { ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> {
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).versionType(VersionType.EXTERNAL).version(10); DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).versionType(VersionType.EXTERNAL).version(10);
@ -113,7 +113,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
{ {
// Testing routing // Testing routing
String docId = "routing"; String docId = "routing";
createSampleDocument(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")).routing("foo")); highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")).routing("foo"));
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).routing("foo"); DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).routing("foo");
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync); DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
assertEquals("index", deleteResponse.getIndex()); assertEquals("index", deleteResponse.getIndex());
@ -344,14 +344,4 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
"version conflict, document already exists (current version [1])]", exception.getMessage()); "version conflict, document already exists (current version [1])]", exception.getMessage());
} }
} }
/**
* Index a document
* @param request index request
* @throws IOException if something goes wrong while executing the index request
*/
private void createSampleDocument(IndexRequest request) throws IOException {
IndexResponse indexResponse = execute(request, highLevelClient()::index, highLevelClient()::indexAsync);
assertEquals(RestStatus.CREATED, indexResponse.status());
}
} }