Search in sources :

Example 6 with DQP

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

the class TestStatement method testWarnings.

@Test
public void testWarnings() throws Exception {
    ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
    Mockito.stub(conn.getConnectionProps()).toReturn(new Properties());
    DQP dqp = Mockito.mock(DQP.class);
    ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>();
    Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject())).toReturn(results);
    ResultsMessage rm = new ResultsMessage();
    rm.setResults(new List<?>[] { Arrays.asList(1) });
    rm.setWarnings(Arrays.asList(new Throwable()));
    rm.setColumnNames(new String[] { "expr1" });
    rm.setDataTypes(new String[] { "string" });
    results.getResultsReceiver().receiveResults(rm);
    Mockito.stub(conn.getDQP()).toReturn(dqp);
    StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) {

        @Override
        protected java.util.TimeZone getServerTimeZone() throws java.sql.SQLException {
            return null;
        }
    };
    statement.execute("select 'a'");
    assertNotNull(statement.getResultSet());
    SQLWarning warning = statement.getWarnings();
    assertNotNull(warning);
    assertNull(warning.getNextWarning());
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) SQLWarning(java.sql.SQLWarning) DQP(org.teiid.client.DQP) ResultsMessage(org.teiid.client.ResultsMessage) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with DQP

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

the class TestStatement method testAsynchTimeout.

@Test
public void testAsynchTimeout() throws Exception {
    ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
    Mockito.stub(conn.getConnectionProps()).toReturn(new Properties());
    final StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    statement.setQueryTimeoutMS(1);
    DQP dqp = Mockito.mock(DQP.class);
    Mockito.stub(statement.getDQP()).toReturn(dqp);
    final AtomicInteger counter = new AtomicInteger();
    Mockito.stub(dqp.cancelRequest(0)).toAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            synchronized (statement) {
                counter.incrementAndGet();
                statement.notifyAll();
            }
            return true;
        }
    });
    ResultsFuture<ResultsMessage> future = new ResultsFuture<ResultsMessage>();
    Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject())).toReturn(future);
    statement.submitExecute("select 'hello world'", null);
    synchronized (statement) {
        while (counter.get() != 1) {
            statement.wait();
        }
    }
    statement.setQueryTimeoutMS(1);
    statement.submitExecute("select 'hello world'", null);
    synchronized (statement) {
        while (counter.get() != 2) {
            statement.wait();
        }
    }
}
Also used : DQP(org.teiid.client.DQP) ResultsMessage(org.teiid.client.ResultsMessage) Properties(java.util.Properties) ResultsFuture(org.teiid.client.util.ResultsFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 8 with DQP

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

the class TestStatement method testGetMoreResults.

@Test
public void testGetMoreResults() throws Exception {
    ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
    Mockito.stub(conn.getConnectionProps()).toReturn(new Properties());
    DQP dqp = Mockito.mock(DQP.class);
    ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>();
    Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject())).toReturn(results);
    ResultsMessage rm = new ResultsMessage();
    rm.setUpdateResult(true);
    rm.setColumnNames(new String[] { "expr1" });
    rm.setDataTypes(new String[] { "integer" });
    rm.setResults(new List<?>[] { Arrays.asList(1) });
    results.getResultsReceiver().receiveResults(rm);
    Mockito.stub(conn.getDQP()).toReturn(dqp);
    StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) {

        @Override
        protected java.util.TimeZone getServerTimeZone() throws java.sql.SQLException {
            return null;
        }
    };
    statement.execute("update x set a = b");
    assertEquals(1, statement.getUpdateCount());
    statement.getMoreResults(Statement.CLOSE_ALL_RESULTS);
    assertEquals(-1, statement.getUpdateCount());
    statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) {

        @Override
        protected java.util.TimeZone getServerTimeZone() throws java.sql.SQLException {
            return null;
        }
    };
    statement.execute("update x set a = b");
    assertEquals(1, statement.getUpdateCount());
    statement.getMoreResults();
    assertEquals(-1, statement.getUpdateCount());
}
Also used : DQP(org.teiid.client.DQP) SQLException(java.sql.SQLException) ResultsMessage(org.teiid.client.ResultsMessage) Properties(java.util.Properties) ResultsFuture(org.teiid.client.util.ResultsFuture) TimeZone(java.util.TimeZone) Test(org.junit.Test)

