Search in sources :

Example 46 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pentaho-kettle by pentaho.

the class TransTest method testRecordsCleanUpMethodIsCalled.

@Test
public void testRecordsCleanUpMethodIsCalled() throws Exception {
    Database mockedDataBase = mock(Database.class);
    Trans trans = mock(Trans.class);
    StepLogTable stepLogTable = StepLogTable.getDefault(mock(VariableSpace.class), mock(HasDatabasesInterface.class));
    stepLogTable.setConnectionName("connection");
    TransMeta transMeta = new TransMeta();
    transMeta.setStepLogTable(stepLogTable);
    when(trans.getTransMeta()).thenReturn(transMeta);
    when(trans.createDataBase(any(DatabaseMeta.class))).thenReturn(mockedDataBase);
    when(trans.getSteps()).thenReturn(new ArrayList<StepMetaDataCombi>());
    doCallRealMethod().when(trans).writeStepLogInformation();
    trans.writeStepLogInformation();
    verify(mockedDataBase).cleanupLogRecords(stepLogTable);
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) StepLogTable(org.pentaho.di.core.logging.StepLogTable) Database(org.pentaho.di.core.database.Database) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 47 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pentaho-kettle by pentaho.

the class TransTest method testSafeStop.

@Test
public void testSafeStop() {
    StepInterface step = mock(StepInterface.class);
    when(step.isSafeStopped()).thenReturn(false);
    when(step.getStepname()).thenReturn("stepName");
    StepMetaDataCombi stepMetaDataCombi = new StepMetaDataCombi();
    stepMetaDataCombi.step = step;
    trans.setSteps(Collections.singletonList(stepMetaDataCombi));
    Result result = trans.getResult();
    assertFalse(result.isSafeStop());
    when(step.isSafeStopped()).thenReturn(true);
    result = trans.getResult();
    assertTrue(result.isSafeStop());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 48 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pentaho-kettle by pentaho.

the class BaseStreamStepTest method setUp.

@Before
public void setUp() throws KettleException {
    KettleLogStore.setLogChannelInterfaceFactory(logChannelFactory);
    when(logChannelFactory.create(any(), any())).thenReturn(logChannel);
    stepMeta = new StepMeta("BaseStreamStep", meta);
    transMeta = new TransMeta();
    transMeta.addStep(stepMeta);
    trans = new Trans(transMeta);
    baseStreamStep = new BaseStreamStep(stepMeta, stepData, 1, transMeta, trans);
    baseStreamStep.source = streamSource;
    baseStreamStep.window = streamWindow;
    StepMetaDataCombi stepMetaDataCombi = new StepMetaDataCombi();
    stepMetaDataCombi.step = baseStreamStep;
    stepMetaDataCombi.data = stepData;
    stepMetaDataCombi.stepMeta = stepMeta;
    stepMetaDataCombi.meta = meta;
    trans.prepareExecution(new String[0]);
    trans.getSteps().add(stepMetaDataCombi);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) Before(org.junit.Before)

Example 49 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pentaho-kettle by pentaho.

the class RunTransServletTest method setup.

@Before
public void setup() throws Exception {
    runTransServlet = new RunTransServlet();
    outData = new ByteArrayOutputStream();
    out = new PrintWriter(outData);
    stepList = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        StepMetaDataCombi stepMetaDataCombi = new StepMetaDataCombi();
        StepMetaInterface stepMeta = mock(StepMetaInterface.class);
        when(stepMeta.passDataToServletOutput()).thenReturn(false);
        stepMetaDataCombi.meta = stepMeta;
        stepList.add(stepMetaDataCombi);
    }
    when(trans.getSteps()).thenReturn(stepList);
    when(trans.getContainerObjectId()).thenReturn(transId);
}
Also used : StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 50 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pentaho-kettle by pentaho.

the class TransPreviewDelegate method capturePreviewData.

public void capturePreviewData(final Trans trans, List<StepMeta> stepMetas) {
    final StringBuffer loggingText = new StringBuffer();
    // First clean out previous preview data. Otherwise this method leaks memory like crazy.
    // 
    previewLogMap.clear();
    previewMetaMap.clear();
    previewDataMap.clear();
    try {
        final TransMeta transMeta = trans.getTransMeta();
        for (final StepMeta stepMeta : stepMetas) {
            final RowMetaInterface rowMeta = transMeta.getStepFields(stepMeta).clone();
            previewMetaMap.put(stepMeta, rowMeta);
            final List<Object[]> rowsData;
            if (previewMode == PreviewMode.LAST) {
                rowsData = new LinkedList<Object[]>();
            } else {
                rowsData = new ArrayList<Object[]>();
            }
            previewDataMap.put(stepMeta, rowsData);
            previewLogMap.put(stepMeta, loggingText);
            StepInterface step = trans.findRunThread(stepMeta.getName());
            if (step != null) {
                switch(previewMode) {
                    case LAST:
                        step.addRowListener(new RowAdapter() {

                            @Override
                            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                                try {
                                    rowsData.add(rowMeta.cloneRow(row));
                                    if (rowsData.size() > PropsUI.getInstance().getDefaultPreviewSize()) {
                                        rowsData.remove(0);
                                    }
                                } catch (Exception e) {
                                    throw new KettleStepException("Unable to clone row for metadata : " + rowMeta, e);
                                }
                            }
                        });
                        break;
                    default:
                        step.addRowListener(new RowAdapter() {

                            @Override
                            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                                if (rowsData.size() < PropsUI.getInstance().getDefaultPreviewSize()) {
                                    try {
                                        rowsData.add(rowMeta.cloneRow(row));
                                    } catch (Exception e) {
                                        throw new KettleStepException("Unable to clone row for metadata : " + rowMeta, e);
                                    }
                                }
                            }
                        });
                        break;
                }
            }
        }
    } catch (Exception e) {
        loggingText.append(Const.getStackTracker(e));
    }
    // In case there were errors during preview...
    // 
    trans.addTransListener(new TransAdapter() {

        @Override
        public void transFinished(Trans trans) throws KettleException {
            // 
            if (trans.getErrors() != 0) {
                // 
                for (StepMetaDataCombi combi : trans.getSteps()) {
                    if (combi.copy == 0) {
                        StringBuffer logBuffer = KettleLogStore.getAppender().getBuffer(combi.step.getLogChannel().getLogChannelId(), false);
                        previewLogMap.put(combi.stepMeta, logBuffer);
                    }
                }
            }
        }
    });
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) TransAdapter(org.pentaho.di.trans.TransAdapter) StepInterface(org.pentaho.di.trans.step.StepInterface) RowAdapter(org.pentaho.di.trans.step.RowAdapter) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Trans(org.pentaho.di.trans.Trans)

Aggregations

StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)55 StepInterface (org.pentaho.di.trans.step.StepInterface)21 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)18 Test (org.junit.Test)13 KettleException (org.pentaho.di.core.exception.KettleException)10 ArrayList (java.util.ArrayList)8 StepMeta (org.pentaho.di.trans.step.StepMeta)8 Trans (org.pentaho.di.trans.Trans)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)6 KettleValueException (org.pentaho.di.core.exception.KettleValueException)6 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)6 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)6 RowSet (org.pentaho.di.core.RowSet)5 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)5 TransMeta (org.pentaho.di.trans.TransMeta)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Before (org.junit.Before)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleFileException (org.pentaho.di.core.exception.KettleFileException)4