QueryTaskUtils { public static void mergeQueryResults( List<ServiceDocumentQueryResult> dataSources, boolean isAscOrder, ServiceDocumentQueryResult result) { mergeQueryResults(dataSources, isAscOrder, EnumSet.noneOf(QueryOption.class), result); } private  QueryTaskUtils(); static void processQueryResults(ServiceHost host,
            List<ServiceDocumentQueryResult> dataSources,
            boolean isAscOrder, EnumSet<QueryOption> queryOptions,
            NodeGroupBroadcastResponse nodeGroupResponse, ServiceDocumentQueryResult result,
            BiConsumer<ServiceDocumentQueryResult, Throwable> onCompletion); static void mergeQueryResults(
            List<ServiceDocumentQueryResult> dataSources, boolean isAscOrder, ServiceDocumentQueryResult result); static void mergeQueryResults(
            List<ServiceDocumentQueryResult> dataSources,
            boolean isAscOrder, EnumSet<QueryOption> queryOptions, ServiceDocumentQueryResult result); static void expandLinks(ServiceHost host, QueryTask task, Operation op); static Set<String> getExpandedQueryPropertyNames(ServiceDocumentDescription description); static void failTask(Operation get, Throwable ex);  }
@Test public void testMergeQueryResultsWithSameData() { ServiceDocumentQueryResult result1 = createServiceDocumentQueryResult( new int[] { 1, 10, 2, 3, 4, 5, 6, 7, 8, 9 }); ServiceDocumentQueryResult result2 = createServiceDocumentQueryResult( new int[] { 1, 10, 2, 3, 4, 5, 6, 7, 8, 9 }); ServiceDocumentQueryResult result3 = createServiceDocumentQueryResult( new int[] { 1, 10, 2, 3, 4, 5, 6, 7, 8, 9 }); List<ServiceDocumentQueryResult> resultsToMerge = Arrays.asList(result1, result2, result3); ServiceDocumentQueryResult mergeResult = new ServiceDocumentQueryResult(); QueryTaskUtils.mergeQueryResults(resultsToMerge, true, mergeResult); assertTrue(verifyMergeResult(mergeResult, new int[] { 1, 10, 2, 3, 4, 5, 6, 7, 8, 9 })); }
@Test public void testMergeQueryResultsWithDifferentData() { ServiceDocumentQueryResult result1 = createServiceDocumentQueryResult( new int[] { 1, 3, 4, 5, 7, 9 }); ServiceDocumentQueryResult result2 = createServiceDocumentQueryResult( new int[] { 10, 2, 3, 4, 5, 6, 9 }); ServiceDocumentQueryResult result3 = createServiceDocumentQueryResult( new int[] { 1, 10, 2, 3, 4, 8 }); List<ServiceDocumentQueryResult> resultsToMerge = Arrays.asList(result1, result2, result3); ServiceDocumentQueryResult mergeResult = new ServiceDocumentQueryResult(); QueryTaskUtils.mergeQueryResults(resultsToMerge, true, mergeResult); assertTrue(verifyMergeResult(mergeResult, new int[] { 1, 10, 2, 3, 4, 5, 6, 7, 8, 9 })); }
@Test public void testMergeQueryResultsWithEmptySet() { ServiceDocumentQueryResult result1 = createServiceDocumentQueryResult( new int[] { 1, 3, 4, 5, 7, 8, 9 }); ServiceDocumentQueryResult result2 = createServiceDocumentQueryResult( new int[] { 10, 2, 3, 4, 5, 6, 9 }); ServiceDocumentQueryResult result3 = createServiceDocumentQueryResult(new int[] {}); List<ServiceDocumentQueryResult> resultsToMerge = Arrays.asList(result1, result2, result3); ServiceDocumentQueryResult mergeResult = new ServiceDocumentQueryResult(); QueryTaskUtils.mergeQueryResults(resultsToMerge, true, mergeResult); assertTrue(verifyMergeResult(mergeResult, new int[] { 1, 10, 2, 3, 4, 5, 6, 7, 8, 9 })); }
@Test public void testMergeQueryResultsWithAllEmpty() { ServiceDocumentQueryResult result1 = createServiceDocumentQueryResult(new int[] {}); ServiceDocumentQueryResult result2 = createServiceDocumentQueryResult(new int[] {}); ServiceDocumentQueryResult result3 = createServiceDocumentQueryResult(new int[] {}); List<ServiceDocumentQueryResult> resultsToMerge = Arrays.asList(result1, result2, result3); ServiceDocumentQueryResult mergeResult = new ServiceDocumentQueryResult(); QueryTaskUtils.mergeQueryResults(resultsToMerge, true, mergeResult); assertTrue(verifyMergeResult(mergeResult, new int[] {})); }
@Test public void testMergeQueryResultsInDescOrder() { ServiceDocumentQueryResult result1 = createServiceDocumentQueryResult( new int[] { 9, 7, 5, 4, 3, 1 }); ServiceDocumentQueryResult result2 = createServiceDocumentQueryResult( new int[] { 9, 6, 5, 4, 3, 2, 10 }); ServiceDocumentQueryResult result3 = createServiceDocumentQueryResult( new int[] { 8, 4, 3, 2, 10, 1 }); List<ServiceDocumentQueryResult> resultsToMerge = Arrays.asList(result1, result2, result3); ServiceDocumentQueryResult mergeResult = new ServiceDocumentQueryResult(); QueryTaskUtils.mergeQueryResults(resultsToMerge, false, mergeResult); assertTrue(verifyMergeResult(mergeResult, new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 10, 1 })); }
@Test public void testMergeQueryResultsWhenCountOptions() { ServiceDocumentQueryResult result1 = createServiceDocumentQueryResult( new int[] { 9, 7, 5, 4, 3, 1 }); result1.documentLinks.clear(); result1.documents.clear(); ServiceDocumentQueryResult result2 = createServiceDocumentQueryResult( new int[] { 9, 6, 5, 4, 3, 2, 10 }); result2.documentLinks.clear(); result2.documents.clear(); ServiceDocumentQueryResult result3 = createServiceDocumentQueryResult( new int[] { 8, 4, 3, 2, 10, 1 }); result3.documentLinks.clear(); result3.documents.clear(); List<ServiceDocumentQueryResult> resultsToMerge = Arrays.asList(result1, result2, result3); ServiceDocumentQueryResult mergeResult = new ServiceDocumentQueryResult(); QueryTaskUtils.mergeQueryResults(resultsToMerge, false, EnumSet.of(QueryOption.COUNT), mergeResult); assertEquals(result2.documentCount, mergeResult.documentCount); }