Example 9 with DQP

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

the class TestStatement method testDisableLocalTransations.

@Test
public void testDisableLocalTransations() throws Exception {
    ServerConnection mock = Mockito.mock(ServerConnection.class);
    DQP dqp = Mockito.mock(DQP.class);
    Mockito.stub(mock.getService(DQP.class)).toReturn(dqp);
    ConnectionImpl conn = new ConnectionImpl(mock, new Properties(), "x");
    StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    assertTrue(conn.getAutoCommit());
    statement.execute("set disablelocaltxn true");
    // $NON-NLS-1$
    assertFalse(statement.execute("start transaction"));
    conn.beginLocalTxnIfNeeded();
    assertFalse(conn.isInLocalTxn());
    statement.execute("set disablelocaltxn false");
    // $NON-NLS-1$
    assertFalse(statement.execute("start transaction"));
    conn.beginLocalTxnIfNeeded();
    assertTrue(conn.isInLocalTxn());
}
Also used : DQP(org.teiid.client.DQP) ServerConnection(org.teiid.net.ServerConnection) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with DQP

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

the class TestAllResultsImpl method helpTestBatching.

static ResultSetImpl helpTestBatching(StatementImpl statement, final int fetchSize, final int batchLength, final int totalLength, final boolean partial) throws TeiidProcessingException, SQLException {
    DQP dqp = statement.getDQP();
    if (dqp == null) {
        dqp = mock(DQP.class);
        stub(statement.getDQP()).toReturn(dqp);
    }
    stub(statement.getFetchSize()).toReturn(fetchSize);
    stub(dqp.processCursorRequest(Matchers.eq(REQUEST_ID), Matchers.anyInt(), Matchers.eq(fetchSize))).toAnswer(new Answer<ResultsFuture<ResultsMessage>>() {

        @Override
        public ResultsFuture<ResultsMessage> answer(InvocationOnMock invocation) throws Throwable {
            ResultsFuture<ResultsMessage> nextBatch = new ResultsFuture<ResultsMessage>();
            int begin = Math.min(totalLength, (Integer) invocation.getArguments()[1]);
            if (partial && begin == fetchSize + 1) {
                begin = begin - 5;
            }
            int length = Math.min(fetchSize, Math.min(totalLength - begin + 1, batchLength));
            nextBatch.getResultsReceiver().receiveResults(exampleResultsMsg4(begin, length, begin + length - 1 >= totalLength));
            return nextBatch;
        }
    });
    int initial = Math.min(fetchSize, batchLength);
    ResultsMessage msg = exampleResultsMsg4(1, initial, initial == totalLength);
    return new ResultSetImpl(msg, statement, new ResultSetMetaDataImpl(new MetadataProvider(DeferredMetadataProvider.loadPartialMetadata(msg.getColumnNames(), msg.getDataTypes())), null), 0);
}
Also used : DQP(org.teiid.client.DQP) ResultsMessage(org.teiid.client.ResultsMessage) ResultsFuture(org.teiid.client.util.ResultsFuture) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Aggregations

DQP (org.teiid.client.DQP)12 Properties (java.util.Properties)9 Test (org.junit.Test)7 ResultsFuture (org.teiid.client.util.ResultsFuture)7 ResultsMessage (org.teiid.client.ResultsMessage)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 SQLException (java.sql.SQLException)3 LogonResult (org.teiid.client.security.LogonResult)3 ConnectionException (org.teiid.net.ConnectionException)3 ServerConnection (org.teiid.net.ServerConnection)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 InvalidSessionException (org.teiid.client.security.InvalidSessionException)2 SessionToken (org.teiid.client.security.SessionToken)2 TeiidException (org.teiid.core.TeiidException)2 CommunicationException (org.teiid.net.CommunicationException)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 BatchUpdateException (java.sql.BatchUpdateException)1