forked from searchbox-io/Jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request searchbox-io#336 from logzio/feature/handle_index_…
…failure_bulk_item Fix NPE when bulk item result has "_id":null
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
jest-common/src/test/java/io/searchbox/core/BulkResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.searchbox.core; | ||
|
||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import org.junit.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class BulkResultTest { | ||
|
||
static String indexFailedResult = "{\n" + | ||
" \"took\": 10,\n" + | ||
" \"errors\": true,\n" + | ||
" \"items\": [\n" + | ||
" {\n" + | ||
" \"index\": {\n" + | ||
" \"_index\": \"index-name\",\n" + | ||
" \"_type\": \"type-name\",\n" + | ||
" \"_id\": null,\n" + | ||
" \"status\": 400,\n" + | ||
" \"error\": \"MapperParsingException[mapping [type-name]]; nested: MapperParsingException[No type specified for property [field-name]]; \"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" ]\n" + | ||
"}"; | ||
|
||
@Test | ||
public void bulkResultWithFailures() { | ||
BulkResult bulkResult = new BulkResult(new GsonBuilder().serializeNulls().create()); | ||
bulkResult.setJsonString(indexFailedResult); | ||
bulkResult.setJsonMap(new Gson().fromJson(indexFailedResult, Map.class)); | ||
bulkResult.setSucceeded(false); | ||
|
||
assertEquals(1, bulkResult.getItems().size()); | ||
assertEquals(1, bulkResult.getFailedItems().size()); | ||
} | ||
} |