You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by pr...@apache.org on 2016/05/31 14:44:16 UTC
lens git commit: LENS-661: Added Weighted driver selector
Repository: lens
Updated Branches:
refs/heads/master 478d6d8a1 -> 1774ced2e
LENS-661: Added Weighted driver selector
Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/1774ced2
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/1774ced2
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/1774ced2
Branch: refs/heads/master
Commit: 1774ced2e49d4ffa8f68f1493c1e9a26fc2e119c
Parents: 478d6d8
Author: Anshul Gupta <me...@gmail.com>
Authored: Tue May 31 20:13:37 2016 +0530
Committer: Rajat Khandelwal <ra...@gmail.com>
Committed: Tue May 31 20:13:37 2016 +0530
----------------------------------------------------------------------
.../lens/driver/cube/TestMinCostSelector.java | 116 --------
.../lens/server/api/LensConfConstants.java | 15 +
.../driver/WeightedQueryCostDriverSelector.java | 101 +++++++
.../server/api/driver/TestMinCostSelector.java | 104 +++++++
.../api/driver/TestWeightedCostSelector.java | 288 +++++++++++++++++++
src/site/apt/admin/jdbcdriver-config.apt | 3 +-
6 files changed, 510 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lens/blob/1774ced2/lens-cube/src/test/java/org/apache/lens/driver/cube/TestMinCostSelector.java
----------------------------------------------------------------------
diff --git a/lens-cube/src/test/java/org/apache/lens/driver/cube/TestMinCostSelector.java b/lens-cube/src/test/java/org/apache/lens/driver/cube/TestMinCostSelector.java
deleted file mode 100644
index 8267229..0000000
--- a/lens-cube/src/test/java/org/apache/lens/driver/cube/TestMinCostSelector.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * 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.lens.driver.cube;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.lens.api.LensConf;
-import org.apache.lens.server.api.driver.LensDriver;
-import org.apache.lens.server.api.driver.MinQueryCostSelector;
-import org.apache.lens.server.api.driver.MockDriver;
-import org.apache.lens.server.api.driver.MockFailDriver;
-import org.apache.lens.server.api.error.LensException;
-import org.apache.lens.server.api.query.MockQueryContext;
-
-import org.apache.hadoop.conf.Configuration;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * The Class TestMinCostSelector.
- */
-public class TestMinCostSelector {
-
- private MockQueryContext createMockContext(String query, Configuration conf, LensConf lensConf,
- Map<LensDriver, String> driverQueries) throws LensException {
- MockQueryContext ctx = new MockQueryContext(query, lensConf, conf, driverQueries.keySet());
- ctx.setDriverQueries(driverQueries);
- ctx.estimateCostForDrivers();
- return ctx;
- }
-
- private MockQueryContext createMockContext(String query, Configuration conf, LensConf lensConf,
- List<LensDriver> drivers, Map<LensDriver, String> driverQueries) throws LensException {
- MockQueryContext ctx = new MockQueryContext(query, lensConf, conf, driverQueries.keySet());
- ctx.setDriverQueries(driverQueries);
- ctx.estimateCostForDrivers();
- return ctx;
- }
-
- @Test
- public void testMinCostSelector() throws LensException {
- MinQueryCostSelector selector = new MinQueryCostSelector();
- List<LensDriver> drivers = new ArrayList<LensDriver>();
- Map<LensDriver, String> driverQueries = new HashMap<LensDriver, String>();
- Configuration conf = new Configuration();
- LensConf qconf = new LensConf();
-
- MockDriver d1 = new MockDriver();
- d1.configure(conf, null, null);
- MockDriver d2 = new MockDriver();
- d2.configure(conf, null, null);
- MockFailDriver fd1 = new MockFailDriver();
- fd1.configure(conf, null, null);
- MockFailDriver fd2 = new MockFailDriver();
- fd2.configure(conf, null, null);
-
- drivers.add(d1);
- drivers.add(d2);
- String query = "test query";
- driverQueries.put(d1, query);
-
- MockQueryContext ctx = createMockContext(query, conf, qconf, driverQueries);
- LensDriver selected = selector.select(ctx, conf);
-
- Assert.assertEquals(d1, selected);
- driverQueries.put(d2, query);
- driverQueries.remove(d1);
- ctx = createMockContext(query, conf, qconf, driverQueries);
-
- selected = selector.select(ctx, conf);
- Assert.assertEquals(d2, selected);
-
- drivers.add(fd1);
- driverQueries.put(fd1, query);
-
- ctx = createMockContext(query, conf, qconf, driverQueries);
- selected = selector.select(ctx, conf);
- Assert.assertEquals(d2, selected);
-
- drivers.add(fd2);
- driverQueries.put(fd2, query);
- ctx = createMockContext(query, conf, qconf, driverQueries);
-
- selected = selector.select(ctx, conf);
- Assert.assertEquals(d2, selected);
-
- drivers.clear();
- driverQueries.clear();
- drivers.add(d1);
- drivers.add(fd1);
- driverQueries.put(d1, query);
- ctx = createMockContext(query, conf, qconf, drivers, driverQueries);
- selected = selector.select(ctx, conf);
- Assert.assertEquals(d1, selected);
- }
-}
http://git-wip-us.apache.org/repos/asf/lens/blob/1774ced2/lens-server-api/src/main/java/org/apache/lens/server/api/LensConfConstants.java
----------------------------------------------------------------------
diff --git a/lens-server-api/src/main/java/org/apache/lens/server/api/LensConfConstants.java b/lens-server-api/src/main/java/org/apache/lens/server/api/LensConfConstants.java
index 85f54d1..0a81f7b 100644
--- a/lens-server-api/src/main/java/org/apache/lens/server/api/LensConfConstants.java
+++ b/lens-server-api/src/main/java/org/apache/lens/server/api/LensConfConstants.java
@@ -52,6 +52,11 @@ public final class LensConfConstants {
public static final String METASTORE_PFX = "lens.metastore.";
/**
+ * The Constant DRIVER_PFX.
+ */
+ public static final String DRIVER_PFX = "lens.driver.";
+
+ /**
* The Constant DRIVER_TYPES_AND_CLASSES
*/
public static final String DRIVER_TYPES_AND_CLASSES = SERVER_PFX + "drivers";
@@ -962,6 +967,16 @@ public final class LensConfConstants {
public static final String DRIVERS_BASE_DIR = "drivers";
/**
+ * The driver weight property
+ */
+ public static final String DRIVER_WEIGHT = DRIVER_PFX + "weight";
+
+ /**
+ * Default driver weight
+ */
+ public static final int DEFAULT_DRIVER_WEIGHT = 1;
+
+ /**
* Name of the property that holds the path of "conf" directory of server
*/
public static final String CONFIG_LOCATION = "config.location";
http://git-wip-us.apache.org/repos/asf/lens/blob/1774ced2/lens-server-api/src/main/java/org/apache/lens/server/api/driver/WeightedQueryCostDriverSelector.java
----------------------------------------------------------------------
diff --git a/lens-server-api/src/main/java/org/apache/lens/server/api/driver/WeightedQueryCostDriverSelector.java b/lens-server-api/src/main/java/org/apache/lens/server/api/driver/WeightedQueryCostDriverSelector.java
new file mode 100644
index 0000000..167e79a
--- /dev/null
+++ b/lens-server-api/src/main/java/org/apache/lens/server/api/driver/WeightedQueryCostDriverSelector.java
@@ -0,0 +1,101 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.lens.server.api.driver;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+
+import static org.apache.lens.server.api.LensConfConstants.DEFAULT_DRIVER_WEIGHT;
+import static org.apache.lens.server.api.LensConfConstants.DRIVER_WEIGHT;
+
+import org.apache.lens.server.api.query.AbstractQueryContext;
+import org.apache.lens.server.api.query.cost.QueryCost;
+
+import org.apache.hadoop.conf.Configuration;
+
+import lombok.extern.slf4j.Slf4j;
+
+
+@Slf4j
+public class WeightedQueryCostDriverSelector implements DriverSelector {
+ /**
+ * Returns the driver that has the minimum query cost according to predefined driver allocation ratios.
+ *
+ * @param ctx the context
+ * @param conf the conf
+ * @return the lens driver
+ */
+ @Override
+ public LensDriver select(final AbstractQueryContext ctx, final Configuration conf) {
+
+ final Collection<LensDriver> drivers = ctx.getDriverContext().getDriversWithValidQueryCost();
+
+ log.info("Candidate drivers: {}", drivers);
+ if (log.isDebugEnabled()) {
+ for (LensDriver driver : drivers) {
+ log.debug("Cost on driver {}: {}", driver, ctx.getDriverQueryCost(driver));
+ log.debug("Driver ratio: {}", driver.getConf().getDouble(DRIVER_WEIGHT, DEFAULT_DRIVER_WEIGHT));
+ }
+ log.debug("Driver ratio: " + DEFAULT_DRIVER_WEIGHT + " => lens.driver.weight not set for that driver.");
+ }
+
+ //The min-cost driver
+ final LensDriver minCostDriver = Collections.min(drivers, new Comparator<LensDriver>() {
+ @Override
+ public int compare(LensDriver d1, LensDriver d2) {
+ final QueryCost c1 = ctx.getDriverQueryCost(d1);
+ final QueryCost c2 = ctx.getDriverQueryCost(d2);
+ return c1.compareTo(c2);
+ }
+ });
+
+ //The collection of minimum cost drivers
+ final QueryCost minCost = ctx.getDriverQueryCost(minCostDriver);
+ final ArrayList<LensDriver> eligibleDrivers = new ArrayList<>();
+ for (LensDriver driver : drivers) {
+ if (ctx.getDriverQueryCost(driver).equals(minCost)) {
+ eligibleDrivers.add(driver);
+ }
+ }
+ //Return the minCostDriver if there is only one min cost driver
+ if (eligibleDrivers.size() == 1){
+ return minCostDriver;
+ }
+ final Collection<LensDriver> minCostDrivers = Collections.unmodifiableCollection(eligibleDrivers);
+
+ //The driverRatio Sum across all minimum cost drivers
+ double driverRatioSum = 0;
+ for (LensDriver driver : minCostDrivers) {
+ driverRatioSum = driverRatioSum + driver.getConf().getDouble(DRIVER_WEIGHT, DEFAULT_DRIVER_WEIGHT);
+ }
+
+ //Weighted random allocation
+ driverRatioSum = Math.random()*driverRatioSum;
+
+ for (LensDriver driver : minCostDrivers){
+ driverRatioSum -= driver.getConf().getDouble(DRIVER_WEIGHT, DEFAULT_DRIVER_WEIGHT);
+ if (driverRatioSum <= 0){
+ return driver;
+ }
+ }
+ return minCostDriver;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lens/blob/1774ced2/lens-server-api/src/test/java/org/apache/lens/server/api/driver/TestMinCostSelector.java
----------------------------------------------------------------------
diff --git a/lens-server-api/src/test/java/org/apache/lens/server/api/driver/TestMinCostSelector.java b/lens-server-api/src/test/java/org/apache/lens/server/api/driver/TestMinCostSelector.java
new file mode 100644
index 0000000..3f45745
--- /dev/null
+++ b/lens-server-api/src/test/java/org/apache/lens/server/api/driver/TestMinCostSelector.java
@@ -0,0 +1,104 @@
+/**
+ * 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.lens.server.api.driver;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lens.api.LensConf;
+import org.apache.lens.server.api.error.LensException;
+import org.apache.lens.server.api.query.MockQueryContext;
+
+import org.apache.hadoop.conf.Configuration;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * The Class TestMinCostSelector.
+ */
+public class TestMinCostSelector {
+
+ private MockQueryContext createMockContext(String query, Configuration conf, LensConf lensConf,
+ Map<LensDriver, String> driverQueries) throws LensException {
+ MockQueryContext ctx = new MockQueryContext(query, lensConf, conf, driverQueries.keySet());
+ ctx.setDriverQueries(driverQueries);
+ ctx.estimateCostForDrivers();
+ return ctx;
+ }
+
+ @Test
+ public void testMinCostSelector() throws LensException {
+ MinQueryCostSelector selector = new MinQueryCostSelector();
+ List<LensDriver> drivers = new ArrayList<LensDriver>();
+ Map<LensDriver, String> driverQueries = new HashMap<LensDriver, String>();
+ Configuration conf = new Configuration();
+ LensConf qconf = new LensConf();
+
+ MockDriver d1 = new MockDriver();
+ d1.configure(conf, null, null);
+ MockDriver d2 = new MockDriver();
+ d2.configure(conf, null, null);
+ MockFailDriver fd1 = new MockFailDriver();
+ fd1.configure(conf, null, null);
+ MockFailDriver fd2 = new MockFailDriver();
+ fd2.configure(conf, null, null);
+
+ drivers.add(d1);
+ drivers.add(d2);
+ String query = "test query";
+ driverQueries.put(d1, query);
+
+ MockQueryContext ctx = createMockContext(query, conf, qconf, driverQueries);
+ LensDriver selected = selector.select(ctx, conf);
+
+ Assert.assertEquals(d1, selected);
+ driverQueries.put(d2, query);
+ driverQueries.remove(d1);
+ ctx = createMockContext(query, conf, qconf, driverQueries);
+
+ selected = selector.select(ctx, conf);
+ Assert.assertEquals(d2, selected);
+
+ drivers.add(fd1);
+ driverQueries.put(fd1, query);
+
+ ctx = createMockContext(query, conf, qconf, driverQueries);
+ selected = selector.select(ctx, conf);
+ Assert.assertEquals(d2, selected);
+
+ drivers.add(fd2);
+ driverQueries.put(fd2, query);
+ ctx = createMockContext(query, conf, qconf, driverQueries);
+
+ selected = selector.select(ctx, conf);
+ Assert.assertEquals(d2, selected);
+
+ drivers.clear();
+ driverQueries.clear();
+ drivers.add(d1);
+ drivers.add(fd1);
+ driverQueries.put(d1, query);
+ ctx = createMockContext(query, conf, qconf, driverQueries);
+ selected = selector.select(ctx, conf);
+ Assert.assertEquals(d1, selected);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lens/blob/1774ced2/lens-server-api/src/test/java/org/apache/lens/server/api/driver/TestWeightedCostSelector.java
----------------------------------------------------------------------
diff --git a/lens-server-api/src/test/java/org/apache/lens/server/api/driver/TestWeightedCostSelector.java b/lens-server-api/src/test/java/org/apache/lens/server/api/driver/TestWeightedCostSelector.java
new file mode 100644
index 0000000..17161cc
--- /dev/null
+++ b/lens-server-api/src/test/java/org/apache/lens/server/api/driver/TestWeightedCostSelector.java
@@ -0,0 +1,288 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.lens.server.api.driver;
+
+import static java.lang.Math.abs;
+
+import static org.apache.lens.server.api.LensConfConstants.DRIVER_WEIGHT;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lens.api.LensConf;
+import org.apache.lens.server.api.error.LensException;
+import org.apache.lens.server.api.query.MockQueryContext;
+import org.apache.lens.server.api.query.cost.FactPartitionBasedQueryCost;
+
+import org.apache.hadoop.conf.Configuration;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * The Class TestWeightedCostSelector.
+ */
+public class TestWeightedCostSelector {
+
+ private WeightedQueryCostDriverSelector selector = new WeightedQueryCostDriverSelector();
+ private Configuration conf = new Configuration();
+ private LensConf qconf = new LensConf();
+ private FactPartitionBasedQueryCost queryCost = new FactPartitionBasedQueryCost(100.0);
+ private int numLoop = 1000; //Number of loops to run to test driver allocation
+ private int errorBuffer = 5; //Error buffer in percentage (change to double for fractional buffers)
+
+
+ private class TestDriverAllocation {
+ double p1, p2, p3;
+ int total;
+ }
+
+ private static MockQueryContext createMockContext(String query, Configuration conf, LensConf lensConf,
+ Map<LensDriver, String> driverQueries) throws LensException {
+ MockQueryContext ctx = new MockQueryContext(query, lensConf, conf, driverQueries.keySet());
+ ctx.setDriverQueries(driverQueries);
+ ctx.estimateCostForDrivers();
+ return ctx;
+ }
+
+ private TestDriverAllocation driverLoop(MockQueryContext ctx, MockDriver d1, MockDriver d2, MockDriver d3,
+ MockDriver d4) {
+ int c1 = 0;
+ int c2 = 0;
+ int c3 = 0;
+
+ for (int i = 0; i < numLoop; i++) {
+ LensDriver selectedDriver = selector.select(ctx, conf);
+ Assert.assertNotEquals(d4, selectedDriver, "Improper driver allocation. Check WeightedQueryCostDriverSelector.");
+ if (d1.equals(selectedDriver)) {
+ c1++;
+ } else {
+ if (d2.equals(selectedDriver)) {
+ c2++;
+ } else {
+ if (d3.equals(selectedDriver)) {
+ c3++;
+ }
+ }
+ }
+ }
+
+ TestDriverAllocation allocation = new TestDriverAllocation();
+ allocation.total = c1 + c2 + c3;
+ allocation.p1 = c1 * 100.0 / (allocation.total);
+ allocation.p2 = c2 * 100.0 / (allocation.total);
+ allocation.p3 = c3 * 100.0 / (allocation.total);
+
+ return allocation;
+ }
+
+ private TestDriverAllocation testDriverSelector(double r1, double r2, double r3, double r4) throws LensException {
+
+ List<LensDriver> drivers = new ArrayList<LensDriver>();
+ Map<LensDriver, String> driverQueries = new HashMap<LensDriver, String>();
+
+ Configuration conf1 = new Configuration();
+ Configuration conf2 = new Configuration();
+ Configuration conf3 = new Configuration();
+ Configuration conf4 = new Configuration();
+
+ //Creating drivers and setting driver ratios
+ MockDriver d1 = new MockDriver();
+ d1.configure(conf1, null, null);
+ if (r1 > 0) {
+ conf1.setDouble(DRIVER_WEIGHT, r1);
+ }
+
+ MockDriver d2 = new MockDriver();
+ d2.configure(conf2, null, null);
+ if (r2 > 0) {
+ conf2.setDouble(DRIVER_WEIGHT, r2);
+ }
+
+ MockDriver d3 = new MockDriver();
+ d3.configure(conf3, null, null);
+ if (r3 > 0) {
+ conf3.setDouble(DRIVER_WEIGHT, r3);
+ }
+
+ MockDriver d4 = new MockDriver();
+ d4.configure(conf4, null, null);
+ if (r4 > 0) {
+ conf4.setDouble(DRIVER_WEIGHT, r4);
+ }
+
+ drivers.add(d1);
+ drivers.add(d2);
+ drivers.add(d3);
+ drivers.add(d4);
+
+ String query = "test query";
+ driverQueries.put(d1, query);
+ driverQueries.put(d2, query);
+ driverQueries.put(d3, query);
+ driverQueries.put(d4, query);
+
+ MockQueryContext ctx = createMockContext(query, conf, qconf, driverQueries);
+ ctx.setDriverCost(d4, queryCost); //Increasing driver 4's query cost
+
+ return driverLoop(ctx, d1, d2, d3, d4);
+ }
+
+ private void assertAllocation(String caseString, TestDriverAllocation allocation, double r1, double r2, double r3) {
+ if (allocation.total != numLoop) {
+ throw new AssertionError(caseString + ": Incomplete driver allocation. Check"
+ + " WeightedQueryCostDriverSelector.");
+ }
+
+ if (abs(allocation.p1 - r1) > errorBuffer) {
+ throw new AssertionError(caseString + ": Driver 1 not properly allocated. Difference by "
+ + abs(allocation.p1 - r1) + "." + " Check WeightedQueryCostDriverSelector");
+ }
+
+ if (abs(allocation.p2 - r2) > errorBuffer) {
+ throw new AssertionError(caseString + ": Driver 2 not properly allocated. Difference by "
+ + abs(allocation.p2 - r2) + "." + " Check WeightedQueryCostDriverSelector");
+ }
+
+ if (abs(allocation.p3 - r3) > errorBuffer) {
+ throw new AssertionError(caseString + ": Driver 3 not properly allocated. Difference by "
+ + abs(allocation.p3 - r3) + "." + " Check WeightedQueryCostDriverSelector");
+ }
+ }
+
+ //4 DRIVERS WITH THEIR WEIGHTS SET (3 are min cost)
+ @Test
+ public void testCustomWeights() throws LensException {
+ double r1 = 30;
+ double r2 = 20;
+ double r3 = 50;
+ double r4 = 100; //Insignificant driver weight due to increased driver cost
+
+ TestDriverAllocation allocation = testDriverSelector(r1, r2, r3, r4);
+
+ assertAllocation("TEST CustomWeights", allocation, r1, r2, r3);
+ }
+
+
+ //4 DRIVERS WITHOUT WEIGHTS SET. (3 are min cost)
+ @Test
+ public void testNoWeights() throws LensException {
+
+ TestDriverAllocation allocation = testDriverSelector(-1, -1, -1, -1);
+
+ assertAllocation("TEST NoWeights", allocation, 33.33, 33.33, 33.33);
+ }
+
+ //2 DRIVERS WITH DIFFERENT WEIGHTS
+ @Test
+ public void testDifferentWeights() throws LensException {
+
+ int r1 = 10;
+ int r2 = 90;
+
+ List<LensDriver> drivers = new ArrayList<LensDriver>();
+ Map<LensDriver, String> driverQueries = new HashMap<LensDriver, String>();
+
+ Configuration conf1 = new Configuration();
+ Configuration conf2 = new Configuration();
+
+ //Creating drivers and setting driver ratios
+ MockDriver d1 = new MockDriver();
+ conf1.setDouble(DRIVER_WEIGHT, r1);
+ d1.configure(conf1, null, null);
+
+ MockDriver d2 = new MockDriver();
+ conf2.setDouble(DRIVER_WEIGHT, r2);
+ d2.configure(conf2, null, null);
+
+ drivers.add(d1);
+ drivers.add(d2);
+ String query = "test query";
+ driverQueries.put(d1, query);
+ driverQueries.put(d2, query);
+
+ MockQueryContext ctx = createMockContext(query, conf, qconf, driverQueries);
+
+ ctx.setDriverCost(d2, queryCost);
+
+ LensDriver selected = selector.select(ctx, conf);
+
+ Assert.assertEquals(selected, d1, "TEST Different Weights: Improper driver allocation. Check "
+ + "WeightedQueryCostDriverSelector.");
+ }
+
+ //DEFAULT MIN COST SELECTOR BEHAVIOR
+ @Test
+ public void testDefaultMinCost() throws LensException {
+ List<LensDriver> drivers = new ArrayList<LensDriver>();
+ Map<LensDriver, String> driverQueries = new HashMap<LensDriver, String>();
+
+ MockDriver d1 = new MockDriver();
+ d1.configure(conf, null, null);
+ MockDriver d2 = new MockDriver();
+ d2.configure(conf, null, null);
+ MockFailDriver fd1 = new MockFailDriver();
+ fd1.configure(conf, null, null);
+ MockFailDriver fd2 = new MockFailDriver();
+ fd2.configure(conf, null, null);
+
+ String message = "TEST DefaultMinCost: Check WeightedQueryCostDriverSelector";
+
+ drivers.add(d1);
+ drivers.add(d2);
+ String query = "test query";
+ driverQueries.put(d1, query);
+
+ MockQueryContext ctx = createMockContext(query, conf, qconf, driverQueries);
+ LensDriver selected = selector.select(ctx, conf);
+
+ Assert.assertEquals(d1, selected, message);
+ driverQueries.put(d2, query);
+ driverQueries.remove(d1);
+ ctx = createMockContext(query, conf, qconf, driverQueries);
+
+ selected = selector.select(ctx, conf);
+ Assert.assertEquals(d2, selected, message);
+
+ drivers.add(fd1);
+ driverQueries.put(fd1, query);
+
+ ctx = createMockContext(query, conf, qconf, driverQueries);
+ selected = selector.select(ctx, conf);
+ Assert.assertEquals(d2, selected, message);
+
+ drivers.add(fd2);
+ driverQueries.put(fd2, query);
+ ctx = createMockContext(query, conf, qconf, driverQueries);
+
+ selected = selector.select(ctx, conf);
+ Assert.assertEquals(d2, selected, message);
+
+ drivers.clear();
+ driverQueries.clear();
+ drivers.add(d1);
+ drivers.add(fd1);
+ driverQueries.put(d1, query);
+ ctx = createMockContext(query, conf, qconf, driverQueries);
+ selected = selector.select(ctx, conf);
+ Assert.assertEquals(d1, selected, message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lens/blob/1774ced2/src/site/apt/admin/jdbcdriver-config.apt
----------------------------------------------------------------------
diff --git a/src/site/apt/admin/jdbcdriver-config.apt b/src/site/apt/admin/jdbcdriver-config.apt
index 8a2666f..8fd5295 100644
--- a/src/site/apt/admin/jdbcdriver-config.apt
+++ b/src/site/apt/admin/jdbcdriver-config.apt
@@ -78,7 +78,8 @@ Jdbc driver configuration
*--+--+---+--+
|27|lens.driver.jdbc.pool.max.statements|20|Maximum number of prepared statements to cache per connection|
*--+--+---+--+
-|28|lens.driver.jdbc.query.launching.constraint.factories|org.apache.lens.server.api.query.constraint.MaxConcurrentDriverQueriesConstraintFactory|Factories used to instantiate constraints enforced on queries by driver. A query will be launched only if all constraints pass. Every Factory should be an implementation of org.apache.lens.server.api.common.ConfigBasedObjectCreationFactory and create an implementation of org.apache.lens.server.api.query.constraint.QueryLaunchingConstraint.|
+|28|lens.driver.jdbc.query.launching.constraint.factories|org.apache.lens.server.api.query.constraint.MaxConcurrentDriverQueriesConstraintFactory,
+ org.apache.lens.driver.jdbc.MaxJDBCConnectionCheckConstraintFactory|Factories used to instantiate constraints enforced on queries by driver. A query will be launched only if all constraints pass. Every Factory should be an implementation of org.apache.lens.server.api.common.ConfigBasedObjectCreationFactory and create an implementation of org.apache.lens.server.api.query.constraint.QueryLaunchingConstraint.|
*--+--+---+--+
|29|lens.driver.jdbc.query.rewriter|org.apache.lens.driver.jdbc.ColumnarSQLRewriter|Rewriting the HQL to optimized sql queries|
*--+--+---+--+