MetadataResultIterator implements Iterator<Map<String, Object>> { @Override public Map<String, Object> next() { if(!hasNext()) { throw new NoSuchElementException(); } Map<String, Object> nextResult = resultsBatchIterator.next(); if(!resultsBatchIterator.hasNext()){ if(resultsBatch.size()<limit) { if (!partitionRunIdIterator.hasNext()) { hasNext = false; } else { getNextQuery(); getNextBatch(); } } else { getNextBatch(); } } return nextResult; } MetadataResultIterator(NavApiCient client, MetadataType type,
                                String query, Integer limit,
                                Iterable<String> extractorRunIds); @Override boolean hasNext(); @Override Map<String, Object> next(); @Override void remove(); static final Integer MAX_QUERY_PARTITION_SIZE; }
@Test(expected = NoSuchElementException.class) public void testNextNone(){ List<String> extractorRunIds = Lists.newArrayList("x##0", "x##1", "x##2"); MetadataResultIterator metadataResultIterator = new MetadataResultIterator(client, MetadataType.ENTITIES,"identity:*", 100, extractorRunIds); Map<String, Object> next = metadataResultIterator.next(); }
@Test public void testNextEntities(){ List<String> extractorRunIds = Lists.newArrayList("x##0", "x##1", "x##2"); Map<String, Object> singleResult = Maps.newHashMap(); singleResult.put("field", "value"); entityBatch.setResults(Lists.newArrayList(singleResult)); MetadataResultIterator metadataResultIterator = new MetadataResultIterator(client, MetadataType.ENTITIES,"identity:*", 100, extractorRunIds); assertEquals(entityBatch.getResults().get(0), metadataResultIterator.next()); }
@Test public void testNextRelations(){ List<String> extractorRunIds = Lists.newArrayList("x##0", "x##1", "x##2"); Map<String, Object> singleResult = Maps.newHashMap(); singleResult.put("field", "value"); relationBatch.setResults(Lists.newArrayList(singleResult)); MetadataResultIterator metadataResultIterator = new MetadataResultIterator(client, MetadataType.RELATIONS, "identity:*", 100, extractorRunIds); assertEquals(relationBatch.getResults().get(0), metadataResultIterator.next()); }