public void index(TodoView todoView) { try { IndexResponse ir = transportClient .prepareIndex(TodoView.INDEX, TodoView.TYPE, todoView.getId()) .setSource(objectMapper.writeValueAsString(todoView), XContentType.JSON) .get(); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
public void index(TodoView todoView) { try { IndexResponse ir = transportClient .prepareIndex(TodoView.INDEX, TodoView.TYPE, todoView.getId()) .setSource(objectMapper.writeValueAsString(todoView), XContentType.JSON) .get(); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Test public void testIndexSearchAndRemove() throws Exception { String id = Utils.generateUniqueString(); String title = "test"; TodoView todoView = new TodoView(id, title, false, 0); todoViewService.index(todoView); Thread.sleep(2000); //Elasticsearch by default refreshes each shard every 1s List<TodoView> todoViews = todoViewService.search(title); Assert.assertTrue(todoViews.stream().anyMatch(view -> id.equals(view.getId()))); todoViewService.remove(id); Thread.sleep(2000); todoViews = todoViewService.search(title); Assert.assertFalse(todoViews.stream().anyMatch(view -> id.equals(view.getId()))); } }
@Test public void testIndexSearchAndRemove() throws Exception { String id = Utils.generateUniqueString(); String title = "test"; TodoView todoView = new TodoView(id, title, false, 0); todoViewService.index(todoView); Thread.sleep(2000); //Elasticsearch by default refreshes each shard every 1s List<TodoView> todoViews = todoViewService.search(title); Assert.assertTrue(todoViews.stream().anyMatch(view -> id.equals(view.getId()))); todoViewService.remove(id); Thread.sleep(2000); todoViews = todoViewService.search(title); Assert.assertFalse(todoViews.stream().anyMatch(view -> id.equals(view.getId()))); } }