Search in sources :

Example 11 with DataServiceExecutor

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);
}
Also used : DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Test(org.junit.Test)

Example 12 with DataServiceExecutor

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));
}
Also used : DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Test(org.junit.Test)

Example 13 with DataServiceExecutor

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;
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) SQL(org.pentaho.di.core.sql.SQL)

Example 14 with DataServiceExecutor

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);
}
Also used : DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor)

Example 15 with DataServiceExecutor

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();
}
Also used : HeapCacheProvidingService(org.pentaho.caching.ri.HeapCacheProvidingService) UIFactory(org.pentaho.di.trans.dataservice.ui.UIFactory) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) TransMeta(org.pentaho.di.trans.TransMeta) LogChannel(org.pentaho.di.core.logging.LogChannel) ServiceCacheFactory(org.pentaho.di.trans.dataservice.optimization.cache.ServiceCacheFactory) SQL(org.pentaho.di.core.sql.SQL) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) PentahoCacheManagerImpl(org.pentaho.caching.impl.PentahoCacheManagerImpl) PentahoCacheSystemConfiguration(org.pentaho.caching.api.PentahoCacheSystemConfiguration) Test(org.junit.Test)

Aggregations

DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)23 Test (org.junit.Test)19 SQL (org.pentaho.di.core.sql.SQL)6 HashMap (java.util.HashMap)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 KettleException (org.pentaho.di.core.exception.KettleException)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 StepListener (org.pentaho.di.trans.step.StepListener)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 IMetaStore (org.pentaho.metastore.api.IMetaStore)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Executor (java.util.concurrent.Executor)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)2 RowProducer (org.pentaho.di.trans.RowProducer)2 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)2