Search in sources :

Example 71 with KettleStepException

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());
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowAdapter(org.pentaho.di.trans.step.RowAdapter) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 72 with KettleStepException

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);
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) Test(org.junit.Test)

Example 73 with KettleStepException

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();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowAdapter(org.pentaho.di.trans.step.RowAdapter) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 74 with KettleStepException

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();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowAdapter(org.pentaho.di.trans.step.RowAdapter)

Example 75 with KettleStepException

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();
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowAdapter(org.pentaho.di.trans.step.RowAdapter) Test(org.junit.Test)

Aggregations

KettleStepException (org.pentaho.di.core.exception.KettleStepException)235 KettleException (org.pentaho.di.core.exception.KettleException)139 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)103 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)97 RowMeta (org.pentaho.di.core.row.RowMeta)51 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)44 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)27 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)27 KettleValueException (org.pentaho.di.core.exception.KettleValueException)26 IOException (java.io.IOException)23 RowAdapter (org.pentaho.di.trans.step.RowAdapter)21 ArrayList (java.util.ArrayList)20 StepMeta (org.pentaho.di.trans.step.StepMeta)19 RowSet (org.pentaho.di.core.RowSet)18 Database (org.pentaho.di.core.database.Database)15 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)13 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)13 FormAttachment (org.eclipse.swt.layout.FormAttachment)12 FormData (org.eclipse.swt.layout.FormData)12 Button (org.eclipse.swt.widgets.Button)12