ccaominh commented on a change in pull request #9407: query laning and load 
shedding
URL: https://github.com/apache/druid/pull/9407#discussion_r389072849
 
 

 ##########
 File path: 
server/src/test/java/org/apache/druid/server/scheduling/HiLoQueryLaningStrategyTest.java
 ##########
 @@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.scheduling;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.objects.Object2IntMap;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.query.Druids;
+import org.apache.druid.query.QueryContexts;
+import org.apache.druid.query.QueryPlus;
+import org.apache.druid.query.aggregation.CountAggregatorFactory;
+import org.apache.druid.query.timeseries.TimeseriesQuery;
+import org.apache.druid.server.QueryLaningStrategy;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class HiLoQueryLaningStrategyTest
+{
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private Druids.TimeseriesQueryBuilder queryBuilder;
+  private HiLoQueryLaningStrategy strategy;
+
+  @Before
+  public void setup()
+  {
+    this.queryBuilder = Druids.newTimeseriesQueryBuilder()
+                              .dataSource("test")
+                              .intervals(ImmutableList.of(Intervals.ETERNITY))
+                              .granularity(Granularities.DAY)
+                              .aggregators(new 
CountAggregatorFactory("count"));
+
+    this.strategy = new HiLoQueryLaningStrategy(10);
+  }
+
+  @Test
+  public void testMaxLowThreadsRequired()
+  {
+    expectedException.expect(NullPointerException.class);
+    expectedException.expectMessage("maxLowThreads must be set");
+    QueryLaningStrategy strategy = new HiLoQueryLaningStrategy(null);
+  }
+
+  @Test
+  public void testLaneLimits()
+  {
+    Object2IntMap<String> laneConfig = strategy.getLaneLimits();
+    Assert.assertEquals(1, laneConfig.size());
+    Assert.assertTrue(laneConfig.containsKey(HiLoQueryLaningStrategy.LOW));
+    Assert.assertEquals(10, laneConfig.getInt(HiLoQueryLaningStrategy.LOW));
+  }
+
+  @Test
+  public void testLaningNoPriority()
+  {
+    TimeseriesQuery query = queryBuilder.build();
+    Assert.assertFalse(strategy.computeLane(QueryPlus.wrap(query), 
ImmutableSet.of()).isPresent());
+  }
+
+  @Test
+  public void testLaningZeroPriority()
+  {
+    TimeseriesQuery query = 
queryBuilder.context(ImmutableMap.of(QueryContexts.PRIORITY_KEY, 0)).build();
+    Assert.assertFalse(strategy.computeLane(QueryPlus.wrap(query), 
ImmutableSet.of()).isPresent());
+  }
+
+  @Test
+  public void testLaningInteractivePriority()
+  {
+    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()
+  {
+    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()
+    );
+  }
+}
 
 Review comment:
   Since the user can select a lane by setting the priority in the query 
context, I'm not sure of the benefit of also having a lane in the query 
context. Later, when there's automatic setting of the lane/priority, I think it 
should first respect the value in the query context if there's one before 
applying the automatic behavior.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to