Search in sources :

Example 36 with Trans

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

the class MetaInjectTest method testTransWaitsForListenersToFinish.

@Test
public void testTransWaitsForListenersToFinish() throws Exception {
    doReturn(new String[] {}).when(transMeta).getPrevStepNames(any(StepMeta.class));
    data.stepInjectionMetasMap = new HashMap<>();
    data.stepInjectionMap = new HashMap<>();
    data.transMeta = new TransMeta();
    meta.setNoExecution(false);
    Trans injectTrans = mock(Trans.class);
    doReturn(injectTrans).when(metaInject).createInjectTrans();
    when(injectTrans.isFinished()).thenReturn(true);
    Result result = mock(Result.class);
    when(injectTrans.getResult()).thenReturn(result);
    metaInject.processRow(meta, data);
    verify(injectTrans).waitUntilFinished();
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Trans(org.pentaho.di.trans.Trans) Result(org.pentaho.di.core.Result) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with Trans

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

the class AccessInputDialog method preview.

// Preview the data
private void preview() {
    try {
        // Create the Access input step
        AccessInputMeta oneMeta = new AccessInputMeta();
        getInfo(oneMeta);
        // check if the path is given
        if (!checkInputTableName(oneMeta)) {
            return;
        }
        TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
        EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "AccessInputDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "AccessInputDialog.NumberRows.DialogMessage"));
        int previewSize = numberDialog.open();
        if (previewSize > 0) {
            TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
            progressDialog.open();
            if (!progressDialog.isCancelled()) {
                Trans trans = progressDialog.getTrans();
                String loggingText = progressDialog.getLoggingText();
                if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                    EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                    etd.setReadOnly();
                    etd.open();
                }
                PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
                prd.open();
            }
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "AccessInputDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "AccessInputDialog.ErrorPreviewingData.DialogMessage"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) AccessInputMeta(org.pentaho.di.trans.steps.accessinput.AccessInputMeta) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) Trans(org.pentaho.di.trans.Trans)

Example 38 with Trans

use of org.pentaho.di.trans.Trans 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 39 with Trans

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

the class ScriptValueAddFunctions_SetVariableScopeTest method setSystemScopeVariable_NoParent.

@Test
public void setSystemScopeVariable_NoParent() {
    Trans trans = createTrans();
    Assert.assertNull(System.getProperty(VARIABLE_NAME));
    try {
        ScriptValuesAddedFunctions.setSystemScopeVariable(trans, VARIABLE_NAME, VARIABLE_VALUE);
        Assert.assertEquals(System.getProperty(VARIABLE_NAME), VARIABLE_VALUE);
        verify(trans).setVariable(eq(VARIABLE_NAME), eq(VARIABLE_VALUE));
    } finally {
        System.clearProperty(VARIABLE_NAME);
    }
}
Also used : Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 40 with Trans

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

the class ScriptValueAddFunctions_SetVariableScopeTest method setGrandParentScopeVariable_TwoLevelHierarchy.

@Test
public void setGrandParentScopeVariable_TwoLevelHierarchy() {
    Trans parent = createTrans();
    Trans child = createTrans(parent);
    ScriptValuesAddedFunctions.setGrandParentScopeVariable(child, VARIABLE_NAME, VARIABLE_VALUE);
    verify(child).setVariable(eq(VARIABLE_NAME), eq(VARIABLE_VALUE));
    verify(parent).setVariable(eq(VARIABLE_NAME), eq(VARIABLE_VALUE));
}
Also used : Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Aggregations

Trans (org.pentaho.di.trans.Trans)307 TransMeta (org.pentaho.di.trans.TransMeta)210 StepMeta (org.pentaho.di.trans.step.StepMeta)118 Test (org.junit.Test)95 StepInterface (org.pentaho.di.trans.step.StepInterface)92 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)84 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)81 TransHopMeta (org.pentaho.di.trans.TransHopMeta)77 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)73 RowStepCollector (org.pentaho.di.trans.RowStepCollector)71 KettleException (org.pentaho.di.core.exception.KettleException)65 RowProducer (org.pentaho.di.trans.RowProducer)58 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)54 TransPreviewProgressDialog (org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog)48 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)47 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)47 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)47 EnterNumberDialog (org.pentaho.di.ui.core.dialog.EnterNumberDialog)42 PrintWriter (java.io.PrintWriter)34 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)29