Search in sources :

Example 1 with DataValue

use of org.apache.phoenix.pherf.rules.DataValue in project phoenix by apache.

the class RuleGeneratorTest method testDateGenerator.

@Test
public void testDateGenerator() throws Exception {
    XMLConfigParser parser = new XMLConfigParser(matcherScenario);
    DataModel model = parser.getDataModels().get(0);
    WriteWorkload loader = new WriteWorkload(parser);
    RulesApplier rulesApplier = loader.getRulesApplier();
    for (Column dataMapping : model.getDataMappingColumns()) {
        if ((dataMapping.getType() == DataTypeMapping.DATE) && (dataMapping.getName().equals("CREATED_DATE"))) {
            // Test directly through generator method and that it converts to Phoenix type
            assertRandomDateValue(dataMapping, rulesApplier);
            // Do this 20 times and we should hit each possibility at least once.
            for (int i = 0; i < 20; i++) {
                DataValue value = rulesApplier.getDataValue(dataMapping);
                assertNotNull("Could not retrieve DataValue for random DATE.", value);
                assertNotNull("Could not retrieve a value in DataValue for random DATE.", value.getValue());
                if (value.getMinValue() != null) {
                    // Check that dates are between min/max
                    assertDateBetween(value);
                }
            }
        }
    }
}
Also used : RulesApplier(org.apache.phoenix.pherf.rules.RulesApplier) Column(org.apache.phoenix.pherf.configuration.Column) DataValue(org.apache.phoenix.pherf.rules.DataValue) DataModel(org.apache.phoenix.pherf.configuration.DataModel) WriteWorkload(org.apache.phoenix.pherf.workload.WriteWorkload) XMLConfigParser(org.apache.phoenix.pherf.configuration.XMLConfigParser) Test(org.junit.Test)

Example 2 with DataValue

use of org.apache.phoenix.pherf.rules.DataValue in project phoenix by apache.

the class RuleGeneratorTest method testNullChance.

@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);
        }
    }
}
Also used : RulesApplier(org.apache.phoenix.pherf.rules.RulesApplier) Column(org.apache.phoenix.pherf.configuration.Column) DataValue(org.apache.phoenix.pherf.rules.DataValue) DataModel(org.apache.phoenix.pherf.configuration.DataModel) WriteWorkload(org.apache.phoenix.pherf.workload.WriteWorkload) XMLConfigParser(org.apache.phoenix.pherf.configuration.XMLConfigParser) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with DataValue

use of org.apache.phoenix.pherf.rules.DataValue in project phoenix by apache.

the class RuleGeneratorTest method testCurrentDateGenerator.

//Test to check the current date is generated correctly between the timestamps at column level and datavalue level
@Test
public void testCurrentDateGenerator() throws Exception {
    XMLConfigParser parser = new XMLConfigParser(matcherScenario);
    DataModel model = parser.getDataModels().get(0);
    WriteWorkload loader = new WriteWorkload(parser);
    RulesApplier rulesApplier = loader.getRulesApplier();
    // Time before generating the date
    String timeStamp1 = rulesApplier.getCurrentDate();
    //sleep for few mili-sec
    sleep(2);
    for (Column dataMapping : model.getDataMappingColumns()) {
        if ((dataMapping.getType() == DataTypeMapping.DATE) && (dataMapping.getUseCurrentDate() == true)) {
            // Generate the date using rules
            DataValue value = rulesApplier.getDataValue(dataMapping);
            assertNotNull("Could not retrieve DataValue for random DATE.", value);
            assertNotNull("Could not retrieve a value in DataValue for random DATE.", value.getValue());
            sleep(2);
            // Time after generating the date
            String timeStamp2 = rulesApplier.getCurrentDate();
            // Check that dates are between timestamp1 & timestamp2
            value.setMinValue(timeStamp1);
            value.setMaxValue(timeStamp2);
            assertDateBetween(value);
        }
        // Check at list level
        if ((dataMapping.getType() == DataTypeMapping.DATE) && (dataMapping.getName().equals("PRESENT_DATE"))) {
            // timestamps
            for (int i = 0; i < 1; i++) {
                DataValue value = rulesApplier.getDataValue(dataMapping);
                assertNotNull("Could not retrieve DataValue for random DATE.", value);
                assertNotNull("Could not retrieve a value in DataValue for random DATE.", value.getValue());
                sleep(2);
                // Time after generating the date
                String timeStamp2 = rulesApplier.getCurrentDate();
                // Check generated date is between timestamp1 & timestamp2
                value.setMinValue(timeStamp1);
                value.setMaxValue(timeStamp2);
                assertDateBetween(value);
            }
        }
    }
}
Also used : RulesApplier(org.apache.phoenix.pherf.rules.RulesApplier) Column(org.apache.phoenix.pherf.configuration.Column) DataValue(org.apache.phoenix.pherf.rules.DataValue) DataModel(org.apache.phoenix.pherf.configuration.DataModel) WriteWorkload(org.apache.phoenix.pherf.workload.WriteWorkload) XMLConfigParser(org.apache.phoenix.pherf.configuration.XMLConfigParser) Test(org.junit.Test)

