Search in sources :

Example 11 with SequenceWrapper

use of org.apache.druid.java.util.common.guava.SequenceWrapper in project druid by druid-io.

the class QuerySchedulerTest method testHiLoLo.

@Test
public void testHiLoLo() throws ExecutionException, InterruptedException {
    TopNQuery report = makeReportQuery();
    ListenableFuture<?> future = executorService.submit(() -> {
        try {
            Query<?> scheduledReport = scheduler.prioritizeAndLaneQuery(QueryPlus.wrap(report), ImmutableSet.of());
            Assert.assertNotNull(scheduledReport);
            Assert.assertEquals(HiLoQueryLaningStrategy.LOW, QueryContexts.getLane(scheduledReport));
            Sequence<Integer> underlyingSequence = makeSequence(10);
            underlyingSequence = Sequences.wrap(underlyingSequence, new SequenceWrapper() {

                @Override
                public void before() {
                    Assert.assertEquals(4, scheduler.getTotalAvailableCapacity());
                    Assert.assertEquals(1, scheduler.getLaneAvailableCapacity(HiLoQueryLaningStrategy.LOW));
                }
            });
            Sequence<Integer> results = scheduler.run(scheduledReport, underlyingSequence);
            int rowCount = consumeAndCloseSequence(results);
            Assert.assertEquals(10, rowCount);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    });
    future.get();
    assertHiLoHasAllCapacity(TEST_HI_CAPACITY, TEST_LO_CAPACITY);
    Assert.assertEquals(QueryScheduler.UNAVAILABLE, scheduler.getLaneAvailableCapacity("non-existent"));
}
Also used : SequenceWrapper(org.apache.druid.java.util.common.guava.SequenceWrapper) TopNQuery(org.apache.druid.query.topn.TopNQuery) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with SequenceWrapper

use of org.apache.druid.java.util.common.guava.SequenceWrapper in project druid by druid-io.

the class QuerySchedulerTest method testHiLoHi.

@Test
public void testHiLoHi() throws ExecutionException, InterruptedException {
    TopNQuery interactive = makeInteractiveQuery();
    ListenableFuture<?> future = executorService.submit(() -> {
        try {
            Query<?> scheduled = scheduler.prioritizeAndLaneQuery(QueryPlus.wrap(interactive), ImmutableSet.of());
            Assert.assertNotNull(scheduled);
            Sequence<Integer> underlyingSequence = makeSequence(10);
            underlyingSequence = Sequences.wrap(underlyingSequence, new SequenceWrapper() {

                @Override
                public void before() {
                    Assert.assertEquals(4, scheduler.getTotalAvailableCapacity());
                    Assert.assertEquals(2, scheduler.getLaneAvailableCapacity(HiLoQueryLaningStrategy.LOW));
                }
            });
            Sequence<Integer> results = scheduler.run(scheduled, underlyingSequence);
            int rowCount = consumeAndCloseSequence(results);
            Assert.assertEquals(10, rowCount);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    });
    future.get();
    Assert.assertEquals(TEST_HI_CAPACITY, scheduler.getTotalAvailableCapacity());
    Assert.assertEquals(QueryScheduler.UNAVAILABLE, scheduler.getLaneAvailableCapacity("non-existent"));
}
Also used : SequenceWrapper(org.apache.druid.java.util.common.guava.SequenceWrapper) TopNQuery(org.apache.druid.query.topn.TopNQuery) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

SequenceWrapper (org.apache.druid.java.util.common.guava.SequenceWrapper)12 IOException (java.io.IOException)4 Sequence (org.apache.druid.java.util.common.guava.Sequence)4 TopNQuery (org.apache.druid.query.topn.TopNQuery)3 Test (org.junit.Test)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)2 Result (org.apache.druid.query.Result)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Function (com.google.common.base.Function)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1