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/a3f6f268 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a3f6f268 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a3f6f268 Branch: refs/heads/4.x-HBase-1.0 Commit: a3f6f268072b45a9e112ed072dd20a8aad393030 Parents: 9d587cd Author: Jan <[email protected]> Authored: Thu Sep 3 17:48:18 2015 -0700 Committer: Cody Marcel <[email protected]> Committed: Fri Sep 11 11:05:13 2015 -0700 ---------------------------------------------------------------------- .../org/apache/phoenix/pherf/DataIngestIT.java | 31 ++++++++++++++++---- .../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, 69 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/a3f6f268/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 4f527fc..33f8a53 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; @@ -34,6 +30,9 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.List; import java.util.Map; + +import com.jcabi.jdbc.JdbcSession; +import com.jcabi.jdbc.Outcome; import org.apache.phoenix.pherf.configuration.Column; import org.apache.phoenix.pherf.configuration.DataModel; import org.apache.phoenix.pherf.configuration.DataTypeMapping; @@ -70,7 +69,7 @@ public class DataIngestIT extends ResultBaseTestIT { scenario.getTableNameWithoutSchemaName(), util.getConnection()); assertTrue("Could not get phoenix columns.", columnListFromPhoenix.size() > 0); - WriteWorkload loader = new WriteWorkload(util, parser, scenario, GeneratePhoenixStats.NO); + WriteWorkload loader = new WriteWorkload(util, parser, scenario, PherfConstants.GeneratePhoenixStats.NO); WorkloadExecutor executor = new WorkloadExecutor(); executor.add(loader); executor.get(); @@ -158,7 +157,7 @@ public class DataIngestIT extends ResultBaseTestIT { // Arrange Scenario scenario = parser.getScenarioByName("testMTWriteScenario"); WorkloadExecutor executor = new WorkloadExecutor(); - executor.add(new WriteWorkload(util, parser, scenario, GeneratePhoenixStats.NO)); + executor.add(new WriteWorkload(util, parser, scenario, PherfConstants.GeneratePhoenixStats.NO)); // Act try { @@ -174,6 +173,26 @@ public class DataIngestIT extends ResultBaseTestIT { } + + @Test + public void testMultiTenantScenarioRunBeforeWriteWorkload() throws Exception { + // Arrange + Scenario scenario = parser.getScenarioByName("testMTDdlWriteScenario"); + WorkloadExecutor executor = new WorkloadExecutor(); + executor.add(new WriteWorkload(util, parser, scenario, PherfConstants.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/a3f6f268/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/a3f6f268/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 fad06a1..57858a3 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 @@ -243,6 +243,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/a3f6f268/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 ff110ee..d4e84b8 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 @@ -164,7 +164,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/a3f6f268/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
