use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestProjectIntoNode method helpTestNextBatch.
private void helpTestNextBatch(int tupleBatchSize, Mode mode) throws Exception {
ProjectIntoNode node = new ProjectIntoNode(2);
TupleSource tupleSource = new FakeDataTupleSource(NUM_ROWS);
RelationalNode child = new FakeRelationalNode(1, tupleSource, tupleBatchSize);
node.addChild(child);
// $NON-NLS-1$
node.setIntoGroup(new GroupSymbol("myGroup"));
// $NON-NLS-1$
ElementSymbol elementSymbol_1 = new ElementSymbol("myGroup.myElement1");
// $NON-NLS-1$
ElementSymbol elementSymbol_2 = new ElementSymbol("myGroup.myElement2");
elementSymbol_1.setType(Integer.class);
elementSymbol_2.setType(String.class);
List<ElementSymbol> elements = Arrays.asList(elementSymbol_1, elementSymbol_2);
node.setIntoElements(elements);
child.setElements(elements);
node.setMode(mode);
// $NON-NLS-1$
node.setModelName("myModel");
CommandContext context = new CommandContext();
BufferManager bm = BufferManagerFactory.getTestBufferManager(tupleBatchSize, tupleBatchSize);
ProcessorDataManager dataManager = new FakePDM(tupleBatchSize);
child.initialize(context, bm, dataManager);
node.initialize(context, bm, dataManager);
node.open();
TupleBatch batch = null;
// Do the remaining batches
while (true) {
try {
batch = node.nextBatch();
break;
} catch (BlockedException e) {
// Normal
}
}
assertNotNull(batch);
List[] tuples = batch.getAllTuples();
assertEquals(1, tuples.length);
Object[] columns = tuples[0].toArray();
assertNotNull(columns);
assertEquals(1, columns.length);
// Should have inserted all rows
assertEquals(new Integer(NUM_ROWS), columns[0]);
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestProjectNode method helpTestProject.
public void helpTestProject(List elements, List[] data, List childElements, List[] expected, ProcessorDataManager dataMgr) throws TeiidComponentException, TeiidProcessingException {
ProjectNode projectNode = helpSetupProject(elements, data, childElements, dataMgr);
projectNode.open();
int currentRow = 1;
while (true) {
try {
TupleBatch batch = projectNode.nextBatch();
for (int row = currentRow; row <= batch.getEndRow(); row++) {
// $NON-NLS-1$
assertEquals("Rows don't match at " + row, expected[row - 1], batch.getTuple(row));
}
if (batch.getTerminationFlag()) {
break;
}
currentRow += batch.getRowCount();
} catch (BlockedException e) {
// ignore and try again
}
}
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestSelectNode method helpTestSelect.
private void helpTestSelect(List elements, Criteria criteria, List childElements, ProcessorDataManager dataMgr, List[] expected, RelationalNode child, SelectNode selectNode) throws TeiidComponentException, TeiidProcessingException {
BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "test", null, null, 1);
child.setElements(childElements);
child.initialize(context, mgr, dataMgr);
selectNode.setCriteria(criteria);
selectNode.setElements(elements);
selectNode.addChild(child);
selectNode.initialize(context, mgr, dataMgr);
selectNode.open();
BatchIterator iterator = new BatchIterator(selectNode);
for (int i = 0; i < expected.length; i++) {
while (true) {
try {
// $NON-NLS-1$
assertEquals("Rows don't match at " + i, expected[i], iterator.nextTuple());
break;
} catch (BlockedException e) {
continue;
}
}
}
assertFalse(iterator.hasNext());
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestSortNode method helpTestSort.
private void helpTestSort(List elements, List[] data, List sortElements, List sortTypes, List[] expected, Mode mode) throws TeiidComponentException, TeiidProcessingException {
BufferManagerImpl mgr = BufferManagerFactory.getTestBufferManager(10000, BATCH_SIZE);
long reserve = mgr.getReserveBatchBytes();
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "test", null, null, 1);
BlockingFakeRelationalNode dataNode = new BlockingFakeRelationalNode(2, data);
dataNode.setReturnPeriod(3);
dataNode.setElements(elements);
dataNode.initialize(context, mgr, null);
SortNode sortNode = new SortNode(1);
sortNode.setSortElements(new OrderBy(sortElements, sortTypes).getOrderByItems());
sortNode.setMode(mode);
sortNode.setElements(elements);
sortNode.addChild(dataNode);
sortNode.initialize(context, mgr, null);
sortNode.open();
assertTrue(sortNode.hasBuffer());
int currentRow = 1;
while (true) {
try {
TupleBatch batch = sortNode.nextBatch();
for (int row = currentRow; row <= batch.getEndRow(); row++) {
// $NON-NLS-1$
assertEquals("Rows don't match at " + row, expected[row - 1], batch.getTuple(row));
}
currentRow += batch.getRowCount();
if (batch.getTerminationFlag()) {
break;
}
} catch (BlockedException e) {
}
}
assertEquals(expected.length, currentRow - 1);
assertEquals(reserve, mgr.getReserveBatchBytes());
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestUnionAllNode method helpTestUnion.
public void helpTestUnion(RelationalNode[] children, RelationalNode union, List[] expected) throws TeiidComponentException, TeiidProcessingException {
BufferManager mgr = BufferManagerFactory.getTestBufferManager(1, 2);
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "test", null, null, 1);
FakeDataManager fdm = new FakeDataManager();
for (int i = 0; i < children.length; i++) {
union.addChild(children[i]);
children[i].initialize(context, mgr, fdm);
}
union.initialize(context, mgr, fdm);
union.open();
int currentRow = 1;
while (true) {
try {
TupleBatch batch = union.nextBatch();
for (int row = currentRow; row <= batch.getEndRow(); row++) {
List tuple = batch.getTuple(row);
// System.out.println(tuple);
// $NON-NLS-1$
assertEquals("Rows don't match at " + row, expected[row - 1], tuple);
}
currentRow += batch.getRowCount();
if (batch.getTerminationFlag()) {
break;
}
} catch (BlockedException e) {
// ignore and retry
}
}
union.close();
// $NON-NLS-1$
assertEquals("Didn't match expected counts", expected.length, currentRow - 1);
}
Aggregations