HTTPBulkLoader { protected BulkableAction<DocumentResult> convertToJestAction(ActionRequest req) { BulkableAction<DocumentResult> action; switch (req.key.getAction()) { case INDEX: action = getIndexAction(req); break; case UPDATE: action = getUpdateAction(req); break; case DELETE: action = getDeleteAction(req); break; default: throw new IllegalStateException("Unknown action: " + req.key.getAction()); } return action; } HTTPBulkLoader(Config config, JestClient client, Optional<Consumer<BulkReport>> onFlushOpt); void addAction(String source, ActionRequest req); void flush(); void start(); void stop();  }
@Test public void testConvertToJestActionIndex() throws Exception { HTTPBulkLoader loader = getBulkLoader(); ActionRequestKey key = ActionRequestKey.newBuilder() .setAction(Action.INDEX) .setId("myId") .build(); BulkableAction<DocumentResult> action = loader.convertToJestAction(new HTTPBulkLoader.ActionRequest(key, "fakeindex", "faketype", 100L, "{}")); assertEquals("index", action.getBulkMethodName()); assertEquals("myId", action.getId()); assertEquals("fakeindex", action.getIndex()); assertEquals("faketype", action.getType()); assertEquals("{}", action.getData(new Gson())); assertEquals(0, action.getParameter(Parameters.VERSION).size()); assertEquals(0, action.getParameter(Parameters.VERSION_TYPE).size()); ActionRequestKey keyWithVersion = ActionRequestKey.newBuilder() .setAction(Action.INDEX) .setId("myId") .setVersion(123L) .setVersionType(VersionType.EXTERNAL) .build(); BulkableAction<DocumentResult> actionWithVersion = loader.convertToJestAction(new HTTPBulkLoader.ActionRequest(keyWithVersion, "fakeindex", "faketype", 100L, "{}")); assertEquals("external", actionWithVersion.getParameter(Parameters.VERSION_TYPE).toArray()[0]); assertEquals(123L, actionWithVersion.getParameter(Parameters.VERSION).toArray()[0]); }
@Test public void testConvertToJestActionUpdate() throws Exception { HTTPBulkLoader loader = getBulkLoader(); ActionRequestKey key = ActionRequestKey.newBuilder() .setAction(Action.UPDATE) .setId("myId") .setVersion(123L) .setVersionType(VersionType.EXTERNAL) .build(); BulkableAction<DocumentResult> action = loader.convertToJestAction(new HTTPBulkLoader.ActionRequest(key, "fakeindex", "faketype", 100L, "{}")); assertEquals("update", action.getBulkMethodName()); assertEquals("myId", action.getId()); assertEquals("fakeindex", action.getIndex()); assertEquals("faketype", action.getType()); assertEquals("external", action.getParameter(Parameters.VERSION_TYPE).toArray()[0]); assertEquals(123L, action.getParameter(Parameters.VERSION).toArray()[0]); assertEquals("{}", action.getData(new Gson())); }
@Test public void testConvertToJestActionDelete() throws Exception { HTTPBulkLoader loader = getBulkLoader(); ActionRequestKey key = ActionRequestKey.newBuilder() .setAction(Action.DELETE) .setId("myId") .setVersion(123L) .setVersionType(VersionType.EXTERNAL) .build(); BulkableAction<DocumentResult> action = loader.convertToJestAction(new HTTPBulkLoader.ActionRequest(key, "fakeindex", "faketype", 100L, null)); assertEquals("delete", action.getBulkMethodName()); assertEquals("myId", action.getId()); assertEquals("fakeindex", action.getIndex()); assertEquals("faketype", action.getType()); assertEquals("external", action.getParameter(Parameters.VERSION_TYPE).toArray()[0]); assertEquals(123L, action.getParameter(Parameters.VERSION).toArray()[0]); assertEquals(null, action.getData(new Gson())); }