use of org.teiid.client.RequestMessage in project teiid by teiid.
the class TestDQPCore method helpExecute.
private ResultsMessage helpExecute(String sql, String userName, int sessionid, boolean txnAutoWrap) throws Exception {
RequestMessage reqMsg = exampleRequestMessage(sql);
if (txnAutoWrap) {
reqMsg.setTxnAutoWrapMode(RequestMessage.TXN_WRAP_ON);
}
ResultsMessage results = execute(userName, sessionid, reqMsg);
core.terminateSession(String.valueOf(sessionid));
assertNull(core.getClientState(String.valueOf(sessionid), false));
if (results.getException() != null) {
throw results.getException();
}
return results;
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class TestDQPCore method testRequestMaxActive.
@Test
public void testRequestMaxActive() throws Exception {
agds.latch = new CountDownLatch(3);
int toRun = 2;
CountDownLatch submitted = new CountDownLatch(toRun);
ExecutorService es = Executors.newCachedThreadPool();
final DQPWorkContext context = DQPWorkContext.getWorkContext();
final AtomicInteger counter = new AtomicInteger();
es.invokeAll(Collections.nCopies(toRun, new Callable<Void>() {
@Override
public Void call() throws Exception {
DQPWorkContext.setWorkContext(context);
RequestMessage reqMsg = exampleRequestMessage("select * FROM BQT1.SmallA");
DQPWorkContext.getWorkContext().getSession().setSessionId("1");
DQPWorkContext.getWorkContext().getSession().setUserName("a");
Future<ResultsMessage> message = null;
try {
message = core.executeRequest(counter.getAndIncrement(), reqMsg);
} finally {
submitted.countDown();
}
assertNotNull(core.getClientState("1", false));
// after this, both will be submitted
submitted.await();
// allow the execution to proceed
agds.latch.countDown();
message.get(500000, TimeUnit.MILLISECONDS);
return null;
}
}));
assertEquals(1, this.core.getMaxWaitingPlanWatermark());
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class TestDQPCore method testDataAvailable.
@Test
public void testDataAvailable() throws Exception {
agds.dataNotAvailable = -1;
agds.dataAvailable = true;
RequestMessage reqMsg = exampleRequestMessage("select * FROM BQT1.SmallA");
ResultsMessage results = execute("A", 1, reqMsg);
if (results.getException() != null) {
throw results.getException();
}
}
use of org.teiid.client.RequestMessage 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.client.RequestMessage 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());
}
Aggregations