use of org.pentaho.di.core.exception.KettleStepException 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.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class InsertUpdateMetaTest method testErrorProcessRow.
@Test
public void testErrorProcessRow() throws KettleException {
Mockito.when(mockHelper.logChannelInterfaceFactory.create(Mockito.any(), Mockito.any(LoggingObjectInterface.class))).thenReturn(mockHelper.logChannelInterface);
Mockito.when(mockHelper.stepMeta.getStepMetaInterface()).thenReturn(new InsertUpdateMeta());
InsertUpdate insertUpdateStep = new InsertUpdate(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
insertUpdateStep = Mockito.spy(insertUpdateStep);
Mockito.doReturn(new Object[] {}).when(insertUpdateStep).getRow();
insertUpdateStep.first = false;
mockHelper.processRowsStepDataInterface.lookupParameterRowMeta = Mockito.mock(RowMetaInterface.class);
mockHelper.processRowsStepDataInterface.keynrs = new int[] {};
mockHelper.processRowsStepDataInterface.db = Mockito.mock(Database.class);
mockHelper.processRowsStepDataInterface.valuenrs = new int[] {};
Mockito.doThrow(new KettleStepException("Test exception")).when(insertUpdateStep).putRow(Mockito.any(), Mockito.any());
boolean result = insertUpdateStep.processRow(mockHelper.processRowsStepMetaInterface, mockHelper.processRowsStepDataInterface);
Assert.assertFalse(result);
}
use of org.pentaho.di.core.exception.KettleStepException 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.exception.KettleStepException 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();
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class CalculatorUnitTest method testReturnDigitsOnly.
@Test
public void testReturnDigitsOnly() throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaString nameMeta = new ValueMetaString("Name");
inputRowMeta.addValueMeta(nameMeta);
ValueMetaString valueMeta = new ValueMetaString("Value");
inputRowMeta.addValueMeta(valueMeta);
RowSet inputRowSet = smh.getMockInputRowSet(new Object[][] { { "name1", "qwe123asd456zxc" }, { "name2", null } });
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("digits", CalculatorMetaFunction.CALC_GET_ONLY_DIGITS, "Value", null, null, ValueMetaInterface.TYPE_STRING, 0, 0, false, "", "", "", "") });
// Verify output
try {
calculator.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
assertEquals("123456", row[2]);
}
});
calculator.processRow(meta, new CalculatorData());
} catch (KettleException ke) {
ke.printStackTrace();
fail();
}
}
Aggregations