@Test(dataProvider = "dpTestPerQueueConstraints") public void testPerQueueConstraints(final String[] launchedQueues, final String candidateQueue, final boolean expectedCanLaunch) { EstimatedImmutableQueryCollection mockLaunchedQueries = mock(EstimatedImmutableQueryCollection.class); LensDriver mockDriver = mock(LensDriver.class); Set<QueryContext> launchedQueries = new HashSet<>(); for (String queue : launchedQueues) { QueryContext context = mock(QueryContext.class); when(context.getQueue()).thenReturn(queue); launchedQueries.add(context); } when(mockLaunchedQueries.getQueries(mockDriver)).thenReturn(launchedQueries); when(mockLaunchedQueries.getQueriesCount(mockDriver)).thenReturn(launchedQueries.size()); QueryContext mockCandidateQuery = mock(QueryContext.class); when(mockCandidateQuery.getQueue()).thenReturn(candidateQueue); when(mockCandidateQuery.getSelectedDriver()).thenReturn(mockDriver); String actualCanLaunch = perQueueConstraint.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);  }