use of org.pentaho.di.trans.step.BaseStep in project pentaho-metaverse by pentaho.
the class StepExternalConsumerRowListenerTest method testStepExternalConsumerRowListener.
@Test
public void testStepExternalConsumerRowListener() throws Exception {
IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
BaseStep mockStep = mock(BaseStep.class, withSettings().extraInterfaces(StepInterface.class));
StepMeta mockStepMeta = mock(StepMeta.class);
BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
StepMetaInterface stepMetaInterface = (StepMetaInterface) bsm;
when(mockStep.getStepMeta()).thenReturn(mockStepMeta);
when(mockStepMeta.getStepMetaInterface()).thenReturn(stepMetaInterface);
Trans mockTrans = mock(Trans.class);
when(mockStep.getTrans()).thenReturn(mockTrans);
IExecutionProfile executionProfile = mock(IExecutionProfile.class);
IExecutionData executionData = mock(IExecutionData.class);
when(executionProfile.getExecutionData()).thenReturn(executionData);
LineageHolder holder = new LineageHolder();
holder.setExecutionProfile(executionProfile);
TransLineageHolderMap.getInstance().putLineageHolder(mockTrans, holder);
StepExternalConsumerRowListener listener = new StepExternalConsumerRowListener(consumer, mockStep);
RowMetaInterface rmi = mock(RowMetaInterface.class);
Object[] row = new Object[0];
listener.rowReadEvent(rmi, row);
}
use of org.pentaho.di.trans.step.BaseStep in project pentaho-kettle by pentaho.
the class BaseStepConcurrencyTest method testInputOutputRowSets.
/**
* Row sets collection modifiers are exposed out of BaseStep class,
* whereas the collection traversal is happening on every row being processed.
*
* We should be sure that modification of the collection will not throw a concurrent modification exception.
*/
@Test
public void testInputOutputRowSets() throws Exception {
int modifiersAmount = 100;
int traversersAmount = 100;
StepMeta stepMeta = mock(StepMeta.class);
TransMeta transMeta = mock(TransMeta.class);
when(stepMeta.getName()).thenReturn(STEP_META);
when(transMeta.findStep(STEP_META)).thenReturn(stepMeta);
when(stepMeta.getTargetStepPartitioningMeta()).thenReturn(mock(StepPartitioningMeta.class));
baseStep = new BaseStep(stepMeta, null, 0, transMeta, mock(Trans.class));
AtomicBoolean condition = new AtomicBoolean(true);
List<RowSetsModifier> rowSetsModifiers = new ArrayList<>();
for (int i = 0; i < modifiersAmount; i++) {
rowSetsModifiers.add(new RowSetsModifier(condition));
}
List<RowSetsTraverser> rowSetsTraversers = new ArrayList<>();
for (int i = 0; i < traversersAmount; i++) {
rowSetsTraversers.add(new RowSetsTraverser(condition));
}
ConcurrencyTestRunner<?, ?> runner = new ConcurrencyTestRunner<Object, Object>(rowSetsModifiers, rowSetsTraversers, condition);
runner.runConcurrentTest();
runner.checkNoExceptionRaised();
}
use of org.pentaho.di.trans.step.BaseStep in project pentaho-kettle by pentaho.
the class Trans method startThreads.
/**
* Starts the threads prepared by prepareThreads(). Before you start the threads, you can add RowListeners to them.
*
* @throws KettleException
* if there is a communication error with a remote output socket.
*/
public void startThreads() throws KettleException {
// Now prepare to start all the threads...
//
nrOfFinishedSteps = 0;
nrOfActiveSteps = 0;
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationStartThreads.id, this);
fireTransStartedListeners();
for (int i = 0; i < steps.size(); i++) {
final StepMetaDataCombi sid = steps.get(i);
sid.step.markStart();
sid.step.initBeforeStart();
// also attach a Step Listener to detect when we're done...
//
StepListener stepListener = new StepListener() {
@Override
public void stepActive(Trans trans, StepMeta stepMeta, StepInterface step) {
nrOfActiveSteps++;
if (nrOfActiveSteps == 1) {
// PDI-5229 sync added
synchronized (transListeners) {
for (TransListener listener : transListeners) {
listener.transActive(Trans.this);
}
}
}
}
@Override
public void stepFinished(Trans trans, StepMeta stepMeta, StepInterface step) {
synchronized (Trans.this) {
nrOfFinishedSteps++;
if (nrOfFinishedSteps >= steps.size()) {
// Set the finished flag
//
setFinished(true);
// Grab the performance statistics one last time (if enabled)
//
addStepPerformanceSnapShot();
try {
fireTransFinishedListeners();
} catch (Exception e) {
step.setErrors(step.getErrors() + 1L);
log.logError(getName() + " : " + BaseMessages.getString(PKG, "Trans.Log.UnexpectedErrorAtTransformationEnd"), e);
}
}
//
if (step.getErrors() > 0) {
log.logMinimal(BaseMessages.getString(PKG, "Trans.Log.TransformationDetectedErrors"));
log.logMinimal(BaseMessages.getString(PKG, "Trans.Log.TransformationIsKillingTheOtherSteps"));
killAllNoWait();
}
}
}
};
//
if (sid.step instanceof BaseStep) {
((BaseStep) sid.step).getStepListeners().add(0, stepListener);
} else {
sid.step.addStepListener(stepListener);
}
}
if (transMeta.isCapturingStepPerformanceSnapShots()) {
stepPerformanceSnapshotSeqNr = new AtomicInteger(0);
stepPerformanceSnapShots = new ConcurrentHashMap<>();
// Calculate the maximum number of snapshots to be kept in memory
//
String limitString = environmentSubstitute(transMeta.getStepPerformanceCapturingSizeLimit());
if (Utils.isEmpty(limitString)) {
limitString = EnvUtil.getSystemProperty(Const.KETTLE_STEP_PERFORMANCE_SNAPSHOT_LIMIT);
}
stepPerformanceSnapshotSizeLimit = Const.toInt(limitString, 0);
// Set a timer to collect the performance data from the running threads...
//
stepPerformanceSnapShotTimer = new Timer("stepPerformanceSnapShot Timer: " + transMeta.getName());
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
if (!isFinished()) {
addStepPerformanceSnapShot();
}
}
};
stepPerformanceSnapShotTimer.schedule(timerTask, 100, transMeta.getStepPerformanceCapturingDelay());
}
// Now start a thread to monitor the running transformation...
//
setFinished(false);
setPaused(false);
setStopped(false);
transFinishedBlockingQueue = new ArrayBlockingQueue<>(10);
TransListener transListener = new TransAdapter() {
@Override
public void transFinished(Trans trans) {
try {
shutdownHeartbeat(trans != null ? trans.heartbeat : null);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationFinish.id, trans);
} catch (KettleException e) {
throw new RuntimeException("Error calling extension point at end of transformation", e);
}
//
if (transMeta.isCapturingStepPerformanceSnapShots() && stepPerformanceSnapShotTimer != null) {
stepPerformanceSnapShotTimer.cancel();
}
transMeta.disposeEmbeddedMetastoreProvider();
setFinished(true);
// no longer running
setRunning(false);
log.snap(Metrics.METRIC_TRANSFORMATION_EXECUTION_STOP);
// If the user ran with metrics gathering enabled and a metrics logging table is configured, add another
// listener...
//
MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
if (metricsLogTable.isDefined()) {
try {
writeMetricsInformation();
} catch (Exception e) {
log.logError("Error writing metrics information", e);
errors.incrementAndGet();
}
}
//
if (transMeta.isUsingUniqueConnections()) {
trans.closeUniqueDatabaseConnections(getResult());
}
// release unused vfs connections
KettleVFS.freeUnusedResources();
}
};
// This should always be done first so that the other listeners achieve a clean state to start from (setFinished and
// so on)
//
transListeners.add(0, transListener);
setRunning(true);
switch(transMeta.getTransformationType()) {
case Normal:
//
for (int i = 0; i < steps.size(); i++) {
final StepMetaDataCombi combi = steps.get(i);
RunThread runThread = new RunThread(combi);
Thread thread = new Thread(runThread);
thread.setName(getName() + " - " + combi.stepname);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.StepBeforeStart.id, combi);
// Call an extension point at the end of the step
//
combi.step.addStepListener(new StepAdapter() {
@Override
public void stepFinished(Trans trans, StepMeta stepMeta, StepInterface step) {
try {
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.StepFinished.id, combi);
} catch (KettleException e) {
throw new RuntimeException("Unexpected error in calling extension point upon step finish", e);
}
}
});
thread.start();
}
break;
case SerialSingleThreaded:
new Thread(new Runnable() {
@Override
public void run() {
try {
//
for (StepMetaDataCombi combi : steps) {
combi.step.setUsingThreadPriorityManagment(false);
}
//
// This is a single threaded version...
//
// Sort the steps from start to finish...
//
Collections.sort(steps, new Comparator<StepMetaDataCombi>() {
@Override
public int compare(StepMetaDataCombi c1, StepMetaDataCombi c2) {
boolean c1BeforeC2 = transMeta.findPrevious(c2.stepMeta, c1.stepMeta);
if (c1BeforeC2) {
return -1;
} else {
return 1;
}
}
});
boolean[] stepDone = new boolean[steps.size()];
int nrDone = 0;
while (nrDone < steps.size() && !isStopped()) {
for (int i = 0; i < steps.size() && !isStopped(); i++) {
StepMetaDataCombi combi = steps.get(i);
if (!stepDone[i]) {
// if (combi.step.canProcessOneRow() ||
// !combi.step.isRunning()) {
boolean cont = combi.step.processRow(combi.meta, combi.data);
if (!cont) {
stepDone[i] = true;
nrDone++;
}
// }
}
}
}
} catch (Exception e) {
errors.addAndGet(1);
log.logError("Error executing single threaded", e);
} finally {
for (int i = 0; i < steps.size(); i++) {
StepMetaDataCombi combi = steps.get(i);
combi.step.dispose(combi.meta, combi.data);
combi.step.markStop();
}
}
}
}).start();
break;
case SingleThreaded:
//
break;
default:
break;
}
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationStart.id, this);
heartbeat = startHeartbeat(getHeartbeatIntervalInSeconds());
if (steps.isEmpty()) {
fireTransFinishedListeners();
}
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.TransformationHasAllocated", String.valueOf(steps.size()), String.valueOf(rowsets.size())));
}
}
use of org.pentaho.di.trans.step.BaseStep in project pentaho-kettle by pentaho.
the class IngresVectorwiseTest method testGuiErrorsWithErrorsAllowed.
@Test
public void testGuiErrorsWithErrorsAllowed() {
try {
int r = wrongRows.size();
BaseStep step = doOutput(wrongRows, "2");
((IngresVectorwiseLoader) step).vwLoadMonitorThread.join();
assertEquals(r - 1, step.getLinesOutput());
assertEquals(r, step.getLinesRead());
assertEquals(r, step.getLinesWritten());
assertEquals(1, step.getLinesRejected());
assertEquals(0, step.getErrors());
} catch (KettleException e) {
fail(e.getMessage());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of org.pentaho.di.trans.step.BaseStep in project pentaho-kettle by pentaho.
the class IngresVectorwiseTest method testGuiErrors.
@Test
public void testGuiErrors() {
try {
int r = wrongRows.size();
BaseStep step = doOutput(wrongRows, "0");
((IngresVectorwiseLoader) step).vwLoadMonitorThread.join();
assertEquals(0, step.getLinesOutput());
assertEquals(r, step.getLinesRead());
assertEquals(r, step.getLinesWritten());
assertEquals(1, step.getLinesRejected());
assertEquals(1, step.getErrors());
} catch (KettleException e) {
fail(e.getMessage());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Aggregations