Search in sources :

Example 16 with SQLOperations

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

Example 17 with SQLOperations

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);
}
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 18 with SQLOperations

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

Example 19 with SQLOperations

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();
}
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 20 with SQLOperations

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 ?, ?"));
}
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)26 Test (org.junit.Test)16 Session (io.crate.action.sql.Session)15 Before (org.junit.Before)14 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)11 User (io.crate.user.User)11 Settings (org.elasticsearch.common.settings.Settings)11 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)10 SessionContext (io.crate.action.sql.SessionContext)9 DependencyCarrier (io.crate.planner.DependencyCarrier)9 List (java.util.List)9 Map (java.util.Map)9 TimeUnit (java.util.concurrent.TimeUnit)9 Nullable (javax.annotation.Nullable)9 DescribeResult (io.crate.action.sql.DescribeResult)8 AccessControl (io.crate.auth.AccessControl)8 AlwaysOKAuthentication (io.crate.auth.AlwaysOKAuthentication)8 Authentication (io.crate.auth.Authentication)8 AuthenticationMethod (io.crate.auth.AuthenticationMethod)8 SQLExecutor (io.crate.testing.SQLExecutor)8