Search in sources :

Example 1 with StatementHandle

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);
}
Also used : StatementHandle(org.apache.calcite.avatica.Meta.StatementHandle) Request(org.apache.calcite.avatica.remote.Service.Request) WireMessage(org.apache.calcite.avatica.proto.Common.WireMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Requests(org.apache.calcite.avatica.proto.Requests) Test(org.junit.Test)

Example 2 with StatementHandle

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StatementHandle(org.apache.calcite.avatica.Meta.StatementHandle) Signature(org.apache.calcite.avatica.Meta.Signature) PreparedStatement(java.sql.PreparedStatement) AvaticaPreparedStatement(org.apache.calcite.avatica.AvaticaPreparedStatement) Cache(com.google.common.cache.Cache) Test(org.junit.Test)

Aggregations

StatementHandle (org.apache.calcite.avatica.Meta.StatementHandle)2 Test (org.junit.Test)2 Cache (com.google.common.cache.Cache)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PreparedStatement (java.sql.PreparedStatement)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AvaticaPreparedStatement (org.apache.calcite.avatica.AvaticaPreparedStatement)1 Signature (org.apache.calcite.avatica.Meta.Signature)1 WireMessage (org.apache.calcite.avatica.proto.Common.WireMessage)1 Requests (org.apache.calcite.avatica.proto.Requests)1 Request (org.apache.calcite.avatica.remote.Service.Request)1