use of io.crate.action.sql.SQLOperations in project crate by crate.
the class SQLIntegrationTestCase method execute.
public SQLResponse execute(String stmt, Object[] args, String node, TimeValue timeout) {
SQLOperations sqlOperations = internalCluster().getInstance(SQLOperations.class, node);
try (Session session = sqlOperations.createSession(sqlExecutor.getCurrentSchema(), User.CRATE_USER)) {
SQLResponse response = sqlExecutor.exec(stmt, args, session, timeout);
this.response = response;
return response;
}
}
use of io.crate.action.sql.SQLOperations in project crate by crate.
the class BaseUsersIntegrationTest method executeAs.
public SQLResponse executeAs(String stmt, String userName) {
SQLOperations sqlOperations = internalCluster().getInstance(SQLOperations.class);
UserLookup userLookup = internalCluster().getInstance(UserLookup.class);
User user = Objects.requireNonNull(userLookup.findUser(userName), "User " + userName + " must exist");
Session session = sqlOperations.createSession(null, user);
return execute(stmt, null, session);
}
use of io.crate.action.sql.SQLOperations in project crate by crate.
the class TableStatsServiceTest method testNoUpdateIfLocalNodeNotAvailable.
@Test
public void testNoUpdateIfLocalNodeNotAvailable() throws Exception {
final ClusterService clusterService = mock(ClusterService.class);
when(clusterService.localNode()).thenReturn(null);
SQLOperations sqlOperations = mock(SQLOperations.class);
SQLOperations.Session session = mock(SQLOperations.Session.class);
when(sqlOperations.createSession(anyString(), any(), anyInt())).thenReturn(session);
TableStatsService statsService = new TableStatsService(Settings.EMPTY, threadPool, clusterService, new TableStats(), new NodeSettingsService(Settings.EMPTY), sqlOperations);
statsService.run();
Mockito.verify(session, times(0)).sync();
}
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