Search in sources :

Example 6 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class TransportDistributedResultActionTest method testKillIsInvokedIfContextIsNotFound.

@Test
public void testKillIsInvokedIfContextIsNotFound() throws Exception {
    TasksService tasksService = new TasksService(clusterService, new JobsLogs(() -> false));
    AtomicInteger numBroadcasts = new AtomicInteger(0);
    TransportKillJobsNodeAction killJobsAction = new TransportKillJobsNodeAction(tasksService, clusterService, mock(TransportService.class)) {

        @Override
        public void broadcast(KillJobsRequest request, ActionListener<Long> listener, Collection<String> excludedNodeIds) {
            numBroadcasts.incrementAndGet();
        }
    };
    TransportDistributedResultAction transportDistributedResultAction = new TransportDistributedResultAction(mock(Transports.class), tasksService, THREAD_POOL, mock(TransportService.class), clusterService, killJobsAction, BackoffPolicy.exponentialBackoff(TimeValue.ZERO, 0));
    StreamBucket.Builder builder = new StreamBucket.Builder(new Streamer[0], RamAccounting.NO_ACCOUNTING);
    try {
        transportDistributedResultAction.nodeOperation(new DistributedResultRequest(UUID.randomUUID(), 0, (byte) 0, 0, builder.build(), true)).get(5, TimeUnit.SECONDS);
        fail("nodeOperation call should fail with TaskMissing");
    } catch (ExecutionException e) {
        assertThat(e.getCause(), Matchers.instanceOf(TaskMissing.class));
    }
    assertThat(numBroadcasts.get(), is(1));
}
Also used : TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) Transports(io.crate.execution.support.Transports) TasksService(io.crate.execution.jobs.TasksService) ActionListener(org.elasticsearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransportService(org.elasticsearch.transport.TransportService) KillJobsRequest(io.crate.execution.jobs.kill.KillJobsRequest) Collection(java.util.Collection) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 7 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class BatchPortalTest method testEachStatementReceivesCorrectParams.

@Test
public void testEachStatementReceivesCorrectParams() throws Throwable {
    SQLExecutor sqlExecutor = SQLExecutor.builder(clusterService).addTable("create table t1 (x int)").build();
    Plan insertPlan = new Plan() {

        @Override
        public StatementType type() {
            return StatementType.INSERT;
        }

        @Override
        public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
            consumer.accept(InMemoryBatchIterator.of(params, null), null);
        }
    };
    Planner planner = new Planner(Settings.EMPTY, clusterService, sqlExecutor.nodeCtx, new TableStats(), null, null, sqlExecutor.schemas(), new StubUserManager(), mock(SessionSettingRegistry.class)) {

        @Override
        public Plan plan(AnalyzedStatement analyzedStatement, PlannerContext plannerContext) {
            return insertPlan;
        }
    };
    DependencyCarrier executor = mock(DependencyCarrier.class, Answers.RETURNS_MOCKS);
    Session session = new Session(sqlExecutor.nodeCtx, sqlExecutor.analyzer, planner, new JobsLogs(() -> false), false, executor, AccessControl.DISABLED, SessionContext.systemSessionContext());
    session.parse("S_1", "insert into t1(x) values(1)", Collections.emptyList());
    session.bind("Portal", "S_1", Collections.emptyList(), null);
    final ArrayList<Object[]> s1Rows = new ArrayList<>();
    session.execute("Portal", 0, new BaseResultReceiver() {

        @Override
        public void setNextRow(Row row) {
            s1Rows.add(row.materialize());
        }
    });
    session.parse("S_2", "insert into t1(x) values(?)", Collections.emptyList());
    session.bind("Portal", "S_2", Collections.singletonList(2), null);
    final ArrayList<Object[]> s2Rows = new ArrayList<>();
    session.execute("Portal", 0, new BaseResultReceiver() {

        @Override
        public void setNextRow(Row row) {
            s2Rows.add(row.materialize());
        }
    });
    session.sync().get(5, TimeUnit.SECONDS);
    assertThat(s1Rows, contains(emptyArray()));
    assertThat(s2Rows, contains(arrayContaining(is(2))));
}
Also used : DependencyCarrier(io.crate.planner.DependencyCarrier) SubQueryResults(io.crate.planner.operators.SubQueryResults) ArrayList(java.util.ArrayList) Plan(io.crate.planner.Plan) TableStats(io.crate.statistics.TableStats) StubUserManager(io.crate.user.StubUserManager) SessionSettingRegistry(io.crate.metadata.settings.session.SessionSettingRegistry) PlannerContext(io.crate.planner.PlannerContext) SQLExecutor(io.crate.testing.SQLExecutor) BaseResultReceiver(io.crate.action.sql.BaseResultReceiver) Planner(io.crate.planner.Planner) AnalyzedStatement(io.crate.analyze.AnalyzedStatement) RowConsumer(io.crate.data.RowConsumer) Row(io.crate.data.Row) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) Session(io.crate.action.sql.Session) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 8 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class PostgresWireProtocolTest method prepare.

