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