@Test public void testCanLaunchShouldReturnFalseWhenAtleastOneConstraintFails() { QueryContext mockCandidateQuery = mock(QueryContext.class); EstimatedImmutableQueryCollection mockRunningQueries = mock(EstimatedImmutableQueryCollection.class); final QueryLaunchingConstraint constraint1 = mock(QueryLaunchingConstraint.class); final QueryLaunchingConstraint constraint2 = mock(QueryLaunchingConstraint.class); QueryLaunchingConstraintsChecker constraintsChecker = new DefaultQueryLaunchingConstraintsChecker(ImmutableSet.of(constraint1, constraint2)); QueryStatus status = QueryStatus.getQueuedStatus(); final QueryLaunchingConstraint driverConstraint = mock(QueryLaunchingConstraint.class); when(mockCandidateQuery.getSelectedDriverQueryConstraints()).thenReturn(ImmutableSet.of(driverConstraint)); when(mockCandidateQuery.getStatus()).thenReturn(status); when(constraint1.allowsLaunchOf(mockCandidateQuery, mockRunningQueries)).thenReturn(null); when(constraint2.allowsLaunchOf(mockCandidateQuery, mockRunningQueries)).thenReturn("constraint 2 failed"); when(driverConstraint.allowsLaunchOf(mockCandidateQuery, mockRunningQueries)) .thenReturn("driver constraint failed"); boolean canLaunchQuery = constraintsChecker.canLaunch(mockCandidateQuery, mockRunningQueries); Assert.assertFalse(canLaunchQuery); Assert.assertEquals(mockCandidateQuery.getStatus().getProgressMessage(), "constraint 2 failed"); }
@Override public boolean canLaunch(final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { Set<QueryLaunchingConstraint> allConstraints = prepareAllConstraints(candidateQuery); for (QueryLaunchingConstraint queryConstraint : allConstraints) { String launchRejectionMessage = queryConstraint.allowsLaunchOf(candidateQuery, launchedQueries); if (launchRejectionMessage != null) { log.info("query {} not allowed to launch. Constraint failed: {} with message: {}", candidateQuery, queryConstraint, launchRejectionMessage); candidateQuery.getStatus().setProgressMessage(launchRejectionMessage); return false; } } return true; }
DefaultQueryLaunchingConstraintsChecker implements QueryLaunchingConstraintsChecker { @Override public boolean canLaunch(final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { Set<QueryLaunchingConstraint> allConstraints = prepareAllConstraints(candidateQuery); for (QueryLaunchingConstraint queryConstraint : allConstraints) { String launchRejectionMessage = queryConstraint.allowsLaunchOf(candidateQuery, launchedQueries); if (launchRejectionMessage != null) { log.info("query {} not allowed to launch. Constraint failed: {} with message: {}", candidateQuery, queryConstraint, launchRejectionMessage); candidateQuery.getStatus().setProgressMessage(launchRejectionMessage); return false; } } return true; } }
DefaultQueryLaunchingConstraintsChecker implements QueryLaunchingConstraintsChecker { @Override public boolean canLaunch(final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { Set<QueryLaunchingConstraint> allConstraints = prepareAllConstraints(candidateQuery); for (QueryLaunchingConstraint queryConstraint : allConstraints) { String launchRejectionMessage = queryConstraint.allowsLaunchOf(candidateQuery, launchedQueries); if (launchRejectionMessage != null) { log.info("query {} not allowed to launch. Constraint failed: {} with message: {}", candidateQuery, queryConstraint, launchRejectionMessage); candidateQuery.getStatus().setProgressMessage(launchRejectionMessage); return false; } } return true; } DefaultQueryLaunchingConstraintsChecker(
    @NonNull final ImmutableSet<QueryLaunchingConstraint> lensQueryConstraints); }
DefaultQueryLaunchingConstraintsChecker implements QueryLaunchingConstraintsChecker { @Override public boolean canLaunch(final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { Set<QueryLaunchingConstraint> allConstraints = prepareAllConstraints(candidateQuery); for (QueryLaunchingConstraint queryConstraint : allConstraints) { String launchRejectionMessage = queryConstraint.allowsLaunchOf(candidateQuery, launchedQueries); if (launchRejectionMessage != null) { log.info("query {} not allowed to launch. Constraint failed: {} with message: {}", candidateQuery, queryConstraint, launchRejectionMessage); candidateQuery.getStatus().setProgressMessage(launchRejectionMessage); return false; } } return true; } DefaultQueryLaunchingConstraintsChecker(
    @NonNull final ImmutableSet<QueryLaunchingConstraint> lensQueryConstraints); @Override boolean canLaunch(final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries); }
DefaultQueryLaunchingConstraintsChecker implements QueryLaunchingConstraintsChecker { @Override public boolean canLaunch(final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { Set<QueryLaunchingConstraint> allConstraints = prepareAllConstraints(candidateQuery); for (QueryLaunchingConstraint queryConstraint : allConstraints) { String launchRejectionMessage = queryConstraint.allowsLaunchOf(candidateQuery, launchedQueries); if (launchRejectionMessage != null) { log.info("query {} not allowed to launch. Constraint failed: {} with message: {}", candidateQuery, queryConstraint, launchRejectionMessage); candidateQuery.getStatus().setProgressMessage(launchRejectionMessage); return false; } } return true; } DefaultQueryLaunchingConstraintsChecker(
    @NonNull final ImmutableSet<QueryLaunchingConstraint> lensQueryConstraints); @Override boolean canLaunch(final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries);  }