use of org.pentaho.di.trans.step.RowAdapter in project pentaho-kettle by pentaho.
the class XmlJoinOmitNullValuesTest method doTest.
private void doTest(final String sourceXml, final String targetXml, final String expectedXml) throws KettleException {
XMLJoin spy = spy(new XMLJoin(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans));
doReturn(createSourceRowSet(sourceXml)).when(spy).findInputRowSet("source");
doReturn(createTargetRowSet(targetXml)).when(spy).findInputRowSet("target");
XMLJoinMeta stepMeta = smh.initStepMetaInterface;
when(stepMeta.getSourceXMLstep()).thenReturn("source");
when(stepMeta.getTargetXMLstep()).thenReturn("target");
when(stepMeta.getSourceXMLfield()).thenReturn("sourceField");
when(stepMeta.getTargetXMLfield()).thenReturn("targetField");
when(stepMeta.getValueXMLfield()).thenReturn("resultField");
when(stepMeta.getTargetXPath()).thenReturn("//root");
when(stepMeta.isOmitNullValues()).thenReturn(true);
spy.init(stepMeta, smh.initStepDataInterface);
spy.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
Assert.assertEquals(expectedXml, row[0]);
}
});
Assert.assertTrue(spy.processRow(stepMeta, smh.initStepDataInterface));
Assert.assertFalse(spy.processRow(stepMeta, smh.initStepDataInterface));
}
use of org.pentaho.di.trans.step.RowAdapter in project pentaho-kettle by pentaho.
the class TransDebugMeta method addRowListenersToTransformation.
public synchronized void addRowListenersToTransformation(final Trans trans) {
final TransDebugMeta self = this;
//
for (final StepMeta stepMeta : stepDebugMetaMap.keySet()) {
final StepDebugMeta stepDebugMeta = stepDebugMetaMap.get(stepMeta);
//
for (StepInterface baseStep : trans.findBaseSteps(stepMeta.getName())) {
baseStep.addRowListener(new RowAdapter() {
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
try {
// This block of code is called whenever there is a row written by the step
// So we want to execute the debugging actions that are specified by the step...
//
int rowCount = stepDebugMeta.getRowCount();
if (stepDebugMeta.isReadingFirstRows() && rowCount > 0) {
int bufferSize = stepDebugMeta.getRowBuffer().size();
if (bufferSize < rowCount) {
// This is the classic preview mode.
// We add simply add the row to the buffer.
//
stepDebugMeta.setRowBufferMeta(rowMeta);
stepDebugMeta.getRowBuffer().add(rowMeta.cloneRow(row));
} else {
// pause the transformation...
//
trans.pauseRunning();
// Also call the pause / break-point listeners on the step debugger...
//
stepDebugMeta.fireBreakPointListeners(self);
}
} else if (stepDebugMeta.isPausingOnBreakPoint() && stepDebugMeta.getCondition() != null) {
//
if (rowCount > 0) {
// Keep a number of rows in memory
// Store them in a reverse order to keep it intuitive for the user.
//
stepDebugMeta.setRowBufferMeta(rowMeta);
stepDebugMeta.getRowBuffer().add(0, rowMeta.cloneRow(row));
// Only keep a number of rows in memory
// If we have too many, remove the last (oldest)
//
int bufferSize = stepDebugMeta.getRowBuffer().size();
if (bufferSize > rowCount) {
stepDebugMeta.getRowBuffer().remove(bufferSize - 1);
}
} else {
//
if (stepDebugMeta.getRowBuffer().isEmpty()) {
stepDebugMeta.getRowBuffer().add(rowMeta.cloneRow(row));
} else {
stepDebugMeta.getRowBuffer().set(0, rowMeta.cloneRow(row));
}
}
//
if (stepDebugMeta.getCondition().evaluate(rowMeta, row)) {
// We hit the break-point: pause the transformation
//
trans.pauseRunning();
// Also fire off the break point listeners...
//
stepDebugMeta.fireBreakPointListeners(self);
}
}
} catch (KettleException e) {
throw new KettleStepException(e);
}
}
});
}
}
}
use of org.pentaho.di.trans.step.RowAdapter in project pentaho-kettle by pentaho.
the class RowGeneratorUnitTest method doesNotWriteRowOnTimeWhenStopped.
@Test
public void doesNotWriteRowOnTimeWhenStopped() throws KettleException, InterruptedException {
TransMeta transMeta = new TransMeta(getClass().getResource("safe-stop.ktr").getPath());
Trans trans = new Trans(transMeta);
trans.prepareExecution(new String[] {});
trans.getSteps().get(1).step.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
trans.safeStop();
}
});
trans.startThreads();
trans.waitUntilFinished();
assertEquals(1, trans.getSteps().get(0).step.getLinesWritten());
assertEquals(1, trans.getSteps().get(1).step.getLinesRead());
}
use of org.pentaho.di.trans.step.RowAdapter 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.trans.step.RowAdapter 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