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)));
}
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();
}
}
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)));
}
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)));
}
Aggregations