Search in sources :

Example 1 with DecoderEmbedder

use of org.jboss.netty.handler.codec.embedder.DecoderEmbedder 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 2 with DecoderEmbedder

use of org.jboss.netty.handler.codec.embedder.DecoderEmbedder 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)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 DecoderEmbedder (org.jboss.netty.handler.codec.embedder.DecoderEmbedder)2 Test (org.junit.Test)2 Option (io.crate.action.sql.Option)1