Search in sources :

Example 46 with ResultsMessage

use of org.teiid.client.ResultsMessage 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 47 with ResultsMessage

use of org.teiid.client.ResultsMessage 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 48 with ResultsMessage

use of org.teiid.client.ResultsMessage 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 49 with ResultsMessage

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

the class TestAllResultsImpl method testWasNull.

@Test
public void testWasNull() throws SQLException {
    ResultsMessage message = exampleMessage(// $NON-NLS-1$
    new List[] { Arrays.asList((String) null), Arrays.asList("1") }, // $NON-NLS-1$
    new String[] { "string" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
    ResultSetImpl rs = new ResultSetImpl(message, statement);
    assertTrue(rs.next());
    assertEquals(Boolean.FALSE.booleanValue(), rs.getBoolean(1));
    assertTrue(rs.wasNull());
    assertEquals(0, rs.getShort(1));
    assertTrue(rs.wasNull());
    assertEquals(0, rs.getInt(1));
    assertTrue(rs.wasNull());
    assertEquals(0l, rs.getLong(1));
    assertTrue(rs.wasNull());
    assertEquals(0f, rs.getFloat(1), 0);
    assertTrue(rs.wasNull());
    assertEquals(0d, rs.getDouble(1), 0);
    assertTrue(rs.wasNull());
    assertNull(rs.getString(1));
    assertTrue(rs.wasNull());
    assertTrue(rs.next());
    assertEquals(1, rs.getShort(1));
    assertFalse(rs.wasNull());
    assertFalse(rs.next());
}
Also used : ResultsMessage(org.teiid.client.ResultsMessage) Test(org.junit.Test)

Example 50 with ResultsMessage

use of org.teiid.client.ResultsMessage 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

ResultsMessage (org.teiid.client.ResultsMessage)54 Test (org.junit.Test)30 RequestMessage (org.teiid.client.RequestMessage)23 ResultsFuture (org.teiid.client.util.ResultsFuture)13 List (java.util.List)6 DQP (org.teiid.client.DQP)6 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)5 ExecutionException (java.util.concurrent.ExecutionException)4 SQLException (java.sql.SQLException)3 TimeoutException (java.util.concurrent.TimeoutException)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 ParameterInfo (org.teiid.client.metadata.ParameterInfo)3 TeiidComponentException (org.teiid.core.TeiidComponentException)3 TeiidException (org.teiid.core.TeiidException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 BigInteger (java.math.BigInteger)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2