public QueryExecutor(XMLConfigParser parser, PhoenixUtil util, WorkloadExecutor workloadExecutor) { this(parser, util, workloadExecutor, parser.getDataModels(), null, false, true); }
public Scenario getScenarioByName(String name) throws Exception { for (Scenario scenario : getScenarios()) { if (scenario.getName().equals(name)) { return scenario; } } return null; }
public synchronized List<Scenario> getScenarios() throws Exception { if (scenarios != null) { return scenarios; } scenarios = Collections.synchronizedList(new ArrayList<Scenario>()); for (Path path : getPaths(getFilePattern())) { try { List<Scenario> scenarioList = XMLConfigParser.readDataModel(path).getScenarios(); for (Scenario scenario : scenarioList) { scenarios.add(scenario); } } catch (JAXBException e) { e.printStackTrace(); } } return scenarios; }
private void init(String pattern) throws Exception { if (dataModels != null) { return; } this.filePattern = pattern; this.dataModels = new ArrayList<>(); this.resourceList = new ResourceList(PherfConstants.RESOURCE_SCENARIO); this.paths = getResources(this.filePattern); if (this.paths.isEmpty()) { throw new FileLoaderException( "Could not load the resource files using the pattern: " + pattern); } for (Path path : this.paths) { System.out.println("Adding model for path:" + path.toString()); this.dataModels.add(XMLConfigParser.readDataModel(path)); } }
XMLConfigParser parser = new XMLConfigParser(scenarioFile); .add(new QueryExecutor(parser, phoenixUtil, workloadExecutor, parser.getDataModels(), queryHint, isFunctional, writeRuntimeResults));
@Test public void testValueListRule() throws Exception { List<String> expectedValues = new ArrayList(); expectedValues.add("aAAyYhnNbBs9kWk"); expectedValues.add("bBByYhnNbBs9kWu"); expectedValues.add("cCCyYhnNbBs9kWr"); XMLConfigParser parser = new XMLConfigParser(matcherScenario); WriteWorkload loader = new WriteWorkload(parser); RulesApplier rulesApplier = loader.getRulesApplier(); Scenario scenario = parser.getScenarios().get(0); Column simPhxCol = new Column(); simPhxCol.setName("PARENT_ID"); simPhxCol.setType(DataTypeMapping.CHAR); // Run this 10 times gives a reasonable chance that all the values will appear at least once for (int i = 0; i < 10; i++) { DataValue value = rulesApplier.getDataForRule(scenario, simPhxCol); assertTrue("Got a value not in the list for the rule. :" + value.getValue(), expectedValues.contains(value.getValue())); } }
@Test public void testPrefixSequence() throws Exception { List<String> expectedValues = new ArrayList(); expectedValues.add("0F90000000000X0"); expectedValues.add("0F90000000000X1"); expectedValues.add("0F90000000000X2"); expectedValues.add("0F90000000000X3"); expectedValues.add("0F90000000000X4"); expectedValues.add("0F90000000000X5"); expectedValues.add("0F90000000000X6"); expectedValues.add("0F90000000000X7"); expectedValues.add("0F90000000000X8"); expectedValues.add("0F90000000000X9"); XMLConfigParser parser = new XMLConfigParser(matcherScenario); WriteWorkload loader = new WriteWorkload(parser); RulesApplier rulesApplier = loader.getRulesApplier(); // Run this 15 times gives a reasonable chance that all the values will appear at least once for (int i = 0; i < 15; i++) { DataValue value = rulesApplier.getDataValue(rulesApplier.getRule("NEWVAL_STRING")); assertTrue("Got a value not in the list for the rule. :" + value.getValue(), expectedValues.contains(value.getValue())); } }
private DataModel getDataModel() throws Exception { Path resourcePath = Paths.get(getResourceUrl().toURI()); return XMLConfigParser.readDataModel(resourcePath); }
DataModel dataModel = parser.getDataModelByName("test_scenario"); List<DataModel> dataModels = new ArrayList<>(); dataModels.add(dataModel); new QueryExecutor(parser, util, executor, dataModels, null, false); executor.add(qe); Scenario scenario = parser.getScenarioByName("testScenarioRW");
@Test public void testPreAndPostDataLoadDdls() throws Exception { Scenario scenario = parser.getScenarioByName("testPreAndPostDdls"); WorkloadExecutor executor = new WorkloadExecutor(); executor.add(new WriteWorkload(util, parser, scenario, GeneratePhoenixStats.NO)); try { executor.get(); executor.shutdown(); } catch (Exception e) { fail("Failed to load data. An exception was thrown: " + e.getMessage()); } assertExpectedNumberOfRecordsWritten(scenario); }
public synchronized Collection<Path> getPaths(String strPattern) throws Exception { if (paths != null) { return paths; } paths = getResources(strPattern); return paths; }
public XMLConfigParser(String pattern) throws Exception { init(pattern); }
@Test public void testSequentialDataSequence() throws Exception { XMLConfigParser parser = new XMLConfigParser(matcherScenario); DataModel model = parser.getDataModels().get(0); WriteWorkload loader = new WriteWorkload(parser); RulesApplier rulesApplier = loader.getRulesApplier(); Column targetColumn = null; for (Column column : model.getDataMappingColumns()) { DataSequence sequence = column.getDataSequence(); if (sequence == DataSequence.SEQUENTIAL) { targetColumn = column; break; } } assertNotNull("Could not find a DataSequence.SEQENTIAL rule.", targetColumn); assertMultiThreadedIncrementValue(targetColumn, rulesApplier); }
@Test public void testScenarioLevelRuleOverride() throws Exception { XMLConfigParser parser = new XMLConfigParser(matcherScenario); WriteWorkload loader = new WriteWorkload(parser); RulesApplier rulesApplier = loader.getRulesApplier(); Scenario scenario = parser.getScenarios().get(0); // Test scenario level overridden rule Column simPhxCol = new Column(); simPhxCol.setName("FIELD"); simPhxCol.setType(DataTypeMapping.VARCHAR); DataValue value = rulesApplier.getDataForRule(scenario, simPhxCol); assertEquals("Override rule should contain field length of 5", 5, value.getValue().length()); }
@Test public void testVarBinary() throws Exception { List<String> expectedValues = new ArrayList(); for (int i=0; i<10; i++) { expectedValues.add("VBOxx00" + i); } XMLConfigParser parser = new XMLConfigParser(matcherScenario); WriteWorkload loader = new WriteWorkload(parser); RulesApplier rulesApplier = loader.getRulesApplier(); for (int i = 0; i < 5; i++) { Column c = rulesApplier.getRule("VAR_BIN"); DataValue value = rulesApplier.getDataValue(c); System.out.println(value.getValue()); assertTrue("Got a value not in the list for the rule. :" + value.getValue(), expectedValues.contains(value.getValue())); } }
@Test public void testDTDInScenario() throws Exception { URL scenarioUrl = XMLConfigParserTest.class.getResource("/scenario/malicious_scenario_with_dtd.xml"); assertNotNull(scenarioUrl); Path p = Paths.get(scenarioUrl.toURI()); try { XMLConfigParser.readDataModel(p); fail("The scenario should have failed to parse because it contains a DTD"); } catch (UnmarshalException e) { // If we don't parse the DTD, the variable 'name' won't be defined in the XML LOG.warn("Caught expected exception", e); Throwable cause = e.getLinkedException(); assertTrue("Cause was a " + cause.getClass(), cause instanceof XMLStreamException); } } }
@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); }
@Test public void testNullChance() throws Exception { XMLConfigParser parser = new XMLConfigParser(matcherScenario); DataModel model = parser.getDataModels().get(0); WriteWorkload loader = new WriteWorkload(parser); RulesApplier rulesApplier = loader.getRulesApplier(); int sampleSize = 100; List<String> values = new ArrayList<>(sampleSize); for (Column dataMapping : model.getDataMappingColumns()) { DataValue value = rulesApplier.getDataValue(dataMapping); if (dataMapping.getNullChance() == 0) { // 0 chance of getting null means we should never have an empty string returned assertFalse("", value.getValue().equals("")); } else if (dataMapping.getNullChance() == 100) { // 100 chance of getting null means we should always have an empty string returned assertTrue("", value.getValue().equals("")); } else if ((dataMapping.getNullChance() == 90)) { // You can't really test for this, but you can eyeball it on debugging. for (int i = 0; i < sampleSize; i++) { DataValue tVal = rulesApplier.getDataValue(dataMapping); values.add(tVal.getValue()); } Collections.sort(values); } } }
@Test public void testTimestampRule() throws Exception { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat df = new SimpleDateFormat("yyyy"); XMLConfigParser parser = new XMLConfigParser(matcherScenario); WriteWorkload loader = new WriteWorkload(parser); RulesApplier rulesApplier = loader.getRulesApplier(); Scenario scenario = parser.getScenarios().get(0); Column simPhxCol = new Column(); simPhxCol.setName("TS_DATE"); simPhxCol.setType(DataTypeMapping.TIMESTAMP); // Run this 10 times gives a reasonable chance that all the values will appear at least once for (int i = 0; i < 10; i++) { DataValue value = rulesApplier.getDataForRule(scenario, simPhxCol); Date dt = simpleDateFormat.parse(value.getValue()); int year = Integer.parseInt(df.format(dt)); assertTrue("Got unexpected TS value" + value.getValue(), year >= 2020 && year <= 2025); } }
@BeforeClass public static void setUp() throws Exception { PherfConstants constants = PherfConstants.create(); properties = constants.getProperties(PherfConstants.PHERF_PROPERTIES, false); String dir = properties.getProperty("pherf.default.results.dir"); resultUtil.ensureBaseDirExists(dir); PhoenixUtil.setZookeeper("localhost"); reader = new SchemaReader(util, matcherSchema); parser = new XMLConfigParser(matcherScenario); }