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());
}
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();
}
}
}
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());
}
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());
}
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);
}
Aggregations