Search in sources :

Example 1 with Column

use of org.apache.phoenix.pherf.configuration.Column 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 Column

use of org.apache.phoenix.pherf.configuration.Column 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 Column

use of org.apache.phoenix.pherf.configuration.Column 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 Column

use of org.apache.phoenix.pherf.configuration.Column in project phoenix by apache.

the class WriteWorkload method getBatches.

private List<Future<Info>> getBatches(DataLoadThreadTime dataLoadThreadTime, Scenario scenario) throws Exception {
    RowCalculator rowCalculator = new RowCalculator(getThreadPoolSize(), scenario.getRowCount());
    List<Future<Info>> writeBatches = new ArrayList<>();
    for (int i = 0; i < getThreadPoolSize(); i++) {
        List<Column> phxMetaCols = pUtil.getColumnsFromPhoenix(scenario.getSchemaName(), scenario.getTableNameWithoutSchemaName(), pUtil.getConnection(scenario.getTenantId()));
        int threadRowCount = rowCalculator.getNext();
        logger.info("Kick off thread (#" + i + ")for upsert with (" + threadRowCount + ") rows.");
        Future<Info> write = upsertData(scenario, phxMetaCols, scenario.getTableName(), threadRowCount, dataLoadThreadTime, this.useBatchApi);
        writeBatches.add(write);
    }
    if (writeBatches.isEmpty()) {
        throw new PherfException("Holy shit snacks! Throwing up hands in disbelief and exiting. Could not write data for some unknown reason.");
    }
    return writeBatches;
}
Also used : PherfException(org.apache.phoenix.pherf.exception.PherfException) Column(org.apache.phoenix.pherf.configuration.Column) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) RowCalculator(org.apache.phoenix.pherf.util.RowCalculator)

Example 5 with Column

use of org.apache.phoenix.pherf.configuration.Column in project phoenix by apache.

the class ColumnTest method testColumnMutate.

@Test
public void testColumnMutate() {
    Column columnA = new Column();
    Column columnB = new Column();
    Column columnC = new Column();
    columnA.setType(DataTypeMapping.VARCHAR);
    columnB.setType(DataTypeMapping.VARCHAR);
    columnA.setLength(15);
    columnA.setMinValue(20);
    columnA.setMaxValue(25);
    columnB.setLength(30);
    columnC.setMaxValue(45);
    columnA.mutate(columnB);
    assertTrue("Mutation failed length", columnA.getLength() == columnB.getLength());
    columnA.mutate(columnC);
    assertTrue("Mutation failed length", columnA.getLength() == columnB.getLength());
    assertTrue("Mutation failed min", columnA.getMinValue() == 20);
    assertTrue("Mutation failed max", columnA.getMaxValue() == columnC.getMaxValue());
    assertTrue("Mutation failed name", columnA.getName() == null);
}
Also used : Column(org.apache.phoenix.pherf.configuration.Column) Test(org.junit.Test)

Aggregations

Column (org.apache.phoenix.pherf.configuration.Column)12 Test (org.junit.Test)8 DataValue (org.apache.phoenix.pherf.rules.DataValue)7 RulesApplier (org.apache.phoenix.pherf.rules.RulesApplier)7 WriteWorkload (org.apache.phoenix.pherf.workload.WriteWorkload)7 XMLConfigParser (org.apache.phoenix.pherf.configuration.XMLConfigParser)6 DataModel (org.apache.phoenix.pherf.configuration.DataModel)5 ArrayList (java.util.ArrayList)4 Scenario (org.apache.phoenix.pherf.configuration.Scenario)4 SQLException (java.sql.SQLException)2 BigDecimal (java.math.BigDecimal)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Connection (java.sql.Connection)1 Date (java.sql.Date)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1 DataSequence (org.apache.phoenix.pherf.configuration.DataSequence)1 PherfException (org.apache.phoenix.pherf.exception.PherfException)1 SchemaReader (org.apache.phoenix.pherf.schema.SchemaReader)1