Search in sources :

Example 11 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class TestDQPCore method testServerTimeout.

@Test
public void testServerTimeout() throws Exception {
    RequestMessage reqMsg = exampleRequestMessage("select to_bytes(stringkey, 'utf-8') FROM BQT1.SmallA");
    reqMsg.setTxnAutoWrapMode(RequestMessage.TXN_WRAP_OFF);
    agds.setSleep(100);
    this.config.setQueryTimeout(1);
    ResultsMessage rm = execute("A", 1, reqMsg);
    assertNotNull(rm.getException());
    assertEquals("57014 TEIID30563 The request 1.0 has been cancelled: TEIID31096 Query has exceeded the VDB/engine timeout of 1 milliseconds.", rm.getException().getMessage());
}
Also used : ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) Test(org.junit.Test)

Example 12 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class TestDQPCoreRequestHandling method testRemoveConnectorInfo.

public void testRemoveConnectorInfo() {
    DQPCore rm = new DQPCore();
    rm.setTransactionService(new FakeTransactionService());
    // $NON-NLS-1$
    RequestMessage r0 = new RequestMessage("foo");
    RequestID requestID = new RequestID(SESSION_STRING, 1);
    RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null);
    AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.getDqpWorkContext(), 1);
    DataTierTupleSource info = Mockito.mock(DataTierTupleSource.class);
    workItem.addConnectorRequest(atomicReq.getAtomicRequestID(), info);
    workItem.closeAtomicRequest(atomicReq.getAtomicRequestID());
    DataTierTupleSource arInfo = workItem.getConnectorRequest(atomicReq.getAtomicRequestID());
    assertNull(arInfo);
}
Also used : RequestID(org.teiid.dqp.message.RequestID) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMessage(org.teiid.client.RequestMessage) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage)

Example 13 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class TestDQPCoreRequestHandling method testGetConnectorInfo.

public void testGetConnectorInfo() {
    DQPCore rm = new DQPCore();
    rm.setTransactionService(new FakeTransactionService());
    // $NON-NLS-1$
    RequestMessage r0 = new RequestMessage("foo");
    RequestID requestID = new RequestID(SESSION_STRING, 1);
    RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null);
    AtomicRequestMessage atomicReq = new AtomicRequestMessage(workItem.requestMsg, workItem.getDqpWorkContext(), 1);
    DataTierTupleSource info = Mockito.mock(DataTierTupleSource.class);
    workItem.addConnectorRequest(atomicReq.getAtomicRequestID(), info);
    DataTierTupleSource arInfo = workItem.getConnectorRequest(atomicReq.getAtomicRequestID());
    assertTrue(arInfo == info);
}
Also used : RequestID(org.teiid.dqp.message.RequestID) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMessage(org.teiid.client.RequestMessage) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage)

Example 14 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class TestDQPCoreRequestHandling method testAddRequest.

public void testAddRequest() {
    DQPCore rm = new DQPCore();
    rm.setTransactionService(new FakeTransactionService());
    // $NON-NLS-1$
    RequestMessage r0 = new RequestMessage("foo");
    RequestID requestID = new RequestID(SESSION_STRING, 1);
    addRequest(rm, r0, requestID, null, null);
}
Also used : RequestID(org.teiid.dqp.message.RequestID) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMessage(org.teiid.client.RequestMessage) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService)

Example 15 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class TestPreparedStatement method testBatchedUpdateExecution.

/**
 * Verify that the <code>executeBatch()</code> method of <code>
 * MMPreparedStatement</code> is resulting in the correct command,
 * parameter values for each command of the batch, and the request type
 * are being set in the request message that would normally be sent to the
 * server.
 *
 * @throws Exception
 */
