use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class ServiceCacheTest method testReplay.
@Test
public void testReplay() throws Exception {
DataServiceExecutor executor = dataServiceExecutor("SELECT * FROM MOCK_SERVICE WHERE A = 2");
CachedService.CacheKey key = CachedService.CacheKey.create(executor);
CachedService cachedService = mock(CachedService.class);
CachedServiceLoader cachedServiceLoader = mock(CachedServiceLoader.class);
when(cache.get(key)).thenReturn(cachedService);
when(cachedService.answersQuery(executor)).thenReturn(true);
when(factory.createCachedServiceLoader(cachedService)).thenReturn(cachedServiceLoader);
when(cachedServiceLoader.replay(executor)).thenReturn(Futures.immediateFuture(2000));
assertThat(serviceCache.activate(executor, serviceStep), is(true));
verify(cachedServiceLoader).replay(executor);
}
use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class ServiceCacheTest method testTimeToLiveCacheInvalid.
@Test
public void testTimeToLiveCacheInvalid() throws KettleException {
DataServiceExecutor executor = dataServiceExecutor("SELECT * FROM MOCK_SERVICE");
// TTL of service cache != template config
serviceCache.setTimeToLive("1010");
CachedService.CacheKey key = CachedService.CacheKey.create(executor);
CachedService existingCache = mock(CachedService.class);
when(cache.get(key)).thenReturn(existingCache);
when(existingCache.answersQuery(executor)).thenReturn(true);
assertThat(serviceCache.getAvailableCache(executor).size(), is(0));
}
use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceTestController method getNewDataServiceExecutor.
protected DataServiceExecutor getNewDataServiceExecutor(boolean enableMetrics) throws KettleException {
try {
resetVariablesAndParameters();
DataServiceExecutor.Builder builder;
if (dataService.isStreaming()) {
builder = new DataServiceExecutor.Builder(new SQL(model.getSql()), dataService, context).rowLimit(dataService.getRowLimit()).timeLimit(dataService.getTimeLimit()).logLevel(model.getLogLevel()).enableMetrics(enableMetrics).windowMode(model.getWindowMode()).windowSize(model.getWindowSize()).windowEvery(model.getWindowEvery()).windowLimit(model.getWindowLimit());
} else {
builder = new DataServiceExecutor.Builder(new SQL(model.getSql()), dataService, context).rowLimit(model.getMaxRows()).logLevel(model.getLogLevel()).enableMetrics(enableMetrics);
}
return builder.build();
} catch (KettleException e) {
model.setAlertMessage(e.getMessage());
throw e;
}
}
use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceTestController method previewQueries.
// Bound via XUL
@SuppressWarnings("unused")
public void previewQueries() throws KettleException {
DataServiceExecutor dataServiceExec = getNewDataServiceExecutor(false);
updateOptimizationImpact(dataServiceExec);
}
use of org.pentaho.di.trans.dataservice.DataServiceExecutor in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceRealTest method testServiceTransKeepsRunningWhenDataServiceIsNotUserDefined.
@Test
public void testServiceTransKeepsRunningWhenDataServiceIsNotUserDefined() throws Exception {
TransMeta transMeta = new TransMeta(getClass().getResource("/GenerateOneMillion.ktr").getPath());
DataServiceMeta dataServiceMeta = new DataServiceMeta(transMeta);
dataServiceMeta.setName("table");
dataServiceMeta.setStepname("Delay Row");
dataServiceMeta.setUserDefined(false);
PentahoCacheSystemConfiguration systemConfiguration = new PentahoCacheSystemConfiguration();
systemConfiguration.setData(new HashMap<>());
PentahoCacheManagerImpl pentahoCacheManager = new PentahoCacheManagerImpl(systemConfiguration, new HeapCacheProvidingService());
ServiceCacheFactory cacheFactory = new ServiceCacheFactory(pentahoCacheManager, Executors.newSingleThreadExecutor());
DataServiceContext dataServiceContext = new DataServiceContext(singletonList(cacheFactory), emptyList(), pentahoCacheManager, new UIFactory(), new LogChannel(""));
SQL countSql = new SQL("select count(*) from table");
DataServiceExecutor countExecutor = new DataServiceExecutor.Builder(countSql, dataServiceMeta, dataServiceContext).build();
countExecutor.executeQuery();
SQL limitSql = new SQL("select field1,field2 from table limit 5");
DataServiceExecutor limitExecutor = new DataServiceExecutor.Builder(limitSql, dataServiceMeta, dataServiceContext).build();
limitExecutor.executeQuery();
limitExecutor.waitUntilFinished();
assertTrue(countExecutor.getGenTrans().isRunning());
assertTrue(countExecutor.getServiceTrans().isRunning());
countExecutor.getServiceTrans().stopAll();
}
Aggregations