@Test(dataProvider = "dpTestAllowsLaunchOfQuery") public void testAllowsLaunchOfQuery(final int currentDriverLaunchedQueries, final boolean expectedCanLaunch) { QueryContext mockCandidateQuery = mock(QueryContext.class); QueryContext mockCandidateQuery2 = mock(QueryContext.class); EstimatedImmutableQueryCollection mockLaunchedQueries = mock(EstimatedImmutableQueryCollection.class); LensDriver mockDriver = mock(LensDriver.class); LensDriver mockDriver2 = mock(LensDriver.class); when(mockCandidateQuery.getSelectedDriver()).thenReturn(mockDriver); when(mockCandidateQuery2.getSelectedDriver()).thenReturn(mockDriver2); when(mockLaunchedQueries.getQueriesCount(mockDriver)).thenReturn(currentDriverLaunchedQueries); when(mockLaunchedQueries.getQueriesCount(mockDriver2)).thenReturn(1); String actualCanLaunch = constraint.allowsLaunchOf(mockCandidateQuery, mockLaunchedQueries); if (expectedCanLaunch) { assertNull(actualCanLaunch); } else { assertNotNull(actualCanLaunch); } }
@Override public String allowsLaunchOf( final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { final LensDriver selectedDriver = candidateQuery.getSelectedDriver(); final Set<QueryContext> driverLaunchedQueries = launchedQueries.getQueries(selectedDriver); String maxConcurrentLimitation = canLaunchWithMaxConcurrentConstraint(candidateQuery, launchedQueries.getQueriesCount(selectedDriver)); if (maxConcurrentLimitation != null) { return maxConcurrentLimitation; } String maxLaunchingLimitation = canLaunchWithMaxLaunchingConstraint(driverLaunchedQueries); if (maxLaunchingLimitation != null) { return maxLaunchingLimitation; } String queueLimitation = canLaunchWithQueueConstraint(candidateQuery, driverLaunchedQueries); if (queueLimitation != null) { return queueLimitation; } String priorityLimitation = canLaunchWithPriorityConstraint(candidateQuery, driverLaunchedQueries); if (priorityLimitation != null) { return priorityLimitation; } return null; }
MaxConcurrentDriverQueriesConstraint implements QueryLaunchingConstraint { @Override public String allowsLaunchOf( final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { final LensDriver selectedDriver = candidateQuery.getSelectedDriver(); final Set<QueryContext> driverLaunchedQueries = launchedQueries.getQueries(selectedDriver); String maxConcurrentLimitation = canLaunchWithMaxConcurrentConstraint(candidateQuery, launchedQueries.getQueriesCount(selectedDriver)); if (maxConcurrentLimitation != null) { return maxConcurrentLimitation; } String maxLaunchingLimitation = canLaunchWithMaxLaunchingConstraint(driverLaunchedQueries); if (maxLaunchingLimitation != null) { return maxLaunchingLimitation; } String queueLimitation = canLaunchWithQueueConstraint(candidateQuery, driverLaunchedQueries); if (queueLimitation != null) { return queueLimitation; } String priorityLimitation = canLaunchWithPriorityConstraint(candidateQuery, driverLaunchedQueries); if (priorityLimitation != null) { return priorityLimitation; } return null; } }
MaxConcurrentDriverQueriesConstraint implements QueryLaunchingConstraint { @Override public String allowsLaunchOf( final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { final LensDriver selectedDriver = candidateQuery.getSelectedDriver(); final Set<QueryContext> driverLaunchedQueries = launchedQueries.getQueries(selectedDriver); String maxConcurrentLimitation = canLaunchWithMaxConcurrentConstraint(candidateQuery, launchedQueries.getQueriesCount(selectedDriver)); if (maxConcurrentLimitation != null) { return maxConcurrentLimitation; } String maxLaunchingLimitation = canLaunchWithMaxLaunchingConstraint(driverLaunchedQueries); if (maxLaunchingLimitation != null) { return maxLaunchingLimitation; } String queueLimitation = canLaunchWithQueueConstraint(candidateQuery, driverLaunchedQueries); if (queueLimitation != null) { return queueLimitation; } String priorityLimitation = canLaunchWithPriorityConstraint(candidateQuery, driverLaunchedQueries); if (priorityLimitation != null) { return priorityLimitation; } return null; }  }
MaxConcurrentDriverQueriesConstraint implements QueryLaunchingConstraint { @Override public String allowsLaunchOf( final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { final LensDriver selectedDriver = candidateQuery.getSelectedDriver(); final Set<QueryContext> driverLaunchedQueries = launchedQueries.getQueries(selectedDriver); String maxConcurrentLimitation = canLaunchWithMaxConcurrentConstraint(candidateQuery, launchedQueries.getQueriesCount(selectedDriver)); if (maxConcurrentLimitation != null) { return maxConcurrentLimitation; } String maxLaunchingLimitation = canLaunchWithMaxLaunchingConstraint(driverLaunchedQueries); if (maxLaunchingLimitation != null) { return maxLaunchingLimitation; } String queueLimitation = canLaunchWithQueueConstraint(candidateQuery, driverLaunchedQueries); if (queueLimitation != null) { return queueLimitation; } String priorityLimitation = canLaunchWithPriorityConstraint(candidateQuery, driverLaunchedQueries); if (priorityLimitation != null) { return priorityLimitation; } return null; }  @Override String allowsLaunchOf(
    final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries); }
MaxConcurrentDriverQueriesConstraint implements QueryLaunchingConstraint { @Override public String allowsLaunchOf( final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { final LensDriver selectedDriver = candidateQuery.getSelectedDriver(); final Set<QueryContext> driverLaunchedQueries = launchedQueries.getQueries(selectedDriver); String maxConcurrentLimitation = canLaunchWithMaxConcurrentConstraint(candidateQuery, launchedQueries.getQueriesCount(selectedDriver)); if (maxConcurrentLimitation != null) { return maxConcurrentLimitation; } String maxLaunchingLimitation = canLaunchWithMaxLaunchingConstraint(driverLaunchedQueries); if (maxLaunchingLimitation != null) { return maxLaunchingLimitation; } String queueLimitation = canLaunchWithQueueConstraint(candidateQuery, driverLaunchedQueries); if (queueLimitation != null) { return queueLimitation; } String priorityLimitation = canLaunchWithPriorityConstraint(candidateQuery, driverLaunchedQueries); if (priorityLimitation != null) { return priorityLimitation; } return null; }  @Override String allowsLaunchOf(
    final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries);  }