@Test
public void testBatchedUpdateExecution() throws Exception {
    // Build up a fake connection instance for use with the prepared statement
    ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
    Mockito.stub(conn.getConnectionProps()).toReturn(new Properties());
    DQP dqp = Mockito.mock(DQP.class);
    ServerConnection serverConn = Mockito.mock(ServerConnection.class);
    LogonResult logonResult = Mockito.mock(LogonResult.class);
    // stub methods
    Mockito.stub(conn.getServerConnection()).toReturn(serverConn);
    Mockito.stub(serverConn.getLogonResult()).toReturn(logonResult);
    Mockito.stub(logonResult.getTimeZone()).toReturn(TimeZone.getDefault());
    // a dummy result message that is specific to this test case
    final ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>();
    final int[] count = new int[1];
    final ResultsMessage rm = new ResultsMessage();
    Mockito.stub(dqp.executeRequest(Matchers.anyLong(), (RequestMessage) Matchers.anyObject())).toAnswer(new Answer<ResultsFuture<ResultsMessage>>() {

        @Override
        public ResultsFuture<ResultsMessage> answer(InvocationOnMock invocation) throws Throwable {
            RequestMessage requestMessage = (RequestMessage) invocation.getArguments()[1];
            count[0] += requestMessage.getParameterValues().size();
            if (count[0] == 100000) {
                rm.setException(new TeiidException());
                rm.setResults(new List<?>[] { Arrays.asList(Statement.EXECUTE_FAILED) });
            } else {
                List<?>[] vals = new List<?>[requestMessage.getParameterValues().size()];
                Arrays.fill(vals, Arrays.asList(0));
                rm.setResults(Arrays.asList(vals));
            }
            return results;
        }
    });
    rm.setUpdateResult(true);
    results.getResultsReceiver().receiveResults(rm);
    Mockito.stub(conn.getDQP()).toReturn(dqp);
    // some update SQL
    // $NON-NLS-1$
    String sqlCommand = "delete from table where col=?";
    TestableMMPreparedStatement statement = (TestableMMPreparedStatement) getMMPreparedStatement(conn, sqlCommand);
    ArrayList<ArrayList<Object>> expectedParameterValues = new ArrayList<ArrayList<Object>>(3);
    // Add some batches and their parameter values
    expectedParameterValues.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(1) })));
    statement.setInt(1, new Integer(1));
    statement.addBatch();
    expectedParameterValues.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(2) })));
    statement.setInt(1, new Integer(2));
    statement.addBatch();
    expectedParameterValues.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(3) })));
    statement.setInt(1, new Integer(3));
    statement.addBatch();
    // execute the batch and verify that it matches our dummy results
    // message set earlier
    assertTrue(Arrays.equals(new int[] { 0, 0, 0 }, statement.executeBatch()));
    // Now verify the statement's RequestMessage is what we expect
    // $NON-NLS-1$
    assertEquals("Command does not match", sqlCommand, statement.requestMessage.getCommandString());
    // $NON-NLS-1$
    assertEquals("Parameter values do not match", expectedParameterValues, statement.requestMessage.getParameterValues());
    // $NON-NLS-1$
    assertTrue("RequestMessage.isBatchedUpdate should be true", statement.requestMessage.isBatchedUpdate());
    // $NON-NLS-1$
    assertFalse("RequestMessage.isCallableStatement should be false", statement.requestMessage.isCallableStatement());
    // $NON-NLS-1$
    assertTrue("RequestMessage.isPreparedStatement should be true", statement.requestMessage.isPreparedStatement());
    count[0] = 0;
    // large batch handling - should split into 5
    for (int i = 0; i < 100000; i++) {
        statement.setInt(1, new Integer(1));
        statement.addBatch();
    }
    try {
        statement.executeBatch();
        fail();
    } catch (BatchUpdateException e) {
        assertEquals(100000, count[0]);
        assertEquals(95309, e.getUpdateCounts().length);
        assertEquals(Statement.EXECUTE_FAILED, e.getUpdateCounts()[95308]);
    }
}
Also used : ResultsMessage(org.teiid.client.ResultsMessage) LogonResult(org.teiid.client.security.LogonResult) ArrayList(java.util.ArrayList) Properties(java.util.Properties) RequestMessage(org.teiid.client.RequestMessage) ArrayList(java.util.ArrayList) List(java.util.List) BatchUpdateException(java.sql.BatchUpdateException) DQP(org.teiid.client.DQP) ServerConnection(org.teiid.net.ServerConnection) TeiidException(org.teiid.core.TeiidException) ResultsFuture(org.teiid.client.util.ResultsFuture) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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