use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.
the class TestDQPCore method testSerialThreadBoundClose.
@Test
public void testSerialThreadBoundClose() throws Exception {
agds.setSleep(100);
agds.threadBound = true;
core.setUserRequestSourceConcurrency(1);
// $NON-NLS-1$
String sql = "SELECT IntKey FROM BQT1.SmallA";
// $NON-NLS-1$
String userName = "logon";
((BufferManagerImpl) core.getBufferManager()).setProcessorBatchSize(1);
RequestMessage reqMsg = exampleRequestMessage(sql);
// execute by don't finish the work
execute(userName, 1, reqMsg);
// make sure the source request is still closed
assertEquals(1, agds.getCloseCount().get());
}
use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.
the class TestDQPCore method testBufferLimit.
@Test
public void testBufferLimit() throws Exception {
// the sql should return 400 rows
// $NON-NLS-1$
String sql = "SELECT A.IntKey FROM BQT1.SmallA as A, BQT1.SmallA as B, (select intkey from BQT1.SmallA limit 4) as C";
// $NON-NLS-1$
String userName = "1";
// $NON-NLS-1$
String sessionid = "1";
RequestMessage reqMsg = exampleRequestMessage(sql);
reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
DQPWorkContext.getWorkContext().getSession().setUserName(userName);
((BufferManagerImpl) core.getBufferManager()).setProcessorBatchSize(1);
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
int rowsPerBatch = 8;
assertEquals(rowsPerBatch, rm.getResultsList().size());
RequestWorkItem item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
message = core.processCursorRequest(reqMsg.getExecutionId(), 9, rowsPerBatch);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(rowsPerBatch, rm.getResultsList().size());
// ensure that we are idle
for (int i = 0; i < 10 && item.getThreadState() != ThreadState.IDLE; i++) {
Thread.sleep(100);
}
assertEquals(ThreadState.IDLE, item.getThreadState());
assertTrue(item.resultsBuffer.getManagedRowCount() <= rowsPerBatch * 23);
// pull the rest of the results
int start = 17;
while (true) {
item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
message = core.processCursorRequest(reqMsg.getExecutionId(), start, rowsPerBatch);
rm = message.get(5000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertTrue(rowsPerBatch >= rm.getResultsList().size());
start += rm.getResultsList().size();
if (rm.getFinalRow() == rm.getLastRow()) {
break;
}
}
// insensitive should not block
reqMsg.setCursorType(ResultSet.TYPE_SCROLL_INSENSITIVE);
reqMsg.setExecutionId(id++);
message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(rowsPerBatch, rm.getResultsList().size());
item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
message = core.processCursorRequest(reqMsg.getExecutionId(), 9, rowsPerBatch);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(rowsPerBatch, rm.getResultsList().size());
// ensure that we are idle
for (int i = 0; i < 10 && item.getThreadState() != ThreadState.IDLE; i++) {
Thread.sleep(100);
}
assertEquals(ThreadState.IDLE, item.getThreadState());
// should buffer the same as forward only until a further batch is requested
assertTrue(item.resultsBuffer.getManagedRowCount() <= rowsPerBatch * 23);
// local should not buffer
reqMsg = exampleRequestMessage(sql);
reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
reqMsg.setSync(true);
message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
rm = message.get(0, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(rowsPerBatch, rm.getResultsList().size());
item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
assertEquals(0, item.resultsBuffer.getManagedRowCount());
assertEquals(8, item.resultsBuffer.getRowCount());
}
use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.
the class TestDQPCore method testUsingFinalBuffer.
@Test
public void testUsingFinalBuffer() throws Exception {
String sql = "select intkey from bqt1.smalla order by intkey";
((BufferManagerImpl) core.getBufferManager()).setProcessorBatchSize(2);
agds.sleep = 50;
RequestMessage reqMsg = exampleRequestMessage(sql);
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(10, rm.getResultsList().size());
message = core.processCursorRequest(reqMsg.getExecutionId(), 3, 2);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(2, rm.getResultsList().size());
}
use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.
the class TestDQPCore method testBufferReuse1.
@Test
public void testBufferReuse1() throws Exception {
// the sql should return 100 rows
String sql = "SELECT IntKey FROM texttable('1112131415' columns intkey integer width 2 no row delimiter) t " + "union " + // $NON-NLS-1$
"SELECT IntKey FROM bqt1.smalla order by intkey";
// $NON-NLS-1$
String userName = "1";
// $NON-NLS-1$
String sessionid = "1";
agds.sleep = 50;
agds.setUseIntCounter(true);
RequestMessage reqMsg = exampleRequestMessage(sql);
reqMsg.setRowLimit(11);
reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
DQPWorkContext.getWorkContext().getSession().setUserName(userName);
BufferManagerImpl bufferManager = (BufferManagerImpl) core.getBufferManager();
bufferManager.setProcessorBatchSize(20);
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(10, rm.getResultsList().size());
message = core.processCursorRequest(reqMsg.getExecutionId(), 6, 5);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(5, rm.getResultsList().size());
message = core.processCursorRequest(reqMsg.getExecutionId(), 11, 5);
rm = message.get(500000, TimeUnit.MILLISECONDS);
assertNull(rm.getException());
assertEquals(1, rm.getResultsList().size());
assertEquals(11, rm.getFirstRow());
assertEquals(11, rm.getFinalRow());
}
use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.
the class TestOrderByProcessing method testDefaultNullOrdering.
@Test
public void testDefaultNullOrdering() throws Exception {
// $NON-NLS-1$
String sql = "select e1 from pm1.g1 order by e1";
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
CommandContext cc = createCommandContext();
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setOptions(new Options().defaultNullOrder(NullOrder.FIRST));
cc.setBufferManager(bm);
ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(), cc);
HardcodedDataManager manager = new HardcodedDataManager(metadata);
manager.addData("SELECT g1.e1 FROM g1", new List[] { Arrays.asList("a"), Arrays.asList("b"), Arrays.asList((String) null) });
helpProcess(plan, cc, manager, new List[] { Arrays.asList((String) null), Arrays.asList("a"), Arrays.asList("b") });
plan = helpGetPlan(helpParse("select e1 from pm1.g1 order by e1 desc"), metadata, new DefaultCapabilitiesFinder(), cc);
helpProcess(plan, cc, manager, new List[] { Arrays.asList((String) null), Arrays.asList("b"), Arrays.asList("a") });
bm.getOptions().setDefaultNullOrder(NullOrder.LAST);
plan = helpGetPlan(helpParse("select e1 from pm1.g1 order by e1 desc"), metadata, new DefaultCapabilitiesFinder(), cc);
helpProcess(plan, cc, manager, new List[] { Arrays.asList("b"), Arrays.asList("a"), Arrays.asList((String) null) });
bm.getOptions().setDefaultNullOrder(NullOrder.HIGH);
plan = helpGetPlan(helpParse("select e1 from pm1.g1 order by e1"), metadata, new DefaultCapabilitiesFinder(), cc);
helpProcess(plan, cc, manager, new List[] { Arrays.asList("a"), Arrays.asList("b"), Arrays.asList((String) null) });
}
Aggregations