Search in sources :

Example 16 with DataServiceExecutor

use of org.pentaho.di.trans.dataservice.DataServiceExecutor 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 17 with DataServiceExecutor

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

the class CachedServiceTest method testObserve.

@Test
public void testObserve() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY);
    ServiceObserver observer = new ServiceObserver(executor);
    assertThat(observer.install(), sameInstance((ListenableFuture<CachedService>) observer));
    assertThat(executor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.READY), hasItem(observer));
    observer.run();
    ArgumentCaptor<RowListener> rowListener = ArgumentCaptor.forClass(RowListener.class);
    ArgumentCaptor<StepListener> stepListener = ArgumentCaptor.forClass(StepListener.class);
    verify(serviceStep).addRowListener(rowListener.capture());
    verify(serviceStep).addStepListener(stepListener.capture());
    assertThat(observer.isDone(), is(false));
    for (RowMetaAndData metaAndData : testData) {
        rowListener.getValue().rowWrittenEvent(metaAndData.getRowMeta(), metaAndData.getData());
    }
    stepListener.getValue().stepFinished(serviceTrans, mock(StepMeta.class), serviceStep);
    assertThat(observer.isDone(), is(true));
    assertThat(observer.get().getRowMetaAndData(), equalTo((Iterable<RowMetaAndData>) testData));
    assertThat(observer.get().isComplete(), is(true));
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) FluentIterable(com.google.common.collect.FluentIterable) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StepListener(org.pentaho.di.trans.step.StepListener) StepMeta(org.pentaho.di.trans.step.StepMeta) RowListener(org.pentaho.di.trans.step.RowListener) Test(org.junit.Test)

Example 18 with DataServiceExecutor

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

the class CachedServiceTest method testReplayPartialCache.

@Test
public void testReplayPartialCache() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY + " LIMIT 20");
    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();
    final AtomicInteger rowsProduced = new AtomicInteger(0);
    when(rowProducer.putRowWait(any(RowMetaInterface.class), any(Object[].class), anyInt(), any(TimeUnit.class))).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            rowsProduced.getAndIncrement();
            return true;
        }
    });
    when(genTrans.isRunning()).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            return rowsProduced.get() < 20;
        }
    });
    // Run cache loader (would be asynchronous)
    replayRunnable.getValue().run();
    verify(rowProducer).finished();
    assertThat(replay.get(1, TimeUnit.SECONDS), equalTo(20));
    assertThat(rowsProduced.get(), equalTo(20));
    for (RowMetaAndData metaAndData : Iterables.limit(testData, 20)) {
        Object[] data = metaAndData.getData();
        verify(rowProducer).putRowWait(eq(metaAndData.getRowMeta()), and(eq(data), AdditionalMatchers.not(same(data))), anyInt(), any(TimeUnit.class));
    }
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Executor(java.util.concurrent.Executor) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Example 19 with DataServiceExecutor

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

the class CachedServiceTest method testObservePartial.

@Test
public void testObservePartial() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY + " LIMIT 20");
    ServiceObserver observer = new ServiceObserver(executor);
    observer.install();
    assertThat(executor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.READY), hasItem(observer));
    observer.run();
    ArgumentCaptor<RowListener> rowListener = ArgumentCaptor.forClass(RowListener.class);
    ArgumentCaptor<StepListener> stepListener = ArgumentCaptor.forClass(StepListener.class);
    verify(serviceStep).addRowListener(rowListener.capture());
    verify(serviceStep).addStepListener(stepListener.capture());
    assertThat(observer.isDone(), is(false));
    for (RowMetaAndData metaAndData : FluentIterable.from(testData)) {
        rowListener.getValue().rowWrittenEvent(metaAndData.getRowMeta(), metaAndData.getData());
    }
    when(serviceStep.isStopped()).thenReturn(true);
    stepListener.getValue().stepFinished(serviceTrans, mock(StepMeta.class), serviceStep);
    assertThat(observer.isDone(), is(true));
    CachedService cachedService = observer.get(5, TimeUnit.SECONDS);
    assertThat(cachedService.isComplete(), is(false));
    assertThat(cachedService.getRowMetaAndData(), equalTo(testData));
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) StepListener(org.pentaho.di.trans.step.StepListener) StepMeta(org.pentaho.di.trans.step.StepMeta) RowListener(org.pentaho.di.trans.step.RowListener) Test(org.junit.Test)

Example 20 with DataServiceExecutor

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

the class CachedServiceTest method testAnswersOverflowDETQuery.

@Test
public void testAnswersOverflowDETQuery() throws Exception {
    String query = "SELECT * FROM " + SERVICE_NAME;
    DataServiceExecutor executor = dataServiceExecutor(query);
    when(sqlTransGenerator.getServiceRowLimit()).thenReturn(10000);
    CachedService partial = partial(executor);
    String aggregateQuery = "SELECT count(*) FROM " + SERVICE_NAME;
    assertThat(partial.answersQuery(dataServiceExecutor(aggregateQuery)), is(true));
}
Also used : DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) 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