Search in sources :

Example 6 with DataServiceContext

use of org.pentaho.di.trans.dataservice.DataServiceContext 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)

Example 7 with DataServiceContext

use of org.pentaho.di.trans.dataservice.DataServiceContext in project pdi-dataservice-server-plugin by pentaho.

the class AnnotationsQueryServiceTest method testLogsExceptionOnWriteEror.

@Test
public void testLogsExceptionOnWriteEror() throws Exception {
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    Query query = queryService.prepareQuery("show annotations from annotatedService", 0, Collections.<String, String>emptyMap());
    MetaStoreException metaStoreException = new MetaStoreException("Unable to load dataservice annotatedService");
    when(dataServiceResolver.getDataService("annotatedService")).thenReturn(null);
    try {
        query.writeTo(new ByteArrayOutputStream());
        fail("should have got exception");
    } catch (IOException e) {
        assertEquals("Error while executing 'show annotations from annotatedService'", e.getMessage());
    }
}
Also used : DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with DataServiceContext

use of org.pentaho.di.trans.dataservice.DataServiceContext in project pdi-dataservice-server-plugin by pentaho.

the class ExecutorQueryServiceTest method testQueryBuildsWithMetastore.

@Test
public void testQueryBuildsWithMetastore() throws Exception {
    final DataServiceFactory factory = mock(DataServiceFactory.class);
    final DataServiceContext context = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final DataServiceExecutor dataServiceExecutor = mock(DataServiceExecutor.class);
    final Trans serviceTrans = mock(Trans.class);
    final Trans genTrans = mock(Trans.class);
    when(context.getMetaStoreUtil()).thenReturn(factory);
    DataServiceExecutor.Builder builder = mock(DataServiceExecutor.Builder.class);
    final IMetaStore metastore = mock(IMetaStore.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(metastoreLocator.getMetastore()).thenReturn(metastore);
    SQL sql = new SQL("select field from table");
    HashMap<String, String> parameters = new HashMap<>();
    int rowLimit = 5432;
    ExecutorQueryService executorQueryService = new ExecutorQueryService(dataServiceResolver, metastoreLocator);
    when(dataServiceResolver.createBuilder(argThat(matchesSql(sql)))).thenReturn(builder);
    when(factory.getMetaStore()).thenReturn(metastore);
    when(builder.rowLimit(rowLimit)).thenReturn(builder);
    when(builder.parameters(parameters)).thenReturn(builder);
    when(builder.metastore(metastore)).thenReturn(builder);
    when(builder.windowMode(null)).thenReturn(builder);
    when(builder.windowSize(0)).thenReturn(builder);
    when(builder.windowEvery(0)).thenReturn(builder);
    when(builder.windowLimit(0)).thenReturn(builder);
    when(builder.build()).thenReturn(dataServiceExecutor);
    when(dataServiceExecutor.getServiceTrans()).thenReturn(serviceTrans);
    when(dataServiceExecutor.getGenTrans()).thenReturn(genTrans);
    Query result = executorQueryService.prepareQuery(sql.getSqlString(), rowLimit, parameters);
    assertEquals(ImmutableList.of(serviceTrans, genTrans), result.getTransList());
    verify(builder).rowLimit(rowLimit);
    verify(builder).parameters(parameters);
    verify(builder).metastore(metastore);
}
Also used : HashMap(java.util.HashMap) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceFactory(org.pentaho.di.trans.dataservice.serialization.DataServiceFactory) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 9 with DataServiceContext

use of org.pentaho.di.trans.dataservice.DataServiceContext in project pdi-dataservice-server-plugin by pentaho.

the class TransOpenedExtensionPointPluginTest method setUp.

@Before
public void setUp() throws Exception {
    DataServiceContext context = mock(DataServiceContext.class);
    DataServiceDelegate delegate = mock(DataServiceDelegate.class);
    when(context.getDataServiceDelegate()).thenReturn(delegate);
    when(delegate.createSyncService()).thenReturn(service);
    extensionPointPlugin = new TransOpenedExtensionPointPlugin(context);
}
Also used : DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) Before(org.junit.Before)

Aggregations

DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)9 Test (org.junit.Test)8 TransMeta (org.pentaho.di.trans.TransMeta)6 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)6 DataServiceResolver (org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver)6 DataServiceDelegate (org.pentaho.di.trans.dataservice.ui.DataServiceDelegate)6 MetastoreLocator (org.pentaho.osgi.metastore.locator.api.MetastoreLocator)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 ModelAnnotationGroup (org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 URL (java.net.URL)2 CreateAttribute (org.pentaho.agilebi.modeler.models.annotations.CreateAttribute)2 SQL (org.pentaho.di.core.sql.SQL)2 Trans (org.pentaho.di.trans.Trans)2 TransHopMeta (org.pentaho.di.trans.TransHopMeta)2 DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)2 Document (org.w3c.dom.Document)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1