use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class ExecutorQueryService method prepareQuery.
@Override
public Query prepareQuery(String sqlString, IDataServiceClientService.StreamingMode windowMode, long windowSize, long windowEvery, long windowLimit, final Map<String, String> parameters) throws KettleException {
SQL sql = new SQL(sqlString);
Query query;
try {
IMetaStore metaStore = metastoreLocator != null ? metastoreLocator.getMetastore() : null;
DataServiceExecutor executor = resolver.createBuilder(sql).rowLimit(0).windowMode(windowMode).windowSize(windowSize).windowEvery(windowEvery).windowLimit(windowLimit).parameters(parameters).metastore(metaStore).build();
query = new ExecutorQuery(executor);
} catch (Exception e) {
Throwables.propagateIfInstanceOf(e, KettleException.class);
throw new KettleException(e);
}
return query;
}
use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class ExecutorQueryService method prepareQuery.
@Override
public Query prepareQuery(String sqlString, int maxRows, Map<String, String> parameters) throws KettleException {
SQL sql = new SQL(sqlString);
Query query;
try {
IMetaStore metaStore = metastoreLocator != null ? metastoreLocator.getMetastore() : null;
DataServiceExecutor executor = resolver.createBuilder(sql).rowLimit(maxRows).parameters(parameters).metastore(metaStore).build();
query = new ExecutorQuery(executor);
} catch (Exception e) {
Throwables.propagateIfInstanceOf(e, KettleException.class);
throw new KettleException(e);
}
return query;
}
use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class TransientResolverTest method testBuilderPassesLogLevel.
@Test
public void testBuilderPassesLogLevel() throws Exception {
File localFolder = temporaryFolder.newFolder("local");
File localFile = new File(localFolder, "name.ktr");
Files.write(transMeta.getXML().getBytes(StandardCharsets.UTF_8), localFile);
String transientId = TransientResolver.buildTransient(localFile.getPath(), "OUTPUT");
when(repository.getTransformationID(any(), eq(root))).thenThrow(new KettleException());
DataServiceExecutor.Builder builder = transientResolver.createBuilder(new SQL("select * from " + transientId));
DataServiceExecutor build = builder.build();
assertEquals(LogLevel.DEBUG, build.getServiceTransMeta().getLogLevel());
}
use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class CachedServiceTest method testReplayFullCache.
@Test
public void testReplayFullCache() throws Exception {
DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY);
CachedService cachedService = CachedService.complete(testData);
RowProducer rowProducer = genTrans.addRowProducer(INJECTOR_STEP, 0);
// Activate cachedServiceLoader
Executor mockExecutor = mock(Executor.class);
final CachedServiceLoader cachedServiceLoader = new CachedServiceLoader(cachedService, mockExecutor);
ListenableFuture<Integer> replay = cachedServiceLoader.replay(executor);
ArgumentCaptor<Runnable> replayRunnable = ArgumentCaptor.forClass(Runnable.class);
verify(mockExecutor).execute(replayRunnable.capture());
stepMetaDataCombi.step = inputStep;
stepMetaDataCombi.meta = inputStepMetaInterface;
stepMetaDataCombi.data = inputStepDataInterface;
List<StepMetaDataCombi> stepMetaDataCombis = new ArrayList<>();
stepMetaDataCombis.add(stepMetaDataCombi);
when(serviceTrans.getSteps()).thenReturn(stepMetaDataCombis);
// Simulate executing data service
executor.executeListeners(DataServiceExecutor.ExecutionPoint.READY);
executor.executeListeners(DataServiceExecutor.ExecutionPoint.START);
// Verify that serviceTrans never started, genTrans is accepting rows
verify(serviceTrans).stopAll();
verify(inputStep).setOutputDone();
verify(inputStep).dispose(inputStepMetaInterface, inputStepDataInterface);
verify(inputStep).markStop();
verify(serviceTrans, never()).startThreads();
verify(genTrans).startThreads();
when(rowProducer.putRowWait(any(RowMetaInterface.class), any(Object[].class), anyInt(), any(TimeUnit.class))).then(new Answer<Boolean>() {
int calls = 0;
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
// Simulate full row set on tenth call
return ++calls != 10;
}
});
when(genTrans.isRunning()).thenReturn(true);
// Run cache loader (would be asynchronous)
replayRunnable.getValue().run();
assertThat(replay.get(1, TimeUnit.SECONDS), equalTo(testData.size()));
InOrder rowsProduced = inOrder(rowProducer);
for (int i = 0; i < testData.size(); i++) {
RowMetaAndData metaAndData = testData.get(i);
// Tenth row was called twice, since row set was full
Object[] data = metaAndData.getData();
rowsProduced.verify(rowProducer, times(i == 9 ? 2 : 1)).putRowWait(eq(metaAndData.getRowMeta()), and(eq(data), AdditionalMatchers.not(same(data))), anyInt(), any(TimeUnit.class));
}
rowsProduced.verify(rowProducer).finished();
rowsProduced.verifyNoMoreInteractions();
}
use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class CachedServiceTest method testObserveCancelled.
@Test
public void testObserveCancelled() throws Exception {
DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY);
ServiceObserver observer = new ServiceObserver(executor);
observer.install();
assertThat(executor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.READY), hasItem(observer));
ListenableFuture<CachedService> failedObserver = new ServiceObserver(executor).install();
try {
failedObserver.get(1, TimeUnit.SECONDS);
fail("Expecting an IllegalStateException");
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
}
assertThat(observer.isDone(), is(false));
ArgumentCaptor<StepListener> stepListener = ArgumentCaptor.forClass(StepListener.class);
observer.run();
verify(serviceStep).addStepListener(stepListener.capture());
when(genTrans.getErrors()).thenReturn(1);
stepListener.getValue().stepFinished(serviceTrans, mock(StepMeta.class), serviceStep);
try {
observer.get(1, TimeUnit.SECONDS);
fail("Expecting an KettleException");
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(KettleException.class));
}
}
Aggregations