Search in sources :

Example 1 with BlockingEvictingQueue

use of io.crate.common.collections.BlockingEvictingQueue in project crate by crate.

the class JobsLogsTest method testExecutionFailureIsRecordedInMetrics.

@Test
public void testExecutionFailureIsRecordedInMetrics() {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    User user = User.of("arthur");
    Queue<JobContextLog> q = new BlockingEvictingQueue<>(1);
    jobsLogs.updateJobsLog(new QueueSink<>(q, () -> {
    }));
    jobsLogs.logPreExecutionFailure(UUID.randomUUID(), "select foo", "stmt error", user);
    List<MetricsView> metrics = StreamSupport.stream(jobsLogs.metrics().spliterator(), false).collect(Collectors.toList());
    assertThat(metrics.size(), is(1));
    assertThat(metrics.get(0).failedCount(), is(1L));
    assertThat(metrics.get(0).totalCount(), is(1L));
    assertThat(metrics.get(0).classification(), is(new Classification(UNDEFINED)));
}
Also used : User(io.crate.user.User) JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) Classification(io.crate.planner.operators.StatementClassifier.Classification) BlockingEvictingQueue(io.crate.common.collections.BlockingEvictingQueue) MetricsView(io.crate.metadata.sys.MetricsView) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 2 with BlockingEvictingQueue

use of io.crate.common.collections.BlockingEvictingQueue in project crate by crate.

the class RamAccountingQueueSinkTest method testFixedSizeRamAccountingQueueSink.

@Test
public void testFixedSizeRamAccountingQueueSink() throws Exception {
    BlockingEvictingQueue<NoopLog> q = new BlockingEvictingQueue<>(15_000);
    RamAccountingQueue<NoopLog> ramAccountingQueue = new RamAccountingQueue<>(q, breaker(), NOOP_ESTIMATOR);
    logSink = new QueueSink<>(ramAccountingQueue, ramAccountingQueue::release);
    int THREADS = 50;
    final CountDownLatch latch = new CountDownLatch(THREADS);
    List<Thread> threads = new ArrayList<>(20);
    for (int i = 0; i < THREADS; i++) {
        Thread t = new Thread(() -> {
            for (int j = 0; j < 1000; j++) {
                logSink.add(new NoopLog());
            }
            latch.countDown();
        });
        t.start();
        threads.add(t);
    }
    latch.await();
    assertThat(ramAccountingQueue.size(), is(15_000));
    for (Thread thread : threads) {
        thread.join();
    }
}
Also used : ArrayList(java.util.ArrayList) BlockingEvictingQueue(io.crate.common.collections.BlockingEvictingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with BlockingEvictingQueue

use of io.crate.common.collections.BlockingEvictingQueue in project crate by crate.

the class JobsLogsTest method testExecutionFailure.

@Test
public void testExecutionFailure() {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    User user = User.of("arthur");
    Queue<JobContextLog> q = new BlockingEvictingQueue<>(1);
    jobsLogs.updateJobsLog(new QueueSink<>(q, () -> {
    }));
    jobsLogs.logPreExecutionFailure(UUID.randomUUID(), "select foo", "stmt error", user);
    List<JobContextLog> jobsLogEntries = StreamSupport.stream(jobsLogs.jobsLog().spliterator(), false).collect(Collectors.toList());
    assertThat(jobsLogEntries.size(), is(1));
    assertThat(jobsLogEntries.get(0).username(), is(user.name()));
    assertThat(jobsLogEntries.get(0).statement(), is("select foo"));
    assertThat(jobsLogEntries.get(0).errorMessage(), is("stmt error"));
    assertThat(jobsLogEntries.get(0).classification(), is(new Classification(UNDEFINED)));
}
Also used : User(io.crate.user.User) JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) Classification(io.crate.planner.operators.StatementClassifier.Classification) BlockingEvictingQueue(io.crate.common.collections.BlockingEvictingQueue) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 4 with BlockingEvictingQueue

use of io.crate.common.collections.BlockingEvictingQueue in project crate by crate.

the class JobsLogsTest method testUniqueOperationIdsInOperationsTable.

@Test
public void testUniqueOperationIdsInOperationsTable() {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    Queue<OperationContextLog> q = new BlockingEvictingQueue<>(10);
    jobsLogs.updateOperationsLog(new QueueSink<>(q, () -> {
    }));
    OperationContext ctxA = new OperationContext(0, UUID.randomUUID(), "dummyOperation", 1L, () -> -1);
    jobsLogs.operationStarted(ctxA.id, ctxA.jobId, ctxA.name, () -> -1);
    OperationContext ctxB = new OperationContext(0, UUID.randomUUID(), "dummyOperation", 1L, () -> -1);
    jobsLogs.operationStarted(ctxB.id, ctxB.jobId, ctxB.name, () -> 1);
    jobsLogs.operationFinished(ctxB.id, ctxB.jobId, null);
    List<OperationContextLog> entries = StreamSupport.stream(jobsLogs.operationsLog().spliterator(), false).collect(Collectors.toList());
    assertThat(entries, contains(new OperationContextLog(ctxB, null)));
    assertFalse(entries.contains(new OperationContextLog(ctxA, null)));
    jobsLogs.operationFinished(ctxA.id, ctxA.jobId, null);
    entries = StreamSupport.stream(jobsLogs.operationsLog().spliterator(), false).collect(Collectors.toList());
    assertTrue(entries.contains(new OperationContextLog(ctxA, null)));
}
Also used : OperationContext(io.crate.expression.reference.sys.operation.OperationContext) OperationContextLog(io.crate.expression.reference.sys.operation.OperationContextLog) BlockingEvictingQueue(io.crate.common.collections.BlockingEvictingQueue) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

BlockingEvictingQueue (io.crate.common.collections.BlockingEvictingQueue)4 Test (org.junit.Test)4 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)2 Classification (io.crate.planner.operators.StatementClassifier.Classification)2 User (io.crate.user.User)2 OperationContext (io.crate.expression.reference.sys.operation.OperationContext)1 OperationContextLog (io.crate.expression.reference.sys.operation.OperationContextLog)1 MetricsView (io.crate.metadata.sys.MetricsView)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1