Search in sources :

Example 21 with StepMetaDataCombi

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

the class RunTransServletTest method testFinishProcessingTransWithServletOutputSteps.

@Test
public void testFinishProcessingTransWithServletOutputSteps() throws Exception {
    StepMetaDataCombi stepMetaDataCombi = new StepMetaDataCombi();
    StepMetaInterface stepMeta = mock(StepMetaInterface.class);
    when(stepMeta.passDataToServletOutput()).thenReturn(true);
    stepMetaDataCombi.meta = stepMeta;
    stepList.add(stepMetaDataCombi);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Thread.currentThread().sleep(2000);
            return null;
        }
    }).when(trans).waitUntilFinished();
    runTransServlet.finishProcessing(trans, out);
    assertTrue(outData.toString().isEmpty());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Test(org.junit.Test)

Example 22 with StepMetaDataCombi

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

the class StepExternalResourceConsumerListenerTest method testCallStepExtensionPoint.

@Test
public void testCallStepExtensionPoint() throws Exception {
    StepExternalResourceConsumerListener stepExtensionPoint = new StepExternalResourceConsumerListener();
    stepExtensionPoint.setStepExternalResourceConsumerProvider(MetaverseTestUtils.getStepExternalResourceConsumerProvider());
    StepMetaDataCombi stepCombi = mock(StepMetaDataCombi.class);
    BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
    stepCombi.meta = (StepMetaInterface) bsm;
    stepCombi.step = mock(StepInterface.class);
    stepCombi.stepMeta = mock(StepMeta.class);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    Map<Class<? extends BaseStepMeta>, Set<IStepExternalResourceConsumer>> stepConsumerMap = new StepExternalResourceConsumerProvider().getStepConsumerMap();
    Set<IStepExternalResourceConsumer> consumers = new HashSet<IStepExternalResourceConsumer>();
    stepConsumerMap.put(bsm.getClass(), consumers);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
    when(consumer.getResourcesFromMeta(Mockito.any())).thenReturn(Collections.emptyList());
    consumers.add(consumer);
    Trans mockTrans = mock(Trans.class);
    when(stepCombi.step.getTrans()).thenReturn(mockTrans);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    when(consumer.isDataDriven(Mockito.any())).thenReturn(Boolean.TRUE);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) StepInterface(org.pentaho.di.trans.step.StepInterface) StepExternalResourceConsumerProvider(org.pentaho.metaverse.analyzer.kettle.step.StepExternalResourceConsumerProvider) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Trans(org.pentaho.di.trans.Trans) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with StepMetaDataCombi

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

the class KettleComponent method registerAsStepListener.

private boolean registerAsStepListener(String stepName, Trans trans) throws KettleComponentException {
    boolean success = false;
    try {
        if (trans != null) {
            List<StepMetaDataCombi> stepList = trans.getSteps();
            // find the specified step
            for (StepMetaDataCombi step : stepList) {
                if (step.stepname.equals(stepName)) {
                    if (ComponentBase.debug) {
                        // $NON-NLS-1$
                        debug(Messages.getInstance().getString("Kettle.DEBUG_FOUND_STEP_IMPORTER"));
                    }
                    // this is the step we are looking for
                    if (ComponentBase.debug) {
                        // $NON-NLS-1$
                        debug(Messages.getInstance().getString("Kettle.DEBUG_GETTING_STEP_METADATA"));
                    }
                    RowMetaInterface row = trans.getTransMeta().getStepFields(stepName);
                    // create the metadata that the Pentaho result sets need
                    String[] fieldNames = row.getFieldNames();
                    String[][] columns = new String[1][fieldNames.length];
                    for (int column = 0; column < fieldNames.length; column++) {
                        columns[0][column] = fieldNames[column];
                    }
                    if (ComponentBase.debug) {
                        // $NON-NLS-1$
                        debug(Messages.getInstance().getString("Kettle.DEBUG_CREATING_RESULTSET_METADATA"));
                    }
                    MemoryMetaData metaData = new MemoryMetaData(columns, null);
                    results = new MemoryResultSet(metaData);
                    errorResults = new MemoryResultSet(metaData);
                    // add ourself as a row listener
                    step.step.addRowListener(this);
                    success = true;
                    break;
                }
            }
        }
    } catch (Exception e) {
        throw new KettleComponentException(Messages.getInstance().getString("Kettle.ERROR_0027_ERROR_INIT_STEP", stepName), // $NON-NLS-1$
        e);
    }
    return success;
}
Also used : StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) KettleException(org.pentaho.di.core.exception.KettleException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 24 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pdi-dataservice-server-plugin by pentaho.

the class StepOptimization method preview.

@Override
public OptimizationImpactInfo preview(DataServiceExecutor executor, PushDownOptimizationMeta meta) {
    OptimizationImpactInfo info = new OptimizationImpactInfo(meta.getStepName());
    Trans serviceTrans = executor.getServiceTrans();
    try {
        // Start up service Trans threads
        serviceTrans.prepareExecution(null);
        // Find the step thread and run preview
        info = preview(executor, serviceTrans.findRunThread(meta.getStepName()));
        // Dispose resources
        for (StepMetaDataCombi stepMetaDataCombi : serviceTrans.getSteps()) {
            stepMetaDataCombi.step.setOutputDone();
            stepMetaDataCombi.step.dispose(stepMetaDataCombi.meta, stepMetaDataCombi.data);
            stepMetaDataCombi.step.markStop();
        }
    } catch (Exception e) {
        info.setErrorMsg(e);
    }
    return info;
}
Also used : StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Trans(org.pentaho.di.trans.Trans)

Example 25 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pdi-dataservice-server-plugin by pentaho.

the class StepOptimizationTest method testPreview.

@Test
public void testPreview() throws Exception {
    OptimizationImpactInfo impactInfo = new OptimizationImpactInfo(OPTIMIZED_STEP);
    doReturn(impactInfo).when(stepOptimization).preview(executor, stepInterface);
    StepMetaDataCombi stepStruct = new StepMetaDataCombi() {

        {
            stepMeta = mock(StepMeta.class);
            stepname = OPTIMIZED_STEP;
            copy = 0;
            step = stepInterface;
            meta = mock(StepMetaInterface.class);
            data = mock(StepDataInterface.class);
        }
    };
    when(serviceTrans.getSteps()).thenReturn(ImmutableList.of(stepStruct));
    assertThat(stepOptimization.preview(executor, meta), sameInstance(impactInfo));
    final InOrder inOrder = inOrder(serviceTrans, stepInterface, stepOptimization);
    // Verify trans is prepared
    inOrder.verify(serviceTrans).prepareExecution(null);
    inOrder.verify(serviceTrans).findRunThread(OPTIMIZED_STEP);
    // Run preview
    inOrder.verify(stepOptimization).preview(executor, stepInterface);
    // Clean up
    inOrder.verify(stepInterface).setOutputDone();
    inOrder.verify(stepInterface).dispose(stepStruct.meta, stepStruct.data);
    inOrder.verify(stepInterface).markStop();
}
Also used : InOrder(org.mockito.InOrder) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) Test(org.junit.Test) BaseTest(org.pentaho.di.trans.dataservice.BaseTest)

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