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));
}
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));
}
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);
}
Aggregations