PHOENIX-2227 Added the ability to Pherf to define a DDL statement that will be 
executed before a scenario is run to support dynamically creating multi-tenant 
views we are going to write and read from


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

Branch: refs/heads/4.5-HBase-0.98
Commit: b715e5d9c41c342d01f1448ea6f31b99690d75db
Parents: a7621e5
Author: Jan <jferna...@salesforce.com>
Authored: Thu Sep 3 17:48:18 2015 -0700
Committer: Cody Marcel <cmar...@cmarcel-wsl1.internal.salesforce.com>
Committed: Thu Sep 10 13:15:50 2015 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/pherf/DataIngestIT.java  | 25 ++++++++++++++++----
 .../phoenix/pherf/configuration/Scenario.java   | 13 ++++++++++
 .../apache/phoenix/pherf/util/PhoenixUtil.java  | 21 ++++++++++++++++
 .../phoenix/pherf/workload/WriteWorkload.java   |  5 +++-
 .../test/resources/scenario/test_scenario.xml   |  6 +++++
 5 files changed, 65 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b715e5d9/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java 
b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java
index 297f882..4fb5ccd 100644
--- a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java
+++ b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java
@@ -18,10 +18,6 @@
 
 package org.apache.phoenix.pherf;
 
-import com.jcabi.jdbc.JdbcSession;
-import com.jcabi.jdbc.Outcome;
-
-import org.apache.phoenix.pherf.PherfConstants.GeneratePhoenixStats;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -35,6 +31,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.phoenix.pherf.PherfConstants.GeneratePhoenixStats;
 import org.apache.phoenix.pherf.configuration.Column;
 import org.apache.phoenix.pherf.configuration.DataModel;
 import org.apache.phoenix.pherf.configuration.DataTypeMapping;
@@ -177,6 +174,26 @@ public class DataIngestIT extends ResultBaseTestIT {
         assertExpectedNumberOfRecordsWritten(scenario);
     }
 
+    
+    @Test
+    public void testMultiTenantScenarioRunBeforeWriteWorkload() throws 
Exception {
+        // Arrange
+        Scenario scenario = parser.getScenarioByName("testMTDdlWriteScenario");
+        WorkloadExecutor executor = new WorkloadExecutor();
+        executor.add(new WriteWorkload(util, parser, scenario, 
GeneratePhoenixStats.NO));
+        
+        // Act
+        try {
+            // Wait for data to load up.
+            executor.get();
+            executor.shutdown();
+        } catch (Exception e) {
+            fail("Failed to load data. An exception was thrown: " + 
e.getMessage());
+        }
+
+        assertExpectedNumberOfRecordsWritten(scenario);
+    }
+    
     private void assertExpectedNumberOfRecordsWritten(Scenario scenario) 
throws Exception,
             SQLException {
         Connection connection = util.getConnection(scenario.getTenantId());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b715e5d9/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
----------------------------------------------------------------------
diff --git 
a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
 
b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
index 6c949d8..200fdc5 100644
--- 
a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
+++ 
b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/configuration/Scenario.java
@@ -39,6 +39,7 @@ public class Scenario {
     private WriteParams writeParams;
     private String name;
     private String tenantId;
+    private String ddl;
 
     public Scenario() {
         writeParams = new WriteParams();
@@ -178,6 +179,18 @@ public class Scenario {
         this.tenantId = tenantId;
     }
 
+    /**
+     * Scenario level DDL that is executed before running the scenario.
+     */
+    @XmlAttribute
+    public String getDdl() {
+        return ddl;
+    }
+    
+    public void setDdl(String ddl) {
+        this.ddl = ddl;
+    }
+    
     public WriteParams getWriteParams() {
         return writeParams;
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b715e5d9/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java
----------------------------------------------------------------------
diff --git 
a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java 
b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java
index 19b6bd2..db967fc 100644
--- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java
+++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/PhoenixUtil.java
@@ -246,6 +246,27 @@ public class PhoenixUtil {
             }
         }
     }
+    
+    /**
+     * Executes any ddl defined at the scenario level. This is executed before 
we commence
+     * the data load.
+     * 
+     * @throws Exception
+     */
+    public void executeScenarioDdl(Scenario scenario) throws Exception {
+        if (null != scenario.getDdl()) {
+            Connection conn = null;
+            try {
+                logger.info("\nExecuting DDL:" + scenario.getDdl() + " on 
tenantId:"
+                        + scenario.getTenantId());
+                executeStatement(scenario.getDdl(), conn = 
getConnection(scenario.getTenantId()));
+            } finally {
+                if (null != conn) {
+                    conn.close();
+                }
+            }
+        }
+    }
 
     public static String getZookeeper() {
                return zookeeper;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b715e5d9/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
----------------------------------------------------------------------
diff --git 
a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
 
b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
index d0b99af..6985abd 100644
--- 
a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
+++ 
b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WriteWorkload.java
@@ -163,7 +163,10 @@ public class WriteWorkload implements Workload {
             DataLoadThreadTime dataLoadThreadTime, Scenario scenario) throws 
Exception {
         logger.info("\nLoading " + scenario.getRowCount() + " rows for " + 
scenario.getTableName());
         long start = System.currentTimeMillis();
-
+        
+        // Execute any Scenario DDL before running workload
+        pUtil.executeScenarioDdl(scenario);
+        
         List<Future> writeBatches = getBatches(dataLoadThreadTime, scenario);
 
         waitForBatches(dataLoadTimeSummary, scenario, start, writeBatches);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b715e5d9/phoenix-pherf/src/test/resources/scenario/test_scenario.xml
----------------------------------------------------------------------
diff --git a/phoenix-pherf/src/test/resources/scenario/test_scenario.xml 
b/phoenix-pherf/src/test/resources/scenario/test_scenario.xml
index b5fe564..735e690 100644
--- a/phoenix-pherf/src/test/resources/scenario/test_scenario.xml
+++ b/phoenix-pherf/src/test/resources/scenario/test_scenario.xml
@@ -223,5 +223,11 @@
         <!-- Test writing to a Multi-tenant View -->
         <scenario tableName="PHERF.TEST_VIEW" tenantId="abcdefghijklmno" 
rowCount="100" name="testMTWriteScenario">
         </scenario>
+        <!--  Test scenario DDL -->
+        <scenario tableName="PHERF.TEST_MT_VIEW" tenantId="abcdefghijklmno" 
+                    ddl="CREATE VIEW IF NOT EXISTS PHERF.TEST_MT_VIEW (field1 
VARCHAR) AS SELECT * FROM PHERF.TEST_MULTI_TENANT_TABLE" 
+                    rowCount="100" name="testMTDdlWriteScenario">
+        </scenario>
+        
     </scenarios>
 </datamodel>
\ No newline at end of file

Reply via email to