### Question:
TupleToRange implements Function<Tuple2<String,IndexInfo>,Iterator<QueryPlan>> { public static Iterator<QueryPlan> createDocumentRanges(JexlNode queryNode, String shard, IndexInfo indexMatches, boolean isTldQuery) { List<QueryPlan> ranges = Lists.newArrayListWithCapacity(indexMatches.uids().size()); for (IndexMatch indexMatch : indexMatches.uids()) { String docId = indexMatch.getUid(); Range range; if (isTldQuery) { range = RangeFactory.createTldDocumentSpecificRange(shard, docId); } else { range = RangeFactory.createDocumentSpecificRange(shard, docId); } if (log.isTraceEnabled()) log.trace(queryNode + " " + indexMatch.getNode()); if (log.isTraceEnabled() && null != indexMatch.getNode()) { log.trace("Building " + range + " from " + (null == queryNode ? "NoQueryNode" : JexlStringBuildingVisitor.buildQuery(queryNode)) + " actually " + JexlStringBuildingVisitor.buildQuery(indexMatch.getNode())); } ranges.add(new QueryPlan(indexMatch.getNode(), range)); } return ranges.iterator(); } TupleToRange(JexlNode currentNode, ShardQueryConfiguration config); Iterator<QueryPlan> apply(Tuple2<String,IndexInfo> tuple); static boolean isDocumentRange(IndexInfo indexInfo); static boolean isShardRange(String shard); static Iterator<QueryPlan> createDocumentRanges(JexlNode queryNode, String shard, IndexInfo indexMatches, boolean isTldQuery); static Iterator<QueryPlan> createShardRange(JexlNode queryNode, String shard, IndexInfo indexInfo); static Iterator<QueryPlan> createDayRange(JexlNode queryNode, String shard, IndexInfo indexInfo);  }### Answer:
@Test public void testGenerateDocumentRanges() { String shard = "20190314_0"; Set<String> docIds = Sets.newHashSet("docId0", "docId1", "docId2"); IndexInfo indexInfo = new IndexInfo(docIds); indexInfo.applyNode(queryNode); List<Range> expectedRanges = new ArrayList<>(3); expectedRanges.add(makeTestRange(shard, "docId0")); expectedRanges.add(makeTestRange(shard, "docId1")); expectedRanges.add(makeTestRange(shard, "docId2")); Iterator<QueryPlan> ranges = TupleToRange.createDocumentRanges(queryNode, shard, indexInfo, config.isTldQuery()); eval(expectedRanges, ranges); }
@Test public void testGenerateTldDocumentRanges() { String shard = "20190314_0"; Set<String> docIds = Sets.newHashSet("docId0", "docId1", "docId2"); IndexInfo indexInfo = new IndexInfo(docIds); indexInfo.applyNode(queryNode); List<Range> expectedRanges = new ArrayList<>(3); expectedRanges.add(makeTldTestRange(shard, "docId0")); expectedRanges.add(makeTldTestRange(shard, "docId1")); expectedRanges.add(makeTldTestRange(shard, "docId2")); config.setTldQuery(true); Iterator<QueryPlan> ranges = TupleToRange.createDocumentRanges(queryNode, shard, indexInfo, config.isTldQuery()); eval(expectedRanges, ranges); }