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);
}
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());
}
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);
}
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);
}
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);
}
}
}
}
});
}
Aggregations