Search in sources :

Example 6 with RowListener

use of org.pentaho.di.trans.step.RowListener 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 7 with RowListener

use of org.pentaho.di.trans.step.RowListener 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 8 with RowListener

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

the class StreamingServiceTransExecutorTest method testGetBufferCleanup.

@Test
public void testGetBufferCleanup() throws Exception {
    serviceExecutor.getBuffer(MOCK_QUERY, MOCK_WINDOW_MODE_ROW_BASED, 1, 0, 0);
    ArgumentCaptor<RowListener> listenerArgumentCaptor = ArgumentCaptor.forClass(RowListener.class);
    verify(serviceStep).addRowListener(listenerArgumentCaptor.capture());
    verify(serviceTrans).startThreads();
    verify(serviceTrans).findRunThread(MOCK_SERVICE_STEP_NAME);
    verify(serviceStep).addRowListener(any(RowAdapter.class));
    // Verify linkage
    RowListener serviceRowListener = listenerArgumentCaptor.getValue();
    assertNotNull(serviceRowListener);
    RowMetaInterface rowMeta = serviceTrans.getTransMeta().getStepFields(MOCK_SERVICE_STEP_NAME);
    Object[] data = new Object[] { 0 };
    serviceExecutor.clearCache();
    serviceRowListener.rowWrittenEvent(rowMeta, data);
    verify(log).logRowlevel(DataServiceConstants.PASSING_ALONG_ROW + rowMeta.getString(data));
    verify(serviceTrans).stopAll();
    verify(log).logDetailed(DataServiceConstants.STREAMING_TRANSFORMATION_STOPPED);
}
Also used : RowAdapter(org.pentaho.di.trans.step.RowAdapter) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowListener(org.pentaho.di.trans.step.RowListener) Test(org.junit.Test)

Aggregations

RowListener (org.pentaho.di.trans.step.RowListener)8 Test (org.junit.Test)5 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)5 StepInterface (org.pentaho.di.trans.step.StepInterface)4 StepListener (org.pentaho.di.trans.step.StepListener)4 StepMeta (org.pentaho.di.trans.step.StepMeta)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 InOrder (org.mockito.InOrder)2 Matchers.anyString (org.mockito.Matchers.anyString)2 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 SQL (org.pentaho.di.core.sql.SQL)2 RowProducer (org.pentaho.di.trans.RowProducer)2 TransListener (org.pentaho.di.trans.TransListener)2 DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)2 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)2 RowAdapter (org.pentaho.di.trans.step.RowAdapter)2 IMetaStore (org.pentaho.metastore.api.IMetaStore)2