use of io.crate.action.sql.Session in project crate by crate.
the class SQLIntegrationTestCase method executeWith.
/**
* Executes {@code statement} once for each entry in {@code setSessionStatementsList}
*
* The inner lists of {@code setSessionStatementsList} will be executed before the statement is executed.
* This is intended to change session settings using `SET ..` statements
*
* @param matcher matcher used to assert the result of {@code statement}
*/
public void executeWith(List<List<String>> setSessionStatementsList, String statement, Matcher<SQLResponse> matcher) {
for (List<String> setSessionStatements : setSessionStatementsList) {
try (Session session = sqlExecutor.newSession()) {
for (String setSessionStatement : setSessionStatements) {
sqlExecutor.exec(setSessionStatement, session);
}
SQLResponse resp = sqlExecutor.exec(statement, session);
assertThat("The query:\n\t" + statement + "\nwith session statements: [" + String.join(", ", setSessionStatements) + "] must produce correct result", resp, matcher);
}
}
}
use of io.crate.action.sql.Session 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.Session 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.Session in project crate by crate.
the class TableStatsServiceTest method testStatsQueriesCorrectly.
@Test
public void testStatsQueriesCorrectly() {
SQLOperations sqlOperations = Mockito.mock(SQLOperations.class);
Session session = Mockito.mock(Session.class);
Mockito.when(sqlOperations.newSystemSession()).thenReturn(session);
TableStatsService statsService = new TableStatsService(Settings.EMPTY, THREAD_POOL, clusterService, sqlOperations);
statsService.run();
Mockito.verify(session, Mockito.times(1)).quickExec(ArgumentMatchers.eq(TableStatsService.STMT), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
}
use of io.crate.action.sql.Session in project crate by crate.
the class TableStatsServiceTest method testNoUpdateIfLocalNodeNotAvailable.
@Test
public void testNoUpdateIfLocalNodeNotAvailable() {
final ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.localNode()).thenReturn(null);
Mockito.when(clusterService.getClusterSettings()).thenReturn(this.clusterService.getClusterSettings());
SQLOperations sqlOperations = Mockito.mock(SQLOperations.class);
Session session = Mockito.mock(Session.class);
Mockito.when(sqlOperations.createSession(ArgumentMatchers.anyString(), ArgumentMatchers.any())).thenReturn(session);
TableStatsService statsService = new TableStatsService(Settings.EMPTY, THREAD_POOL, clusterService, sqlOperations);
statsService.run();
Mockito.verify(session, Mockito.times(0)).sync();
}
Aggregations