Repository: lens
Updated Branches:
  refs/heads/master 5741aee71 -> 5a40ee60c


LENS-816 : Fix ThreadSafeEstimatedQueryCollection methods not to ignore driver 
arguments


Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/5a40ee60
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/5a40ee60
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/5a40ee60

Branch: refs/heads/master
Commit: 5a40ee60c152a5acb547aa69dc714f51c42777ff
Parents: 5741aee
Author: Rajat Khandelwal <[email protected]>
Authored: Thu Oct 15 05:53:25 2015 +0530
Committer: Amareshwari Sriramadasu <[email protected]>
Committed: Thu Oct 15 05:53:25 2015 +0530

----------------------------------------------------------------------
 .../ThreadSafeEstimatedQueryCollection.java     |  4 +-
 .../ThreadSafeEstimatedQueryCollectionTest.java | 81 ++++++++++++++++++++
 2 files changed, 83 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lens/blob/5a40ee60/lens-server/src/main/java/org/apache/lens/server/query/collect/ThreadSafeEstimatedQueryCollection.java
----------------------------------------------------------------------
diff --git 
a/lens-server/src/main/java/org/apache/lens/server/query/collect/ThreadSafeEstimatedQueryCollection.java
 
b/lens-server/src/main/java/org/apache/lens/server/query/collect/ThreadSafeEstimatedQueryCollection.java
index 5d24379..ca24a8b 100644
--- 
a/lens-server/src/main/java/org/apache/lens/server/query/collect/ThreadSafeEstimatedQueryCollection.java
+++ 
b/lens-server/src/main/java/org/apache/lens/server/query/collect/ThreadSafeEstimatedQueryCollection.java
@@ -41,12 +41,12 @@ public class ThreadSafeEstimatedQueryCollection implements 
EstimatedQueryCollect
 
   @Override
   public synchronized Set<QueryContext> getQueries(LensDriver driver) {
-    return this.estimatedQueries.getQueries();
+    return this.estimatedQueries.getQueries(driver);
   }
 
   @Override
   public synchronized int getQueriesCount(LensDriver driver) {
-    return this.estimatedQueries.getQueriesCount();
+    return this.estimatedQueries.getQueriesCount(driver);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/lens/blob/5a40ee60/lens-server/src/test/java/org/apache/lens/server/query/constraint/ThreadSafeEstimatedQueryCollectionTest.java
----------------------------------------------------------------------
diff --git 
a/lens-server/src/test/java/org/apache/lens/server/query/constraint/ThreadSafeEstimatedQueryCollectionTest.java
 
b/lens-server/src/test/java/org/apache/lens/server/query/constraint/ThreadSafeEstimatedQueryCollectionTest.java
new file mode 100644
index 0000000..9138f8e
--- /dev/null
+++ 
b/lens-server/src/test/java/org/apache/lens/server/query/constraint/ThreadSafeEstimatedQueryCollectionTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.query.constraint;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import static org.testng.Assert.assertEquals;
+
+import org.apache.lens.server.api.driver.LensDriver;
+import org.apache.lens.server.api.query.QueryContext;
+import 
org.apache.lens.server.api.query.constraint.MaxConcurrentDriverQueriesConstraint;
+import org.apache.lens.server.api.query.constraint.QueryLaunchingConstraint;
+import org.apache.lens.server.api.query.cost.FactPartitionBasedQueryCost;
+import org.apache.lens.server.api.query.cost.QueryCost;
+import org.apache.lens.server.query.collect.DefaultEstimatedQueryCollection;
+import org.apache.lens.server.query.collect.DefaultQueryCollection;
+import org.apache.lens.server.query.collect.ThreadSafeEstimatedQueryCollection;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class ThreadSafeEstimatedQueryCollectionTest {
+  public static final QueryCost COST = new FactPartitionBasedQueryCost(10);
+
+  @DataProvider
+  public Object[][] dpTestAllowsLaunchOfQuery() {
+    return new Object[][]{{2, true}, {3, false}, {11, false}};
+  }
+
+  @Test(dataProvider = "dpTestAllowsLaunchOfQuery")
+  public void testAllowsLaunchOfQuery(final int currentDriverLaunchedQueries, 
final boolean expectedCanLaunch) {
+
+    int maxConcurrentQueries = 3;
+
+    LensDriver mockDriver = mock(LensDriver.class);
+    LensDriver mockDriver2 = mock(LensDriver.class);
+
+    QueryLaunchingConstraint constraint = new 
MaxConcurrentDriverQueriesConstraint(maxConcurrentQueries);
+    ThreadSafeEstimatedQueryCollection col = new 
ThreadSafeEstimatedQueryCollection(new
+      DefaultEstimatedQueryCollection(new DefaultQueryCollection()));
+
+    for (int i = 0; i < currentDriverLaunchedQueries; i++) {
+      QueryContext query = mock(QueryContext.class);
+      when(query.getSelectedDriver()).thenReturn(mockDriver);
+      when(query.getSelectedDriverQueryCost()).thenReturn(COST);
+      col.add(query);
+    }
+    for (int i = 0; i < 2; i++) {
+      QueryContext query = mock(QueryContext.class);
+      when(query.getSelectedDriver()).thenReturn(mockDriver2);
+      when(query.getSelectedDriverQueryCost()).thenReturn(COST);
+      col.add(query);
+    }
+
+    // new candidate query
+    QueryContext mockCandidateQuery = mock(QueryContext.class);
+    when(mockCandidateQuery.getSelectedDriver()).thenReturn(mockDriver);
+    when(mockCandidateQuery.getSelectedDriverQueryCost()).thenReturn(COST);
+    boolean actualCanLaunch = constraint.allowsLaunchOf(mockCandidateQuery, 
col);
+
+    assertEquals(actualCanLaunch, expectedCanLaunch);
+  }
+}

Reply via email to