Fix priority parsing in HiLoQueryLaningStrategy (#11302)

This commit is contained in:
Abhishek Agarwal 2021-06-07 15:27:27 +05:30 committed by GitHub
parent 44d629319d
commit 7ffe402b87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -67,8 +67,12 @@ public class HiLoQueryLaningStrategy implements QueryLaningStrategy
public <T> Optional<String> computeLane(QueryPlus<T> query, Set<SegmentServerSelector> segments)
{
final Query<T> theQuery = query.getQuery();
// QueryContexts.getPriority gives a default, since we are setting priority
final Integer priority = theQuery.getContextValue(QueryContexts.PRIORITY_KEY);
// QueryContexts.getPriority gives a default, but it can parse the value to integer. Before calling QueryContexts.getPriority
// we make sure that priority has been set.
Integer priority = null;
if (null != theQuery.getContextValue(QueryContexts.PRIORITY_KEY)) {
priority = QueryContexts.getPriority(theQuery);
}
final String lane = theQuery.getContextValue(QueryContexts.LANE_KEY);
if (lane == null && priority != null && priority < 0) {
return Optional.of(LOW);

View File

@ -155,6 +155,13 @@ public class HiLoQueryLaningStrategyTest
Assert.assertFalse(strategy.computeLane(QueryPlus.wrap(query), ImmutableSet.of()).isPresent());
}
@Test
public void testLaningInteractivePriority_String()
{
TimeseriesQuery query = queryBuilder.context(ImmutableMap.of(QueryContexts.PRIORITY_KEY, "100")).build();
Assert.assertFalse(strategy.computeLane(QueryPlus.wrap(query), ImmutableSet.of()).isPresent());
}
@Test
public void testLaningLowPriority()
{
@ -166,6 +173,17 @@ public class HiLoQueryLaningStrategyTest
);
}
@Test
public void testLaningLowPriority_String()
{
TimeseriesQuery query = queryBuilder.context(ImmutableMap.of(QueryContexts.PRIORITY_KEY, "-1")).build();
Assert.assertTrue(strategy.computeLane(QueryPlus.wrap(query), ImmutableSet.of()).isPresent());
Assert.assertEquals(
HiLoQueryLaningStrategy.LOW,
strategy.computeLane(QueryPlus.wrap(query), ImmutableSet.of()).get()
);
}
@Test
public void testLaningPreservesManualSetLane()
{