use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class QueryProcessor method nextBatchDirect.
private TupleBatch nextBatchDirect() throws BlockedException, TeiidProcessingException, TeiidComponentException {
boolean done = false;
TupleBatch result = null;
try {
init();
long currentTime = System.currentTimeMillis();
Assertion.assertTrue(!processorClosed);
while (currentTime < context.getTimeSliceEnd() || context.isNonBlocking()) {
if (requestCanceled) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, this.context.getRequestId()));
}
if (currentTime > context.getTimeoutEnd()) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30161, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30161));
}
result = processPlan.nextBatch();
if (continuous) {
result.setRowOffset(rowOffset);
if (result.getTerminationFlag()) {
result.setTermination(TupleBatch.ITERATION_TERMINATED);
List<Object> terminationTuple = Arrays.asList(new Object[this.getOutputElements().size()]);
result.getTuples().add(terminationTuple);
this.context.getTupleSourceCache().close();
this.processPlan.close();
this.processPlan.reset();
this.context.incrementReuseCount();
this.open = false;
}
rowOffset = result.getEndRow() + 1;
}
if (result.getTermination() != TupleBatch.NOT_TERMINATED) {
if (result.getTerminationFlag()) {
done = true;
}
break;
}
if (result.getRowCount() > 0) {
break;
}
}
} catch (BlockedException e) {
throw e;
} catch (TeiidException e) {
closeProcessing();
if (e instanceof TeiidProcessingException) {
throw (TeiidProcessingException) e;
}
if (e instanceof TeiidComponentException) {
throw (TeiidComponentException) e;
}
throw new TeiidComponentException(QueryPlugin.Event.TEIID30162, e);
}
if (done) {
closeProcessing();
}
if (result == null) {
RequestWorkItem workItem = this.getContext().getWorkItem();
if (workItem != null) {
// if we have a workitem (non-test scenario) then before
// throwing exprired time slice we need to indicate there's more work
workItem.moreWork();
}
throw EXPIRED_TIME_SLICE;
}
return result;
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestAsyncTupleSource method testTupleSource.
@Test
public void testTupleSource() throws TeiidComponentException, TeiidProcessingException {
AsyncTupleSource ats = new AsyncTupleSource(new Callable<TupleSource>() {
@Override
public TupleSource call() throws Exception {
return new CollectionTupleSource(Arrays.asList(Arrays.asList(1), Arrays.asList(2)).iterator());
}
}, new CommandContext());
for (int i = 0; i < 20; i++) {
try {
assertEquals(Arrays.asList(1), ats.nextTuple());
break;
} catch (BlockedException e) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
}
}
}
assertEquals(Arrays.asList(2), ats.nextTuple());
assertNull(ats.nextTuple());
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestProcessor method doProcess.
public static long doProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults, CommandContext context) throws Exception {
BufferManager bufferMgr = context.getBufferManager();
if (bufferMgr == null) {
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setProcessorBatchSize(context.getProcessorBatchSize());
context.setBufferManager(bm);
bufferMgr = bm;
}
context.getNextRand(0);
if (context.getTempTableStore() == null) {
context.setTempTableStore(new TempTableStore(context.getConnectionId(), TransactionMode.ISOLATE_WRITES));
}
if (context.getGlobalTableStore() == null) {
GlobalTableStoreImpl gts = new GlobalTableStoreImpl(bufferMgr, null, context.getMetadata());
context.setGlobalTableStore(gts);
}
if (!(dataManager instanceof TempTableDataManager)) {
SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
cache.setTupleBufferCache(bufferMgr);
dataManager = new TempTableDataManager(dataManager, bufferMgr, cache);
}
if (context.getQueryProcessorFactory() == null) {
context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bufferMgr, dataManager, new DefaultCapabilitiesFinder(), null, context.getMetadata()));
}
TupleBuffer id = null;
long rowCount = 0;
try {
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
// processor.setNonBlocking(true);
BatchCollector collector = processor.createBatchCollector();
for (int i = 0; i < 100; i++) {
try {
id = collector.collectTuples();
break;
} catch (BlockedException e) {
}
}
if (id == null) {
fail("did not complete processing");
}
rowCount = id.getRowCount();
if (DEBUG) {
// $NON-NLS-1$
System.out.println("\nResults:\n" + id.getSchema());
TupleSource ts2 = id.createIndexedTupleSource();
for (int j = 0; j < rowCount; j++) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("" + j + ": " + ts2.nextTuple());
}
}
if (expectedResults != null) {
examineResults(expectedResults, bufferMgr, id);
}
} finally {
if (id != null) {
id.remove();
}
}
return rowCount;
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestBatchedUpdateNode method helpTestNextBatch.
private FakePDM helpTestNextBatch(String[] commands, int[] expectedResults) throws Exception {
int numExecutedCommands = 0;
for (int i = 0; i < expectedResults.length; i++) {
numExecutedCommands += expectedResults[i];
}
FakePDM fakePDM = new FakePDM(numExecutedCommands);
BatchedUpdateNode node = helpOpen(commands, fakePDM);
TupleBatch batch = null;
try {
batch = node.nextBatch();
} catch (BlockedException e) {
batch = node.nextBatch();
}
assertNotNull(batch);
assertTrue(batch.getTerminationFlag());
assertEquals(expectedResults.length, batch.getRowCount());
for (int i = 0; i < expectedResults.length; i++) {
List tuple = batch.getTuple(i + 1);
assertNotNull(tuple);
Object result = tuple.get(0);
assertNotNull(result);
assertEquals(new Integer(expectedResults[i]), result);
}
return fakePDM;
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestJoinNode method process.
private void process(List[] expectedResults) throws TeiidComponentException, TeiidProcessingException {
join.open();
int currentRow = 1;
while (true) {
try {
TupleBatch batch = join.nextBatch();
for (; currentRow <= batch.getEndRow(); currentRow++) {
List tuple = batch.getTuple(currentRow);
// $NON-NLS-1$
assertEquals("Rows don't match at " + currentRow, expectedResults[currentRow - 1], tuple);
}
if (batch.getTerminationFlag()) {
break;
}
} catch (BlockedException e) {
// ignore and retry
}
}
assertEquals(expectedResults.length, currentRow - 1);
join.close();
}
Aggregations