HTTPBulkLoader { public void addAction(String source, ActionRequest req) throws Throwable { BulkableAction<DocumentResult> action = convertToJestAction(req); WriterCommand addCmd = WriterCommand.getAddCmd(new SourcedActionRequest(source, req, action)); sendCmd(addCmd); } HTTPBulkLoader(Config config, JestClient client, Optional<Consumer<BulkReport>> onFlushOpt); void addAction(String source, ActionRequest req); void flush(); void start(); void stop();  }
@Test public void testDeadWriterDetectionOnAdd() throws Throwable { HTTPBulkLoader loader = getBulkLoader(); loader.writerFuture = mock(Future.class); when(loader.writerFuture.isDone()).thenReturn(true); when(loader.writerFuture.get()).thenThrow(new RuntimeException("TEST")); HTTPBulkLoader.ActionRequest req = getRequest(); loader.addAction("test", req); assertThatThrownBy(() -> loader.addAction("test", req)).isInstanceOf(RuntimeException.class) .hasMessageContaining("TEST"); }
@Test public void testDeadWriterDetectionOnFlushCmdSend() throws Throwable { HTTPBulkLoader loader = getBulkLoader(); loader.writerFuture = mock(Future.class); when(loader.writerFuture.isDone()).thenReturn(true); when(loader.writerFuture.get()).thenThrow(new RuntimeException("TEST")); HTTPBulkLoader.ActionRequest req = getRequest(); loader.addAction("test", req); assertThatThrownBy(loader::flush).isInstanceOf(RuntimeException.class) .hasMessageContaining("TEST"); }