Repository: lens
Updated Branches:
  refs/heads/master 0dc5494d5 -> 935647ca0


LENS-964: Fixed Test cases for TestLensQueryCommands


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

Branch: refs/heads/master
Commit: 935647ca0cfdee1f300e0054d354c6c8f6469060
Parents: 0dc5494
Author: Puneet Gupta <[email protected]>
Authored: Wed Mar 2 15:59:23 2016 +0530
Committer: Puneet <[email protected]>
Committed: Wed Mar 2 15:59:23 2016 +0530

----------------------------------------------------------------------
 .../lens/cli/commands/LensQueryCommands.java    |  9 ++-
 .../lens/cli/TestLensDimensionCommands.java     |  8 ++-
 .../apache/lens/cli/TestLensQueryCommands.java  | 69 +++++++++++++-------
 3 files changed, 57 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lens/blob/935647ca/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
----------------------------------------------------------------------
diff --git 
a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java 
b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
index 007bf34..2c7b17f 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensQueryCommands.java
@@ -335,10 +335,13 @@ public class LensQueryCommands extends BaseLensCommand {
               + formatResultSet(results);
           }
         }
-      } else if (async) {
-        return formatResultSet(getClient().getAsyncResults(queryHandle));
       } else {
-        return formatResultSet(getClient().getSyncResults(queryHandle));
+        if (async) {
+          results = getClient().getAsyncResults(queryHandle);
+        } else {
+          results = getClient().getSyncResults(queryHandle);
+        }
+        return results.getResultSet() == null ? "Resultset not available for 
the query" : formatResultSet(results);
       }
     } catch (Throwable t) {
       return t.getMessage();

http://git-wip-us.apache.org/repos/asf/lens/blob/935647ca/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java
----------------------------------------------------------------------
diff --git 
a/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java 
b/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java
index 45555f4..955d4c7 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensDimensionCommands.java
@@ -87,13 +87,17 @@ public class TestLensDimensionCommands extends 
LensCliApplicationTest {
     testFields(getCommand());
     testJoinChains(getCommand());
     testUpdateCommand(new File(dimensionSpec.toURI()), getCommand());
-    getCommand().dropDimension("test_dim");
-    getCommand().dropDimension("test_detail");
+    dropDimensions();
     dimensionList = getCommand().showDimensions();
     Assert.assertFalse(dimensionList.contains("test_dim"));
     Assert.assertFalse(dimensionList.contains("test_detail"));
   }
 
+  public static void dropDimensions() {
+    getCommand().dropDimension("test_dim");
+    getCommand().dropDimension("test_detail");
+  }
+
   private void testJoinChains(LensDimensionCommands command) {
     XJoinChains chains = new XJoinChains();
     XJoinChain chain1 = new XJoinChain();

http://git-wip-us.apache.org/repos/asf/lens/blob/935647ca/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java
----------------------------------------------------------------------
diff --git 
a/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java 
b/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java
index 2de3cc1..97e5512 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java
@@ -34,6 +34,7 @@ import org.apache.lens.api.metastore.*;
 import org.apache.lens.api.query.QueryHandle;
 import org.apache.lens.api.query.QueryStatus;
 import org.apache.lens.cli.commands.LensCubeCommands;
+import org.apache.lens.cli.commands.LensDimensionTableCommands;
 import org.apache.lens.cli.commands.LensQueryCommands;
 import org.apache.lens.client.LensClient;
 import org.apache.lens.driver.hive.TestHiveDriver;
@@ -41,9 +42,7 @@ import org.apache.lens.driver.hive.TestHiveDriver;
 import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.fs.Path;
 
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
+import org.testng.annotations.*;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -66,7 +65,7 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
 
   @BeforeClass
   public void createResultsDir() {
-    resDir = new File("target/results");
+    resDir = new File("target/lens-results");
     assertTrue(resDir.exists() || resDir.mkdirs());
   }
 
@@ -87,7 +86,7 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
     if (withMetrics) {
       client.setConnectionParam("lens.query.enable.metrics.per.query", "true");
     }
-    setup(client);
+
     LensQueryCommands qCom = new LensQueryCommands();
     qCom.setClient(client);
     return qCom;
@@ -138,15 +137,18 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
     }
     String status = qCom.getStatus(handle);
     log.debug("Prepared Query Status is  " + status);
-    assertTrue(status.contains("Status : SUCCESSFUL"));
+    assertTrue(status.contains("Status: SUCCESSFUL"));
 
+    //Fetch results
     result = qCom.getQueryResults(handle, null, true);
     log.debug("Prepared Query Result is  " + result);
     assertTrue(result.contains("1\tfirst"));
-    // Fetch again.
+    //Wait for query to purge. Purger runs every second
+    Thread.sleep(3000);
+    //Fetch again. Should not get resultset
     result = qCom.getQueryResults(handle, null, true);
     log.debug("Prepared Query Result is  " + result);
-    assertTrue(result.contains("1\tfirst"));
+    assertTrue(result.contains("Resultset not available for the query"), 
"Query is not purged yet " + handle);
 
     result = qCom.destroyPreparedQuery(qh);
 
@@ -243,7 +245,7 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
     while (!queryStatus.finished()) {
       if (queryStatus.launched()) {
         String details = qCom.getDetails(null);
-        assertTrue(details.contains("driverQuery"));
+        assertTrue(details.contains("Driver Query:"));
       }
       Thread.sleep(1000);
       queryStatus = qCom.getClient().getQueryStatus(qh);
@@ -252,18 +254,13 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
     // Check that query name searching is 'ilike'
     String result2 = qCom.getAllQueries("", "query", "all", "", -1, 
Long.MAX_VALUE);
     assertTrue(result2.contains(qh), result2);
-
-    assertTrue(qCom.getStatus(qh).contains("Status : SUCCESSFUL"));
+    assertTrue(qCom.getStatus(qh).contains("Status: SUCCESSFUL"));
     String details = qCom.getDetails(qh);
-    assertTrue(details.contains("driverQuery"));
+    assertTrue(details.contains("Driver Query:"));
 
     result = qCom.getQueryResults(null, null, true);
     assertTrue(result.contains("1\tfirst"));
 
-    downloadResult(qCom, qh, result);
-    // re-download should also succeed
-    downloadResult(qCom, qh, result);
-
     // Kill query is not tested as there is no deterministic way of killing a 
query
 
     result = qCom.getAllQueries("SUCCESSFUL", "", "all", "", -1, 
Long.MAX_VALUE);
@@ -315,11 +312,6 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
     System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
   }
 
-  private void downloadResult(LensQueryCommands qCom, String qh, String 
expected) throws IOException {
-    assertTrue(qCom.getQueryResults(qh, resDir, true).contains("Saved"));
-    assertEquals(readFile(resDir.getAbsolutePath() + File.separator + qh + 
".csv").trim(), expected.trim());
-  }
-
   private String readFile(String path) throws FileNotFoundException {
     return new Scanner(new File(path)).useDelimiter("\\Z").next();
   }
@@ -330,7 +322,9 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
    * @param client the new up
    * @throws Exception the exception
    */
-  public void setup(LensClient client) throws Exception {
+  @BeforeClass
+  public void setup() throws Exception {
+    LensClient client = new LensClient();
     LensCubeCommands command = new LensCubeCommands();
     command.setClient(client);
 
@@ -356,6 +350,21 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
     assertEquals(result.getStatus(), APIResult.Status.SUCCEEDED);
   }
 
+  @AfterClass
+  public void tearDown() {
+    LensClient client = new LensClient();
+
+    LensCubeCommands cubeCmd = new LensCubeCommands();
+    cubeCmd.setClient(client);
+    cubeCmd.dropCube("sample_cube");
+
+    TestLensDimensionCommands.dropDimensions();
+
+    LensDimensionTableCommands dimTableCmd = new LensDimensionTableCommands();
+    dimTableCmd.setClient(client);
+    dimTableCmd.dropDimensionTable("dim_table", true);
+  }
+
   /**
    * Test show persistent result set.
    *
@@ -365,7 +374,7 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
   @Test(dataProvider = "queryCommands")
   public void showPersistentResultSet(LensQueryCommands qCom) throws Exception 
{
     System.out.println("@@PERSISTENT_RESULT_TEST-------------");
-    
qCom.getClient().setConnectionParam("lens.query.enable.persistent.resultset.indriver",
 "true");
+    
qCom.getClient().setConnectionParam("lens.query.enable.persistent.resultset", 
"true");
     String query = "cube select id,name from test_dim";
     try {
       String result = qCom.executeQuery(query, false, "testQuery3");
@@ -376,10 +385,22 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
       log.error("Exception not expected while getting resultset.", exc);
       fail("Exception not expected: " + exc.getMessage());
     }
+    //Downlaod once
+    downloadResult(qCom, 
qCom.getClient().getStatement().getQueryHandleString(), "testQuery3", 
"\"1\",\"first\"");
+    //Download Again
+    downloadResult(qCom, 
qCom.getClient().getStatement().getQueryHandleString(), "testQuery3",  
"\"1\",\"first\"");
     System.out.println("@@END_PERSISTENT_RESULT_TEST-------------");
     
qCom.getClient().setConnectionParam("lens.query.enable.persistent.resultset.indriver",
 "false");
   }
 
+  private void downloadResult(LensQueryCommands qCom, String qHandle, String 
qName, String expected)
+    throws IOException{
+    assertTrue(qCom.getQueryResults(qHandle, resDir, true).contains("Saved 
to"));
+    assertEquals(readFile(resDir.getAbsolutePath() + File.separator + qName + 
"-" + qHandle + ".csv").trim(),
+        expected.trim());
+  }
+
+
   /**
    * Test execute sync results.
    *
@@ -407,7 +428,7 @@ public class TestLensQueryCommands extends 
LensCliApplicationTest {
     while (!qCom.getClient().getQueryStatus(qh).finished()) {
       Thread.sleep(5000);
     }
-    assertTrue(qCom.getStatus(qh).contains("Status : SUCCESSFUL"));
+    assertTrue(qCom.getStatus(qh).contains("Status: SUCCESSFUL"));
 
     String result = qCom.getQueryResults(qh, null, true);
     System.out.println("@@ RESULT " + result);

Reply via email to