use of org.pentaho.di.trans.step.StepInterface in project pentaho-kettle by pentaho.
the class CheckSumTest method executeHexTest.
/**
* Create, execute, and return the row listener attached to the output step with complete results from the execution.
*
* @param checkSumType
* Type of checksum to use (the array index of {@link CheckSumMeta#checksumtypeCodes})
* @param compatibilityMode
* Use compatibility mode for CheckSum
* @param input
* String to calculate checksum for
* @param meta
* meta to be used
* @return RowListener with results.
*/
private MockRowListener executeHexTest(int checkSumType, boolean compatibilityMode, Object input, ValueMetaInterface meta, boolean oldChecksumBehaviour) throws Exception {
Trans trans = buildHexadecimalChecksumTrans(checkSumType, compatibilityMode, oldChecksumBehaviour);
trans.prepareExecution(null);
StepInterface output = trans.getRunThread("Output", 0);
MockRowListener listener = new MockRowListener();
output.addRowListener(listener);
RowProducer rp = trans.addRowProducer("CheckSum", 0);
RowMeta inputRowMeta = createStringRowMeta(meta);
((BaseStep) trans.getRunThread("CheckSum", 0)).setInputRowMeta(inputRowMeta);
trans.startThreads();
rp.putRow(inputRowMeta, new Object[] { input });
rp.finished();
trans.waitUntilFinished();
trans.stopAll();
trans.cleanup();
return listener;
}
use of org.pentaho.di.trans.step.StepInterface in project pdi-dataservice-server-plugin by pentaho.
the class DefaultTransWiring method run.
@Override
public void run() {
// This is where we will inject the rows from the service transformation step
//
final RowProducer rowProducer;
final Trans serviceTrans = dataServiceExecutor.getServiceTrans();
final Trans genTrans = dataServiceExecutor.getGenTrans();
try {
rowProducer = dataServiceExecutor.addRowProducer();
} catch (KettleException e) {
throw Throwables.propagate(e);
}
// Now connect the 2 transformations with listeners and injector
//
StepInterface serviceStep = serviceTrans.findRunThread(dataServiceExecutor.getService().getStepname());
if (serviceStep == null) {
throw Throwables.propagate(new KettleException("Service step is not accessible"));
}
serviceStep.addRowListener(new DefaultTransWiringRowAdapter(serviceTrans, genTrans, rowProducer));
// Let the other transformation know when there are no more rows
//
serviceStep.addStepListener(new StepAdapter() {
@Override
public void stepFinished(Trans trans, StepMeta stepMeta, StepInterface step) {
rowProducer.finished();
}
});
dataServiceExecutor.getGenTrans().findRunThread(dataServiceExecutor.getResultStepName()).addStepListener(new StepAdapter() {
@Override
public void stepFinished(Trans trans, StepMeta stepMeta, StepInterface step) {
if (serviceTrans.isRunning()) {
trans.getLogChannel().logBasic("Query finished, stopping service transformation");
serviceTrans.stopAll();
}
}
});
}
use of org.pentaho.di.trans.step.StepInterface in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceExecutorTest method testExecuteQueryNoResults.
@Test
public void testExecuteQueryNoResults() throws Exception {
SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
StepInterface serviceStep = serviceTrans.findRunThread(DATA_SERVICE_STEP);
StepInterface resultStep = genTrans.findRunThread(RESULT_STEP_NAME);
when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
PushDownOptimizationMeta optimization = mock(PushDownOptimizationMeta.class);
when(optimization.isEnabled()).thenReturn(true);
dataService.getPushDownOptimizationMeta().add(optimization);
IMetaStore metastore = mock(IMetaStore.class);
DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).build();
ArgumentCaptor<String> objectIds = ArgumentCaptor.forClass(String.class);
verify(serviceTrans).setContainerObjectId(objectIds.capture());
when(serviceTrans.getContainerObjectId()).thenReturn(objectIds.getValue());
verify(genTrans).setContainerObjectId(objectIds.capture());
when(genTrans.getContainerObjectId()).thenReturn(objectIds.getValue());
verify(serviceTrans).setMetaStore(metastore);
verify(genTrans).setMetaStore(metastore);
RowProducer sqlTransRowProducer = mock(RowProducer.class);
when(genTrans.addRowProducer(INJECTOR_STEP_NAME, 0)).thenReturn(sqlTransRowProducer);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Start Execution
executor.executeQuery(new DataOutputStream(outputStream));
// Check header was written
assertThat(outputStream.size(), greaterThan(0));
outputStream.reset();
InOrder genTransStartup = inOrder(genTrans, resultStep);
InOrder serviceTransStartup = inOrder(optimization, serviceTrans, serviceStep);
ArgumentCaptor<RowListener> listenerArgumentCaptor = ArgumentCaptor.forClass(RowListener.class);
ArgumentCaptor<StepListener> resultStepListener = ArgumentCaptor.forClass(StepListener.class);
ArgumentCaptor<TransListener> transListenerCaptor = ArgumentCaptor.forClass(TransListener.class);
genTransStartup.verify(genTrans).addTransListener(transListenerCaptor.capture());
genTransStartup.verify(genTrans).addRowProducer(INJECTOR_STEP_NAME, 0);
genTransStartup.verify(resultStep).addStepListener(resultStepListener.capture());
genTransStartup.verify(resultStep).addRowListener(listenerArgumentCaptor.capture());
RowListener clientRowListener = listenerArgumentCaptor.getValue();
genTransStartup.verify(genTrans).startThreads();
serviceTransStartup.verify(optimization).activate(executor);
serviceTransStartup.verify(serviceStep).addRowListener(listenerArgumentCaptor.capture());
serviceTransStartup.verify(serviceTrans).startThreads();
// Verify linkage
RowListener serviceRowListener = listenerArgumentCaptor.getValue();
assertNotNull(serviceRowListener);
// Push row from service to sql Trans
RowMetaInterface rowMeta = genTrans.getTransMeta().getStepFields(RESULT_STEP_NAME);
doReturn(true).when(serviceTrans).isRunning();
resultStepListener.getValue().stepFinished(genTrans, resultStep.getStepMeta(), resultStep);
verify(serviceTrans).stopAll();
// Verify Service Trans finished
ArgumentCaptor<StepListener> serviceStepListener = ArgumentCaptor.forClass(StepListener.class);
verify(serviceStep).addStepListener(serviceStepListener.capture());
serviceStepListener.getValue().stepFinished(serviceTrans, serviceStep.getStepMeta(), serviceStep);
verify(sqlTransRowProducer).finished();
// finish transformation, so that the listener runs
transListenerCaptor.getValue().transFinished(genTrans);
InOrder writeRows = inOrder(rowMeta);
ArgumentCaptor<DataOutputStream> streamCaptor = ArgumentCaptor.forClass(DataOutputStream.class);
writeRows.verify(rowMeta).writeMeta(streamCaptor.capture());
DataOutputStream dataOutputStream = streamCaptor.getValue();
writeRows.verify(rowMeta, times(0)).writeData(same(dataOutputStream), argThat(arrayWithSize(1)));
writeRows.verifyNoMoreInteractions();
executor.waitUntilFinished();
verify(serviceTrans).waitUntilFinished();
verify(genTrans).waitUntilFinished();
}
use of org.pentaho.di.trans.step.StepInterface in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceExecutorTest method testExecuteQuery.
@Test
public void testExecuteQuery() throws Exception {
SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
StepInterface serviceStep = serviceTrans.findRunThread(DATA_SERVICE_STEP);
StepInterface resultStep = genTrans.findRunThread(RESULT_STEP_NAME);
when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
PushDownOptimizationMeta optimization = mock(PushDownOptimizationMeta.class);
when(optimization.isEnabled()).thenReturn(true);
dataService.getPushDownOptimizationMeta().add(optimization);
IMetaStore metastore = mock(IMetaStore.class);
DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).build();
ArgumentCaptor<String> objectIds = ArgumentCaptor.forClass(String.class);
verify(serviceTrans).setContainerObjectId(objectIds.capture());
when(serviceTrans.getContainerObjectId()).thenReturn(objectIds.getValue());
verify(genTrans).setContainerObjectId(objectIds.capture());
when(genTrans.getContainerObjectId()).thenReturn(objectIds.getValue());
verify(serviceTrans).setMetaStore(metastore);
verify(genTrans).setMetaStore(metastore);
RowProducer sqlTransRowProducer = mock(RowProducer.class);
when(genTrans.addRowProducer(INJECTOR_STEP_NAME, 0)).thenReturn(sqlTransRowProducer);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Start Execution
executor.executeQuery(new DataOutputStream(outputStream));
// Check header was written
assertThat(outputStream.size(), greaterThan(0));
outputStream.reset();
InOrder genTransStartup = inOrder(genTrans, resultStep);
InOrder serviceTransStartup = inOrder(optimization, serviceTrans, serviceStep);
ArgumentCaptor<RowListener> listenerArgumentCaptor = ArgumentCaptor.forClass(RowListener.class);
ArgumentCaptor<StepListener> resultStepListener = ArgumentCaptor.forClass(StepListener.class);
ArgumentCaptor<TransListener> transListenerCaptor = ArgumentCaptor.forClass(TransListener.class);
genTransStartup.verify(genTrans).addTransListener(transListenerCaptor.capture());
genTransStartup.verify(genTrans).addRowProducer(INJECTOR_STEP_NAME, 0);
genTransStartup.verify(resultStep).addStepListener(resultStepListener.capture());
genTransStartup.verify(resultStep).addRowListener(listenerArgumentCaptor.capture());
RowListener clientRowListener = listenerArgumentCaptor.getValue();
genTransStartup.verify(genTrans).startThreads();
serviceTransStartup.verify(optimization).activate(executor);
serviceTransStartup.verify(serviceStep).addRowListener(listenerArgumentCaptor.capture());
serviceTransStartup.verify(serviceTrans).startThreads();
// Verify linkage
RowListener serviceRowListener = listenerArgumentCaptor.getValue();
assertNotNull(serviceRowListener);
// Push row from service to sql Trans
RowMetaInterface rowMeta = genTrans.getTransMeta().getStepFields(RESULT_STEP_NAME);
Object[] data;
for (int i = 0; i < 50; i++) {
data = new Object[] { i };
Object[] dataClone = { i };
when(rowMeta.cloneRow(data)).thenReturn(dataClone);
serviceRowListener.rowWrittenEvent(rowMeta, data);
verify(sqlTransRowProducer).putRowWait(same(rowMeta), and(eq(dataClone), not(same(data))), any(Long.class), any(TimeUnit.class));
verify(rowMeta).cloneRow(data);
}
doReturn(true).when(serviceTrans).isRunning();
resultStepListener.getValue().stepFinished(genTrans, resultStep.getStepMeta(), resultStep);
verify(serviceTrans).stopAll();
// Verify Service Trans finished
ArgumentCaptor<StepListener> serviceStepListener = ArgumentCaptor.forClass(StepListener.class);
verify(serviceStep).addStepListener(serviceStepListener.capture());
serviceStepListener.getValue().stepFinished(serviceTrans, serviceStep.getStepMeta(), serviceStep);
verify(sqlTransRowProducer).finished();
// Push row from service to sql Trans
for (int i = 0; i < 50; i++) {
Object[] row = { i };
clientRowListener.rowWrittenEvent(rowMeta, row);
}
transListenerCaptor.getValue().transFinished(genTrans);
InOrder writeRows = inOrder(rowMeta);
ArgumentCaptor<DataOutputStream> streamCaptor = ArgumentCaptor.forClass(DataOutputStream.class);
writeRows.verify(rowMeta).writeMeta(streamCaptor.capture());
DataOutputStream dataOutputStream = streamCaptor.getValue();
writeRows.verify(rowMeta, times(50)).writeData(same(dataOutputStream), argThat(arrayWithSize(1)));
writeRows.verifyNoMoreInteractions();
executor.waitUntilFinished();
verify(serviceTrans).waitUntilFinished();
verify(genTrans).waitUntilFinished();
}
use of org.pentaho.di.trans.step.StepInterface in project pdi-dataservice-server-plugin by pentaho.
the class TableInputParameterGenerationTest method testFailures.
@Test
public void testFailures() throws Exception {
// Throw exception if type is not TableInput
try {
service.pushDown(mock(Condition.class), mock(ParameterGeneration.class), mock(StepInterface.class));
fail();
} catch (PushDownOptimizationException thrown) {
assertThat(thrown.getMessage(), notNullValue());
}
// Throw exception if connection fails
KettleDatabaseException expected = new KettleDatabaseException();
data.db = mock(DatabaseWrapper.class);
doThrow(expected).when(data.db).connect();
try {
service.pushDown(mock(Condition.class), mock(ParameterGeneration.class), stepInterface);
fail();
} catch (PushDownOptimizationException thrown) {
assertThat(thrown.getCause(), equalTo((Throwable) expected));
}
}
Aggregations