Example 4 with DataValue

use of org.apache.phoenix.pherf.rules.DataValue in project phoenix by apache.

the class RuleGeneratorTest method assertRandomDateValue.

/**
     * Verifies that we can generate a date between to specific dates.
     *
     * @param dataMapping
     * @param rulesApplier
     * @throws Exception
     */
private void assertRandomDateValue(Column dataMapping, RulesApplier rulesApplier) throws Exception {
    List<DataValue> dataValues = dataMapping.getDataValues();
    DataValue ruleValue = dataValues.get(2);
    String dt = rulesApplier.generateRandomDate(ruleValue.getMinValue(), ruleValue.getMaxValue());
    ruleValue.setValue(dt);
    assertDateBetween(ruleValue);
}
Also used : DataValue(org.apache.phoenix.pherf.rules.DataValue)

Example 5 with DataValue

use of org.apache.phoenix.pherf.rules.DataValue in project phoenix by apache.

the class ConfigurationParserTest method writeXML.

/*
        Used for debugging to dump out a simple xml filed based on the bound objects.
     */
private String writeXML() {
    DataModel data = new DataModel();
    try {
        DataValue dataValue = new DataValue();
        dataValue.setDistribution(20);
        dataValue.setValue("jnhgGhHminwiajn");
        List<DataValue> dataValueList = new ArrayList<>();
        dataValueList.add(dataValue);
        Column column = new Column();
        column.setLength(15);
        column.setDataSequence(DataSequence.RANDOM);
        column.setName("TEST_COL");
        column.setUserDefined(true);
        column.setDataValues(dataValueList);
        List<Column> columnList = new ArrayList<>();
        columnList.add(column);
        data.setDataMappingColumns(columnList);
        Scenario scenario = new Scenario();
        scenario.setPhoenixProperties(new HashMap<String, String>());
        scenario.getPhoenixProperties().put("phoenix.query.threadPoolSize", "200");
        scenario.setDataOverride(new DataOverride());
        scenario.setTableName("tableName");
        scenario.setRowCount(10);
        QuerySet querySet = new QuerySet();
        querySet.setExecutionType(ExecutionType.PARALLEL);
        querySet.setExecutionDurationInMs(10000);
        scenario.getQuerySet().add(querySet);
        Query query = new Query();
        querySet.getQuery().add(query);
        querySet.setConcurrency("15");
        querySet.setNumberOfExecutions(20);
        query.setStatement("select * from FHA");
        Scenario scenario2 = new Scenario();
        scenario2.setPhoenixProperties(new HashMap<String, String>());
        scenario2.setDataOverride(new DataOverride());
        scenario2.setTableName("tableName2");
        scenario2.setRowCount(500);
        List<Scenario> scenarios = new ArrayList<Scenario>();
        scenarios.add(scenario);
        scenarios.add(scenario2);
        data.setScenarios(scenarios);
        // create JAXB context and initializing Marshaller
        JAXBContext jaxbContext = JAXBContext.newInstance(DataModel.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        // for getting nice formatted output
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        // Writing to console
        jaxbMarshaller.marshal(data, System.out);
    } catch (JAXBException e) {
        // some exception occured
        e.printStackTrace();
    }
    return data.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) DataValue(org.apache.phoenix.pherf.rules.DataValue) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext)

Aggregations

DataValue (org.apache.phoenix.pherf.rules.DataValue)10 Column (org.apache.phoenix.pherf.configuration.Column)7 RulesApplier (org.apache.phoenix.pherf.rules.RulesApplier)6 WriteWorkload (org.apache.phoenix.pherf.workload.WriteWorkload)6 Test (org.junit.Test)6 XMLConfigParser (org.apache.phoenix.pherf.configuration.XMLConfigParser)5 ArrayList (java.util.ArrayList)4 DataModel (org.apache.phoenix.pherf.configuration.DataModel)3 Scenario (org.apache.phoenix.pherf.configuration.Scenario)3 BigDecimal (java.math.BigDecimal)1 Date (java.sql.Date)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 QueryExecutor (org.apache.phoenix.pherf.workload.QueryExecutor)1 Workload (org.apache.phoenix.pherf.workload.Workload)1