use of org.apache.calcite.avatica.Meta.StatementHandle in project calcite-avatica by apache.
the class ProtobufSerializationTest method testExecuteSerialization.
@Test
public void testExecuteSerialization() throws Exception {
Service.ExecuteRequest executeRequest = new Service.ExecuteRequest(new StatementHandle("connection", 12345, getSignature()), getTypedValues(), 0);
Requests.ExecuteRequest pbExecuteRequest = executeRequest.serialize();
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
pbExecuteRequest.writeTo(baos);
byte[] serialized = baos.toByteArray();
baos.reset();
WireMessage wireMsg = WireMessage.newBuilder().setName(Requests.ExecuteRequest.class.getName()).setWrappedMessage(UnsafeByteOperations.unsafeWrap(serialized)).build();
wireMsg.writeTo(baos);
serialized = baos.toByteArray();
ProtobufTranslation translator = new ProtobufTranslationImpl();
Request newRequest = translator.parseRequest(serialized);
Assert.assertEquals(executeRequest, newRequest);
}
use of org.apache.calcite.avatica.Meta.StatementHandle in project calcite-avatica by apache.
the class JdbcMetaTest method testPrepareAndExecuteSetsMaxRows.
@Test
public void testPrepareAndExecuteSetsMaxRows() throws Exception {
final String id = UUID.randomUUID().toString();
final int statementId = 12345;
final String sql = "SELECT * FROM FOO";
final int maxRows = 500;
JdbcMeta meta = Mockito.mock(JdbcMeta.class);
PreparedStatement statement = Mockito.mock(PreparedStatement.class);
@SuppressWarnings("unchecked") Cache<Integer, StatementInfo> statementCache = (Cache<Integer, StatementInfo>) Mockito.mock(Cache.class);
Signature signature = Mockito.mock(Signature.class);
final StatementInfo statementInfo = new StatementInfo(statement);
final StatementHandle statementHandle = new StatementHandle(id, statementId, signature);
Mockito.when(meta.getStatementCache()).thenReturn(statementCache);
Mockito.when(statementCache.getIfPresent(statementId)).thenReturn(statementInfo);
Mockito.when(statement.getResultSet()).thenReturn(null);
// The real methods
Mockito.when(meta.prepareAndExecute(statementHandle, sql, maxRows, 50, null)).thenCallRealMethod();
Mockito.doCallRealMethod().when(meta).setMaxRows(statement, maxRows);
// Call our method
meta.prepareAndExecute(statementHandle, sql, maxRows, 50, null);
// Verify we called setMaxRows with the right value
Mockito.verify(statement).setMaxRows(maxRows);
}
Aggregations