Search in sources :

Example 26 with RequestMessage

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;
}
Also used : ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage)

Example 27 with RequestMessage

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 28 with RequestMessage

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();
    }
}
Also used : ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) Test(org.junit.Test)

Example 29 with RequestMessage

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());
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) RequestMessage(org.teiid.client.RequestMessage) Test(org.junit.Test)

Example 30 with RequestMessage

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());
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) Test(org.junit.Test)

Aggregations

RequestMessage (org.teiid.client.RequestMessage)44 ResultsMessage (org.teiid.client.ResultsMessage)23 Test (org.junit.Test)22 AtomicRequestMessage (org.teiid.dqp.message.AtomicRequestMessage)10 RequestID (org.teiid.dqp.message.RequestID)8 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)6 FakeTransactionService (org.teiid.dqp.internal.datamgr.FakeTransactionService)6 ResultsFuture (org.teiid.client.util.ResultsFuture)5 List (java.util.List)4 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)4 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 TeiidComponentException (org.teiid.core.TeiidComponentException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 Command (org.teiid.query.sql.lang.Command)3 TimeoutException (java.util.concurrent.TimeoutException)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 CommandContext (org.teiid.query.util.CommandContext)2 BatchUpdateException (java.sql.BatchUpdateException)1