Search in sources :

Example 6 with SQLOperations

use of io.crate.action.sql.SQLOperations in project crate by crate.

the class ConnectionContextTest method testFlushMessageResultsInSyncCallOnSession.

@Test
public void testFlushMessageResultsInSyncCallOnSession() throws Exception {
    SQLOperations sqlOperations = mock(SQLOperations.class);
    SQLOperations.Session session = mock(SQLOperations.Session.class);
    when(sqlOperations.createSession(anyString(), anySetOf(Option.class), anyInt())).thenReturn(session);
    ConnectionContext ctx = new ConnectionContext(sqlOperations);
    DecoderEmbedder<ChannelBuffer> e = new DecoderEmbedder<>(ctx.decoder, ctx.handler);
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    ClientMessages.sendStartupMessage(buffer, "doc");
    ClientMessages.sendParseMessage(buffer, "", "select ?", new int[0]);
    ClientMessages.sendFlush(buffer);
    e.offer(buffer);
    verify(session, times(1)).sync();
}
Also used : DecoderEmbedder(org.jboss.netty.handler.codec.embedder.DecoderEmbedder) Option(io.crate.action.sql.Option) SQLOperations(io.crate.action.sql.SQLOperations) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 7 with SQLOperations

use of io.crate.action.sql.SQLOperations in project crate by crate.

the class ConnectionContextTest method testBindMessageCanBeReadIfTypeForParamsIsUnknown.

@Test
public void testBindMessageCanBeReadIfTypeForParamsIsUnknown() throws Exception {
    ConnectionContext ctx = new ConnectionContext(sqlOperations);
    DecoderEmbedder<ChannelBuffer> e = new DecoderEmbedder<>(ctx.decoder, ctx.handler);
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    ClientMessages.sendStartupMessage(buffer, "doc");
    // no type hints for parameters
    ClientMessages.sendParseMessage(buffer, "S1", "select ?, ?", new int[0]);
    List<Object> params = Arrays.<Object>asList(10, 20);
    ClientMessages.sendBindMessage(buffer, "P1", "S1", params);
    e.offer(buffer);
    SQLOperations.Session session = sessions.get(0);
    // If the query can be retrieved via portalName it means bind worked
    assertThat(session.getQuery("P1"), is("select ?, ?"));
}
Also used : DecoderEmbedder(org.jboss.netty.handler.codec.embedder.DecoderEmbedder) SQLOperations(io.crate.action.sql.SQLOperations) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Aggregations

SQLOperations (io.crate.action.sql.SQLOperations)7 Test (org.junit.Test)4 NodeSettingsService (org.elasticsearch.node.settings.NodeSettingsService)3 Option (io.crate.action.sql.Option)2 JobsLogs (io.crate.operation.collect.stats.JobsLogs)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 ClusterService (org.elasticsearch.cluster.ClusterService)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 DecoderEmbedder (org.jboss.netty.handler.codec.embedder.DecoderEmbedder)2 Before (org.junit.Before)2 DataType (io.crate.types.DataType)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)1 ThreadPool (org.elasticsearch.threadpool.ThreadPool)1 BeforeClass (org.junit.BeforeClass)1