use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class TransExecutorUnitTest method collectsExecutionResults.
@Test
public void collectsExecutionResults() throws Exception {
prepareOneRowForExecutor();
StepMeta parentStepMeta = mock(StepMeta.class);
when(parentStepMeta.getName()).thenReturn("parentStepMeta");
meta.setParentStepMeta(parentStepMeta);
internalResult.setResult(true);
meta.setExecutionResultField("executionResultField");
internalResult.setNrErrors(1);
meta.setExecutionNrErrorsField("executionNrErrorsField");
internalResult.setNrLinesRead(2);
meta.setExecutionLinesReadField("executionLinesReadField");
internalResult.setNrLinesWritten(3);
meta.setExecutionLinesWrittenField("executionLinesWrittenField");
internalResult.setNrLinesInput(4);
meta.setExecutionLinesInputField("executionLinesInputField");
internalResult.setNrLinesOutput(5);
meta.setExecutionLinesOutputField("executionLinesOutputField");
internalResult.setNrLinesRejected(6);
meta.setExecutionLinesRejectedField("executionLinesRejectedField");
internalResult.setNrLinesUpdated(7);
meta.setExecutionLinesUpdatedField("executionLinesUpdatedField");
internalResult.setNrLinesDeleted(8);
meta.setExecutionLinesDeletedField("executionLinesDeletedField");
internalResult.setNrFilesRetrieved(9);
meta.setExecutionFilesRetrievedField("executionFilesRetrievedField");
internalResult.setExitStatus(10);
meta.setExecutionExitStatusField("executionExitStatusField");
RowSet rowSet = new QueueRowSet();
// any value except null
StepMeta stepMeta = mockStepAndMapItToRowSet("stepMetaMock", rowSet);
meta.setExecutionResultTargetStepMeta(stepMeta);
executor.init(meta, data);
executor.setInputRowMeta(new RowMeta());
assertTrue("Passing one line at first time", executor.processRow(meta, data));
assertFalse("Executing the internal trans during the second round", executor.processRow(meta, data));
Object[] resultsRow = rowSet.getRowImmediate();
assertNotNull(resultsRow);
assertNull("Only one row is expected", rowSet.getRowImmediate());
assertEquals(internalResult.getResult(), resultsRow[0]);
assertEquals(internalResult.getNrErrors(), resultsRow[1]);
assertEquals(internalResult.getNrLinesRead(), resultsRow[2]);
assertEquals(internalResult.getNrLinesWritten(), resultsRow[3]);
assertEquals(internalResult.getNrLinesInput(), resultsRow[4]);
assertEquals(internalResult.getNrLinesOutput(), resultsRow[5]);
assertEquals(internalResult.getNrLinesRejected(), resultsRow[6]);
assertEquals(internalResult.getNrLinesUpdated(), resultsRow[7]);
assertEquals(internalResult.getNrLinesDeleted(), resultsRow[8]);
assertEquals(internalResult.getNrFilesRetrieved(), resultsRow[9]);
assertEquals(internalResult.getExitStatus(), ((Number) resultsRow[10]).intValue());
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class TransExecutorUnitTest method collectsResultsFromInternalTransformation.
@Test
public void collectsResultsFromInternalTransformation() throws Exception {
prepareOneRowForExecutor();
RowMetaAndData expectedResult = new RowMetaAndData(new RowMeta(), "fake result");
internalResult.getRows().add(expectedResult);
RowSet rowSet = new QueueRowSet();
// any value except null
StepMeta stepMeta = mockStepAndMapItToRowSet("stepMetaMock", rowSet);
meta.setOutputRowsSourceStepMeta(stepMeta);
executor.init(meta, data);
executor.setInputRowMeta(new RowMeta());
assertTrue("Passing one line at first time", executor.processRow(meta, data));
assertFalse("Executing the internal trans during the second round", executor.processRow(meta, data));
Object[] resultsRow = rowSet.getRowImmediate();
assertNotNull(resultsRow);
assertArrayEquals(expectedResult.getData(), resultsRow);
assertNull("Only one row is expected", rowSet.getRowImmediate());
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class BaseStepTest method outputRowMetasAreNotSharedAmongSeveralStreams.
@Test
public void outputRowMetasAreNotSharedAmongSeveralStreams() throws Exception {
RowSet rs1 = new SingleRowRowSet();
RowSet rs2 = new SingleRowRowSet();
when(mockHelper.trans.isRunning()).thenReturn(true);
BaseStep baseStep = new BaseStep(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
baseStep.setStopped(false);
baseStep.setRepartitioning(StepPartitioningMeta.PARTITIONING_METHOD_NONE);
baseStep.setOutputRowSets(Arrays.asList(rs1, rs2));
for (RowSet rowSet : baseStep.getOutputRowSets()) {
assertNull("RowMeta should be null, since no calls were done", rowSet.getRowMeta());
}
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaString("string"));
rowMeta.addValueMeta(new ValueMetaInteger("integer"));
baseStep.putRow(rowMeta, new Object[] { "a", 1 });
RowMetaInterface meta1 = rs1.getRowMeta();
RowMetaInterface meta2 = rs2.getRowMeta();
assertNotNull(meta1);
assertNotNull(meta2);
// content is same
for (ValueMetaInterface meta : meta1.getValueMetaList()) {
assertTrue(meta.getName(), meta2.exists(meta));
}
// whereas instances differ
assertFalse(meta1 == meta2);
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class CalculatorBackwardCompatibilityUnitTest method assertRound2.
public void assertRound2(final double expectedResult, final double value, final long precision) throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaNumber valueMeta = new ValueMetaNumber("Value");
ValueMetaInteger precisionMeta = new ValueMetaInteger("Precision");
inputRowMeta.addValueMeta(valueMeta);
inputRowMeta.addValueMeta(precisionMeta);
RowSet inputRowSet = smh.getMockInputRowSet(new Object[] { value, precision });
inputRowSet.setRowMeta(inputRowMeta);
Calculator calculator = new Calculator(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
calculator.addRowSetToInputRowSets(inputRowSet);
calculator.setInputRowMeta(inputRowMeta);
calculator.init(smh.initStepMetaInterface, smh.initStepDataInterface);
CalculatorMeta meta = new CalculatorMeta();
meta.setCalculation(new CalculatorMetaFunction[] { new CalculatorMetaFunction("test", CalculatorMetaFunction.CALC_ROUND_2, "Value", "Precision", null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false, "", "", "", "") });
// Verify output
try {
calculator.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
assertEquals(expectedResult, row[2]);
}
});
calculator.processRow(meta, new CalculatorData());
} catch (KettleException ke) {
ke.printStackTrace();
fail();
}
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class CalculatorBackwardCompatibilityUnitTest method assertRound.
public void assertRound(final double expectedResult, final double value) throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaNumber valueMeta = new ValueMetaNumber("Value");
inputRowMeta.addValueMeta(valueMeta);
RowSet inputRowSet = smh.getMockInputRowSet(new Object[] { value });
inputRowSet.setRowMeta(inputRowMeta);
Calculator calculator = new Calculator(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
calculator.addRowSetToInputRowSets(inputRowSet);
calculator.setInputRowMeta(inputRowMeta);
calculator.init(smh.initStepMetaInterface, smh.initStepDataInterface);
CalculatorMeta meta = new CalculatorMeta();
meta.setCalculation(new CalculatorMetaFunction[] { new CalculatorMetaFunction("test", CalculatorMetaFunction.CALC_ROUND_1, "Value", null, null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false, "", "", "", "") });
// Verify output
try {
calculator.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
assertEquals(expectedResult, row[1]);
}
});
calculator.processRow(meta, new CalculatorData());
} catch (KettleException ke) {
ke.printStackTrace();
fail();
}
}
Aggregations