@Before
public void prepare() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table users (name text not null)").build();
    sqlOperations = new SQLOperations(e.nodeCtx, e.analyzer, e.planner, () -> mock(DependencyCarrier.class), new JobsLogs(() -> true), Settings.EMPTY, clusterService, USER_MANAGER_PROVIDER) {

        @Override
        public Session createSession(@Nullable String defaultSchema, @Nullable User user) {
            Session session = super.createSession(defaultSchema, user);
            sessions.add(session);
            return session;
        }
    };
}
Also used : User(io.crate.user.User) SQLExecutor(io.crate.testing.SQLExecutor) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) SecureString(org.elasticsearch.common.settings.SecureString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SQLOperations(io.crate.action.sql.SQLOperations) Session(io.crate.action.sql.Session) Before(org.junit.Before)

Example 9 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class RemoteCollectorTest method prepare.

@Before
public void prepare() {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(Map.of("remoteNode", Map.of("dummyTable", IntArrayList.from(1)))), RowGranularity.DOC, Collections.singletonList(createReference("name", DataTypes.STRING)), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    TasksService tasksService = new TasksService(clusterService, new JobsLogs(() -> true));
    numBroadcastCalls = new AtomicInteger(0);
    transportKillJobsNodeAction = new TransportKillJobsNodeAction(tasksService, clusterService, mock(TransportService.class)) {

        @Override
        public void broadcast(KillJobsRequest request, ActionListener<Long> listener) {
            numBroadcastCalls.incrementAndGet();
        }
    };
    consumer = new TestingRowConsumer();
    remoteCollector = new RemoteCollector(jobId, new SessionSettings("dummyUser", SearchPath.createSearchPathFrom("dummySchema")), "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, Runnable::run, tasksService, RamAccounting.NO_ACCOUNTING, consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.execution.jobs.transport.TransportJobAction) TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TasksService(io.crate.execution.jobs.TasksService) SessionSettings(io.crate.metadata.settings.SessionSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KillJobsRequest(io.crate.execution.jobs.kill.KillJobsRequest) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Before(org.junit.Before)

Example 10 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class KillPlanTest method testKillTaskCallsBroadcastOnTransportKillAllNodeAction.

@Test
public void testKillTaskCallsBroadcastOnTransportKillAllNodeAction() {
    AtomicInteger broadcastCalls = new AtomicInteger(0);
    AtomicInteger nodeOperationCalls = new AtomicInteger(0);
    TransportKillAllNodeAction killAllNodeAction = new TransportKillAllNodeAction(new TasksService(clusterService, new JobsLogs(() -> false)), clusterService, mock(TransportService.class)) {

        @Override
        public void broadcast(KillAllRequest request, ActionListener<Long> listener) {
            broadcastCalls.incrementAndGet();
        }

        @Override
        public CompletableFuture<KillResponse> nodeOperation(KillAllRequest request) {
            nodeOperationCalls.incrementAndGet();
            return super.nodeOperation(request);
        }
    };
    KillPlan killPlan = new KillPlan(null);
    killPlan.execute(null, "dummy-user", killAllNodeAction, mock(TransportKillJobsNodeAction.class), new TestingRowConsumer());
    assertThat(broadcastCalls.get(), is(1));
    assertThat(nodeOperationCalls.get(), is(0));
}
Also used : TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) KillAllRequest(io.crate.execution.jobs.kill.KillAllRequest) ActionListener(org.elasticsearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransportService(org.elasticsearch.transport.TransportService) TransportKillAllNodeAction(io.crate.execution.jobs.kill.TransportKillAllNodeAction) TasksService(io.crate.execution.jobs.TasksService) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) KillResponse(io.crate.execution.jobs.kill.KillResponse) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)14 UUID (java.util.UUID)5 AnalyzedStatement (io.crate.analyze.AnalyzedStatement)4 Row (io.crate.data.Row)4 RowConsumer (io.crate.data.RowConsumer)4 TasksService (io.crate.execution.jobs.TasksService)4 DependencyCarrier (io.crate.planner.DependencyCarrier)4 Plan (io.crate.planner.Plan)4 Planner (io.crate.planner.Planner)4 PlannerContext (io.crate.planner.PlannerContext)4 SubQueryResults (io.crate.planner.operators.SubQueryResults)4 Test (org.junit.Test)4 AnalyzedBegin (io.crate.analyze.AnalyzedBegin)3 AnalyzedCommit (io.crate.analyze.AnalyzedCommit)3 AnalyzedDeallocate (io.crate.analyze.AnalyzedDeallocate)3 AnalyzedDiscard (io.crate.analyze.AnalyzedDiscard)3 Analyzer (io.crate.analyze.Analyzer)3 ParamTypeHints (io.crate.analyze.ParamTypeHints)3 QueriedSelectRelation (io.crate.analyze.QueriedSelectRelation)3 Relations (io.crate.analyze.Relations)3