use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class TestRelationalNodeStatistics method testStatsCollectionBuffer.
@Test
public void testStatsCollectionBuffer() throws TeiidComponentException, TeiidProcessingException {
List[] data = createData(1000);
FakeRelationalNode fakeNode = createFakeNode(data);
fakeNode.setUseBuffer(true);
// read from fake node
while (true) {
TupleBatch batch = fakeNode.nextBatch();
if (batch.getTerminationFlag()) {
break;
}
}
int actualNodeBlocks = fakeNode.getNodeStatistics().getNodeBlocks();
int actualNodeNextBatchCalls = fakeNode.getNodeStatistics().getNodeNextBatchCalls();
long actualNodeOutputRows = fakeNode.getNodeStatistics().getNodeOutputRows();
// $NON-NLS-1$
assertEquals("The NodeOutputRows was Inccorrect. Correct: 1000 Actual: " + actualNodeOutputRows, 1000, actualNodeOutputRows);
// $NON-NLS-1$
assertEquals("The NodeNextBatchCalls was Inccorrect. Correct: 10 Actual: " + actualNodeNextBatchCalls, 10, actualNodeNextBatchCalls);
// $NON-NLS-1$
assertEquals("The NodeBlocks was Inccorrect. Correct: 0 Actual: " + actualNodeBlocks, 0, actualNodeBlocks);
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class TestSelectNode method testEmptyBatchIndexing.
/**
* Ensures that a final empty batch is reindexed so that the batch iterator works correctly
*/
@Test
public void testEmptyBatchIndexing() throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List elements = new ArrayList();
elements.add(es1);
CompareCriteria crit = new CompareCriteria(new Constant(0), CompareCriteria.EQ, new Constant(new Integer(1)));
List childElements = new ArrayList();
childElements.add(es1);
RelationalNode child = new RelationalNode(0) {
int i = 0;
@Override
public Object clone() {
return null;
}
@Override
protected TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (i++ == 0) {
return new TupleBatch(1, new List[] { Arrays.asList(1), Arrays.asList(1) });
}
TupleBatch batch = new TupleBatch(3, new List[0]);
batch.setTerminationFlag(true);
return batch;
}
};
helpTestSelect(elements, crit, childElements, null, new List[0], child);
}
use of org.teiid.common.buffer.TupleBatch 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.TupleBatch 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);
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class TestLocalBufferService method testStateTransfer.
@Test
public void testStateTransfer() throws Exception {
BufferServiceImpl svc = new BufferServiceImpl();
svc.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/1");
svc.setUseDisk(true);
svc.start();
BufferManager mgr = svc.getBufferManager();
List<ElementSymbol> schema = new ArrayList<ElementSymbol>(2);
// $NON-NLS-1$
ElementSymbol es = new ElementSymbol("x");
es.setType(DataTypeManager.getDataTypeClass(DefaultDataTypes.STRING));
schema.add(es);
// $NON-NLS-1$
ElementSymbol es2 = new ElementSymbol("y");
es2.setType(DataTypeManager.getDataTypeClass(DefaultDataTypes.INTEGER));
schema.add(es2);
// $NON-NLS-1$
TupleBuffer buffer = mgr.createTupleBuffer(schema, "cached", TupleSourceType.FINAL);
buffer.setBatchSize(50);
buffer.setId("state_id");
for (int batch = 0; batch < 3; batch++) {
for (int row = 0; row < 50; row++) {
int val = (batch * 50) + row;
buffer.addTuple(Arrays.asList(new Object[] { "String" + val, new Integer(val) }));
}
}
buffer.close();
mgr.distributeTupleBuffer(buffer.getId(), buffer);
FileOutputStream fo = new FileOutputStream(UnitTestUtil.getTestScratchPath() + "/teiid/statetest");
((BufferManagerImpl) mgr).getState(buffer.getId(), fo);
fo.close();
svc.stop();
// now read back
BufferServiceImpl svc2 = new BufferServiceImpl();
svc2.setDiskDirectory(UnitTestUtil.getTestScratchPath() + "/teiid/2");
svc2.setUseDisk(true);
svc2.start();
BufferManagerImpl mgr2 = svc2.getBufferManager();
FileInputStream fis = new FileInputStream(UnitTestUtil.getTestScratchPath() + "/teiid/statetest");
mgr2.setState(buffer.getId(), fis);
fis.close();
String id = "state_id";
buffer = mgr2.getTupleBuffer(id);
for (int batch = 0; batch < 3; batch++) {
TupleBatch tb = buffer.getBatch((batch * 50) + 1);
List[] rows = tb.getAllTuples();
for (int row = 0; row < 50; row++) {
int val = (batch * 50) + row;
assertEquals("String" + val, rows[row].get(0));
assertEquals(val, rows[row].get(1));
}
}
svc2.stop();
}
Aggregations