Source:
public void testSaveAndScroll() throws Exception { NXAuditEventsService audit = (NXAuditEventsService) Framework.getRuntime() .getComponent(NXAuditEventsService.NAME); assertNotNull(audit); ESAuditBackend esBackend = (ESAuditBackend) audit.getBackend(); List<String> jsonEntries = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); for (int i = 0; i < 42; i++) { ObjectNode logEntryJson = mapper.createObjectNode(); logEntryJson.put(LOG_ID, Integer.valueOf(i).longValue()); logEntryJson.put(LOG_EVENT_ID, "idForAuditStorage"); jsonEntries.add(mapper.writeValueAsString(logEntryJson)); } esBackend.append(jsonEntries); LogEntryGen.flushAndSync(); AuditQueryBuilder builder = new AuditQueryBuilder().predicates(Predicates.eq(LOG_EVENT_ID, "idForAuditStorage")); List<LogEntry> logs = esBackend.queryLogs(builder); assertEquals(42, logs.size()); ScrollResult<String> scrollResult = esBackend.scroll(builder, 5, 10); int total = 0; while (scrollResult.hasResults()) { assertTrue(scrollResult.getResults().size() <= 5); jsonEntries = scrollResult.getResults(); List<LogEntry> entries = jsonEntries.stream().map(json -> { try { return mapper.readValue(json, LogEntryImpl.class); } catch (IOException e) { throw new UncheckedIOException(e); } }).collect(Collectors.toList()); entries.forEach(entry -> assertEquals("idForAuditStorage", entry.getEventId())); total += entries.size(); scrollResult = esBackend.scroll(scrollResult.getScrollId()); } assertEquals(42, total); }

Target:
public void testSaveAndScroll() throws Exception { NXAuditEventsService audit = (NXAuditEventsService) Framework.getRuntime() .getComponent(NXAuditEventsService.NAME); assertNotNull(audit); ESAuditBackend esBackend = (ESAuditBackend) audit.getBackend(); String idForAuditStorage = "idForAuditStorage"; ObjectMapper mapper = new ObjectMapper(); List<String> jsonEntries = new ArrayList<>(); List<Long> ids = new ArrayList<>(); for (int i = 1; i <= 42; i++) { ObjectNode logEntryJson = mapper.createObjectNode(); logEntryJson.put(LOG_ID, Integer.valueOf(i).longValue()); logEntryJson.put(LOG_EVENT_ID, idForAuditStorage); jsonEntries.add(mapper.writeValueAsString(logEntryJson)); ids.add(Long.valueOf(i)); } esBackend.append(jsonEntries); LogEntryGen.flushAndSync(); AuditQueryBuilder builder = new AuditQueryBuilder().predicates(Predicates.eq(LOG_EVENT_ID, idForAuditStorage)); List<LogEntry> logs = esBackend.queryLogs(builder); assertEquals(42, logs.size()); ScrollResult<String> scrollResult = esBackend.scroll(builder, 5, 10); int total = 0; while (scrollResult.hasResults()) { assertTrue(scrollResult.getResults().size() <= 5); jsonEntries = scrollResult.getResults(); List<LogEntry> entries = jsonEntries.stream().map(json -> { try { return mapper.readValue(json, LogEntryImpl.class); } catch (IOException e) { throw new UncheckedIOException(e); } }).collect(Collectors.toList()); for (LogEntry entry : entries) { assertTrue(ids.remove(Long.valueOf(entry.getId()))); assertEquals(idForAuditStorage, entry.getEventId()); } total += entries.size(); scrollResult = esBackend.scroll(scrollResult.getScrollId()); } assertEquals(42, total); assertTrue(ids.isEmpty()); LogEntry logEntry = esBackend.getLogEntryByID(4); assertNotNull(logEntry); assertEquals(4, logEntry.getId()); assertEquals(idForAuditStorage, logEntry.getEventId()); }