@Test public void testSelectQueriesWithAllSelectionPolicies(){ QueryContext q1 = mock(QueryContext.class); QueryContext q2 = mock(QueryContext.class); QueryContext q3 = mock(QueryContext.class); Set<QueryContext> eligibleQueriesSet1 = Sets.newHashSet(Arrays.asList(q1, q2)); Set<QueryContext> eligibleQueriesSet2 = Sets.newHashSet(Arrays.asList(q1, q3)); Set<QueryContext> eligibleQueriesSet3 = Sets.newHashSet(Arrays.asList(q1, q2)); FinishedLensQuery mockFinishedQuery = mock(FinishedLensQuery.class); EstimatedImmutableQueryCollection mockWaitingQueries = mock(EstimatedImmutableQueryCollection.class); WaitingQueriesSelectionPolicy policy1 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy policy2 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy driverSelectionPolicy = mock(WaitingQueriesSelectionPolicy.class); when(mockFinishedQuery.getDriverSelectionPolicies()).thenReturn(ImmutableSet.of(driverSelectionPolicy)); when(policy1.selectQueries(mockFinishedQuery, mockWaitingQueries)).thenReturn(eligibleQueriesSet1); when(policy2.selectQueries(mockFinishedQuery, mockWaitingQueries)).thenReturn(eligibleQueriesSet2); when(driverSelectionPolicy.selectQueries(mockFinishedQuery, mockWaitingQueries)).thenReturn(eligibleQueriesSet3); WaitingQueriesSelector selector = new UnioningWaitingQueriesSelector(ImmutableSet.of(policy1, policy2)); Set<QueryContext> actualEligibleQueries = selector.selectQueries(mockFinishedQuery, mockWaitingQueries); Set<QueryContext> expectedEligibleQueries = Sets.newHashSet(Arrays.asList(q1, q2, q3)); assertEquals(actualEligibleQueries, expectedEligibleQueries); }
@Override public Set<QueryContext> selectQueries(final FinishedLensQuery finishedQuery, final EstimatedImmutableQueryCollection waitingQueries) { Set<WaitingQueriesSelectionPolicy> allSelectionPolicies = prepareAllSelectionPolicies(finishedQuery); List<Set<QueryContext>> candiateQueriesSets = getAllCandidateQueriesSets(finishedQuery, waitingQueries, allSelectionPolicies); return Sets.newHashSet(Iterables.concat(candiateQueriesSets)); }
UnioningWaitingQueriesSelector implements WaitingQueriesSelector { @Override public Set<QueryContext> selectQueries(final FinishedLensQuery finishedQuery, final EstimatedImmutableQueryCollection waitingQueries) { Set<WaitingQueriesSelectionPolicy> allSelectionPolicies = prepareAllSelectionPolicies(finishedQuery); List<Set<QueryContext>> candiateQueriesSets = getAllCandidateQueriesSets(finishedQuery, waitingQueries, allSelectionPolicies); return Sets.newHashSet(Iterables.concat(candiateQueriesSets)); } }
UnioningWaitingQueriesSelector implements WaitingQueriesSelector { @Override public Set<QueryContext> selectQueries(final FinishedLensQuery finishedQuery, final EstimatedImmutableQueryCollection waitingQueries) { Set<WaitingQueriesSelectionPolicy> allSelectionPolicies = prepareAllSelectionPolicies(finishedQuery); List<Set<QueryContext>> candiateQueriesSets = getAllCandidateQueriesSets(finishedQuery, waitingQueries, allSelectionPolicies); return Sets.newHashSet(Iterables.concat(candiateQueriesSets)); } UnioningWaitingQueriesSelector(
    @NonNull final ImmutableSet<WaitingQueriesSelectionPolicy> selectionPolicies); }
UnioningWaitingQueriesSelector implements WaitingQueriesSelector { @Override public Set<QueryContext> selectQueries(final FinishedLensQuery finishedQuery, final EstimatedImmutableQueryCollection waitingQueries) { Set<WaitingQueriesSelectionPolicy> allSelectionPolicies = prepareAllSelectionPolicies(finishedQuery); List<Set<QueryContext>> candiateQueriesSets = getAllCandidateQueriesSets(finishedQuery, waitingQueries, allSelectionPolicies); return Sets.newHashSet(Iterables.concat(candiateQueriesSets)); } UnioningWaitingQueriesSelector(
    @NonNull final ImmutableSet<WaitingQueriesSelectionPolicy> selectionPolicies); @Override Set<QueryContext> selectQueries(final FinishedLensQuery finishedQuery,
      final EstimatedImmutableQueryCollection waitingQueries); }
UnioningWaitingQueriesSelector implements WaitingQueriesSelector { @Override public Set<QueryContext> selectQueries(final FinishedLensQuery finishedQuery, final EstimatedImmutableQueryCollection waitingQueries) { Set<WaitingQueriesSelectionPolicy> allSelectionPolicies = prepareAllSelectionPolicies(finishedQuery); List<Set<QueryContext>> candiateQueriesSets = getAllCandidateQueriesSets(finishedQuery, waitingQueries, allSelectionPolicies); return Sets.newHashSet(Iterables.concat(candiateQueriesSets)); } UnioningWaitingQueriesSelector(
    @NonNull final ImmutableSet<WaitingQueriesSelectionPolicy> selectionPolicies); @Override Set<QueryContext> selectQueries(final FinishedLensQuery finishedQuery,
      final EstimatedImmutableQueryCollection waitingQueries);  }