Search in sources :

Example 1 with SQLOperations

use of io.crate.action.sql.SQLOperations in project crate by crate.

the class QueryStatsTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    SQLOperations sqlOperations = mock(SQLOperations.class);
    when(sqlOperations.createSession(anyString(), anyObject(), anyInt())).thenReturn(session);
    doNothing().when(session).parse(anyString(), anyString(), anyListOf(DataType.class));
    queryStats = spy(new QueryStats(sqlOperations, Settings.EMPTY));
}
Also used : DataType(io.crate.types.DataType) SQLOperations(io.crate.action.sql.SQLOperations) BeforeClass(org.junit.BeforeClass)

Example 2 with SQLOperations

use of io.crate.action.sql.SQLOperations in project crate by crate.

the class ConnectionContextTest method setUp.

@Before
public void setUp() throws Exception {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    sqlOperations = new SQLOperations(e.analyzer, e.planner, () -> mock(Executor.class), jobsLogs, Settings.EMPTY, clusterService) {

        @Override
        public Session createSession(@Nullable String defaultSchema, Set<Option> options, int defaultLimit) {
            Session session = super.createSession(defaultSchema, options, defaultLimit);
            sessions.add(session);
            return session;
        }
    };
}
Also used : Option(io.crate.action.sql.Option) JobsLogs(io.crate.operation.collect.stats.JobsLogs) SQLOperations(io.crate.action.sql.SQLOperations) Before(org.junit.Before)

Example 3 with SQLOperations

use of io.crate.action.sql.SQLOperations in project crate by crate.

the class DecommissioningServiceTest method setUp.

@Before
public void setUp() throws Exception {
    NodeSettingsService settingsService = new NodeSettingsService(Settings.EMPTY);
    threadPool = mock(ThreadPool.class, Answers.RETURNS_MOCKS.get());
    jobsLogs = new JobsLogs(() -> true);
    sqlOperations = mock(SQLOperations.class, Answers.RETURNS_MOCKS.get());
    decommissioningService = new TestableDecommissioningService(Settings.EMPTY, new NoopClusterService(), jobsLogs, threadPool, settingsService, sqlOperations, mock(TransportClusterHealthAction.class), mock(TransportClusterUpdateSettingsAction.class));
}
Also used : ThreadPool(org.elasticsearch.threadpool.ThreadPool) JobsLogs(io.crate.operation.collect.stats.JobsLogs) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) SQLOperations(io.crate.action.sql.SQLOperations) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Example 4 with SQLOperations

use of io.crate.action.sql.SQLOperations in project crate by crate.

the class TableStatsServiceTest method testStatsQueriesCorrectly.

@Test
public void testStatsQueriesCorrectly() throws Throwable {
    ClusterService clusterService = mock(ClusterService.class);
    when(clusterService.localNode()).thenReturn(mock(DiscoveryNode.class));
    final SQLOperations sqlOperations = mock(SQLOperations.class);
    SQLOperations.SQLDirectExecutor sqlDirectExecutor = mock(SQLOperations.SQLDirectExecutor.class);
    when(sqlOperations.createSQLDirectExecutor(eq("sys"), eq(TableStatsService.TABLE_STATS), eq(TableStatsService.STMT), eq(TableStatsService.DEFAULT_SOFT_LIMIT))).thenReturn(sqlDirectExecutor);
    TableStatsService statsService = new TableStatsService(Settings.EMPTY, threadPool, clusterService, new TableStats(), new NodeSettingsService(Settings.EMPTY), sqlOperations);
    statsService.run();
    verify(sqlDirectExecutor, times(1)).execute(any(TableStatsService.TableStatsResultReceiver.class), eq(Collections.emptyList()));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) 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 5 with SQLOperations

use of io.crate.action.sql.SQLOperations in project crate by crate.

the class PreExecutionBenchmark method setup.

@Setup
public void setup() throws Exception {
    Path tempDir = Files.createTempDirectory("");
    Settings settings = Settings.builder().put("path.home", tempDir.toAbsolutePath().toString()).build();
    Environment environment = new Environment(settings, tempDir);
    node = new Node(environment, List.of(Netty4Plugin.class), true);
    node.start();
    Injector injector = node.injector();
    sqlOperations = injector.getInstance(SQLOperations.class);
    analyzer = injector.getInstance(Analyzer.class);
    planner = injector.getInstance(Planner.class);
    clusterService = injector.getInstance(ClusterService.class);
    nodeCtx = injector.getInstance(NodeContext.class);
    String statement = "create table users (id int primary key, name string, date timestamp, text string index using fulltext)";
    var resultReceiver = new BaseResultReceiver();
    sqlOperations.newSystemSession().quickExec(statement, resultReceiver, Row.EMPTY);
    resultReceiver.completionFuture().get(5, TimeUnit.SECONDS);
}
Also used : Path(java.nio.file.Path) NodeContext(io.crate.metadata.NodeContext) Node(org.elasticsearch.node.Node) ClusterService(org.elasticsearch.cluster.service.ClusterService) Injector(org.elasticsearch.common.inject.Injector) Environment(org.elasticsearch.env.Environment) BaseResultReceiver(io.crate.action.sql.BaseResultReceiver) Planner(io.crate.planner.Planner) SQLOperations(io.crate.action.sql.SQLOperations) Settings(org.elasticsearch.common.settings.Settings) Setup(org.openjdk.jmh.annotations.Setup)

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