Search in sources :

Example 11 with Session

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);
        }
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Session(io.crate.action.sql.Session)

Example 12 with Session

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;
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) SQLOperations(io.crate.action.sql.SQLOperations) Session(io.crate.action.sql.Session)

Example 13 with Session

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);
}
Also used : User(io.crate.user.User) UserLookup(io.crate.user.UserLookup) SQLOperations(io.crate.action.sql.SQLOperations) Session(io.crate.action.sql.Session)

Example 14 with 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());
}
Also used : SQLOperations(io.crate.action.sql.SQLOperations) Session(io.crate.action.sql.Session) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 15 with Session

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();
}
Also used : ClusterService(org.elasticsearch.cluster.service.ClusterService) SQLOperations(io.crate.action.sql.SQLOperations) Session(io.crate.action.sql.Session) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

Session (io.crate.action.sql.Session)19 SQLOperations (io.crate.action.sql.SQLOperations)12 Test (org.junit.Test)9 User (io.crate.user.User)8 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)7 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)7 SQLExecutor (io.crate.testing.SQLExecutor)6 ByteBuf (io.netty.buffer.ByteBuf)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 SessionContext (io.crate.action.sql.SessionContext)5 AccessControl (io.crate.auth.AccessControl)5 DependencyCarrier (io.crate.planner.DependencyCarrier)5 PGTypes (io.crate.protocols.postgres.types.PGTypes)5 DataTypes (io.crate.types.DataTypes)5 StubUserManager (io.crate.user.StubUserManager)5 Unpooled (io.netty.buffer.Unpooled)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Arrays (java.util.Arrays)5 Collections (java.util.Collections)5