Search in sources :

Example 21 with ServerConfig

use of org.apache.druid.server.initialization.ServerConfig in project druid by druid-io.

the class QueryResourceTest method testTooManyQueryInLaneImplicitFromDurationThreshold.

@Test(timeout = 10_000L)
public void testTooManyQueryInLaneImplicitFromDurationThreshold() throws InterruptedException {
    expectPermissiveHappyPathAuth();
    final CountDownLatch waitTwoStarted = new CountDownLatch(2);
    final CountDownLatch waitOneScheduled = new CountDownLatch(1);
    final CountDownLatch waitAllFinished = new CountDownLatch(3);
    final QueryScheduler scheduler = new QueryScheduler(40, new ThresholdBasedQueryPrioritizationStrategy(null, "P90D", null, null), new HiLoQueryLaningStrategy(1), new ServerConfig());
    createScheduledQueryResource(scheduler, ImmutableList.of(waitTwoStarted), ImmutableList.of(waitOneScheduled));
    assertResponseAndCountdownOrBlockForever(SIMPLE_TIMESERIES_QUERY, waitAllFinished, response -> Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()));
    waitOneScheduled.await();
    assertResponseAndCountdownOrBlockForever(SIMPLE_TIMESERIES_QUERY, waitAllFinished, response -> {
        Assert.assertEquals(QueryCapacityExceededException.STATUS_CODE, response.getStatus());
        QueryCapacityExceededException ex;
        try {
            ex = jsonMapper.readValue((byte[]) response.getEntity(), QueryCapacityExceededException.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Assert.assertEquals(QueryCapacityExceededException.makeLaneErrorMessage(HiLoQueryLaningStrategy.LOW, 1), ex.getMessage());
        Assert.assertEquals(QueryCapacityExceededException.ERROR_CODE, ex.getErrorCode());
    });
    waitTwoStarted.await();
    assertResponseAndCountdownOrBlockForever(SIMPLE_TIMESERIES_QUERY_SMALLISH_INTERVAL, waitAllFinished, response -> Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()));
    waitAllFinished.await();
}
Also used : ServerConfig(org.apache.druid.server.initialization.ServerConfig) QueryCapacityExceededException(org.apache.druid.query.QueryCapacityExceededException) ThresholdBasedQueryPrioritizationStrategy(org.apache.druid.server.scheduling.ThresholdBasedQueryPrioritizationStrategy) HiLoQueryLaningStrategy(org.apache.druid.server.scheduling.HiLoQueryLaningStrategy) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 22 with ServerConfig

use of org.apache.druid.server.initialization.ServerConfig in project druid by druid-io.

the class QuerySchedulerTest method createInjector.

private Injector createInjector() {
    Injector injector = GuiceInjectors.makeStartupInjectorWithModules(ImmutableList.of(binder -> {
        binder.bind(ServerConfig.class).toInstance(new ServerConfig());
        JsonConfigProvider.bind(binder, "druid.query.scheduler", QuerySchedulerProvider.class, Global.class);
    }));
    ObjectMapper mapper = injector.getInstance(Key.get(ObjectMapper.class, Json.class));
    mapper.setInjectableValues(new InjectableValues.Std().addValue(ServerConfig.class, injector.getInstance(ServerConfig.class)));
    return injector;
}
Also used : QueryPlus(org.apache.druid.query.QueryPlus) Key(com.google.inject.Key) Future(java.util.concurrent.Future) After(org.junit.After) ProvisionException(com.google.inject.ProvisionException) ManualQueryPrioritizationStrategy(org.apache.druid.server.scheduling.ManualQueryPrioritizationStrategy) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) HiLoQueryLaningStrategy(org.apache.druid.server.scheduling.HiLoQueryLaningStrategy) Sequence(org.apache.druid.java.util.common.guava.Sequence) LazySequence(org.apache.druid.java.util.common.guava.LazySequence) ImmutableSet(com.google.common.collect.ImmutableSet) Execs(org.apache.druid.java.util.common.concurrent.Execs) ImmutableMap(com.google.common.collect.ImmutableMap) UUID(java.util.UUID) Json(org.apache.druid.guice.annotations.Json) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) QueryContexts(org.apache.druid.query.QueryContexts) List(java.util.List) BaseSequence(org.apache.druid.java.util.common.guava.BaseSequence) SequenceWrapper(org.apache.druid.java.util.common.guava.SequenceWrapper) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TopNQuery(org.apache.druid.query.topn.TopNQuery) ArrayList(java.util.ArrayList) Yielders(org.apache.druid.java.util.common.guava.Yielders) QueryCapacityExceededException(org.apache.druid.query.QueryCapacityExceededException) ImmutableList(com.google.common.collect.ImmutableList) Query(org.apache.druid.query.Query) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) SegmentServerSelector(org.apache.druid.client.SegmentServerSelector) Yielder(org.apache.druid.java.util.common.guava.Yielder) ExpectedException(org.junit.rules.ExpectedException) Sequences(org.apache.druid.java.util.common.guava.Sequences) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) Before(org.junit.Before) Properties(java.util.Properties) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) Iterator(java.util.Iterator) ServerConfig(org.apache.druid.server.initialization.ServerConfig) TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) Global(org.apache.druid.guice.annotations.Global) EasyMock(org.easymock.EasyMock) Injector(com.google.inject.Injector) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) NoQueryLaningStrategy(org.apache.druid.server.scheduling.NoQueryLaningStrategy) Assert(org.junit.Assert) ServerConfig(org.apache.druid.server.initialization.ServerConfig) Injector(com.google.inject.Injector) Json(org.apache.druid.guice.annotations.Json) Global(org.apache.druid.guice.annotations.Global) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with ServerConfig

use of org.apache.druid.server.initialization.ServerConfig in project druid by druid-io.

the class SetAndVerifyContextQueryRunnerTest method testTimeoutZeroIsNotImmediateTimeoutExplicitServersideMax.

@Test
public void testTimeoutZeroIsNotImmediateTimeoutExplicitServersideMax() {
    Query<ScanResultValue> query = new Druids.ScanQueryBuilder().dataSource("foo").intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.ETERNITY))).context(ImmutableMap.of(QueryContexts.TIMEOUT_KEY, 0)).build();
    ServerConfig defaultConfig = new ServerConfig() {

        @Override
        public long getMaxQueryTimeout() {
            return 10000L;
        }
    };
    QueryRunner<ScanResultValue> mockRunner = EasyMock.createMock(QueryRunner.class);
    SetAndVerifyContextQueryRunner<ScanResultValue> queryRunner = new SetAndVerifyContextQueryRunner<>(defaultConfig, mockRunner);
    Query<ScanResultValue> transformed = queryRunner.withTimeoutAndMaxScatterGatherBytes(query, defaultConfig);
    // timeout is set to 0, so withTimeoutAndMaxScatterGatherBytes should set QUERY_FAIL_TIME to be the current
    // time + max query timeout at the time the method was called
    // this means that the fail time should be greater than the current time when checking
    Assert.assertTrue(System.currentTimeMillis() < (Long) transformed.getContextValue(DirectDruidClient.QUERY_FAIL_TIME));
}
Also used : ServerConfig(org.apache.druid.server.initialization.ServerConfig) ScanResultValue(org.apache.druid.query.scan.ScanResultValue) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) Test(org.junit.Test)

Example 24 with ServerConfig

use of org.apache.druid.server.initialization.ServerConfig in project druid by druid-io.

the class DruidAvaticaHandlerTest method testMaxRowsPerFrame.

@Test
public void testMaxRowsPerFrame() throws Exception {
    final AvaticaServerConfig smallFrameConfig = new AvaticaServerConfig() {

        @Override
        public int getMaxConnections() {
            return 2;
        }

        @Override
        public int getMaxStatementsPerConnection() {
            return 4;
        }

        @Override
        public int getMaxRowsPerFrame() {
            return 2;
        }
    };
    final PlannerConfig plannerConfig = new PlannerConfig();
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    final ExprMacroTable macroTable = CalciteTests.createExprMacroTable();
    final List<Meta.Frame> frames = new ArrayList<>();
    DruidSchemaCatalog rootSchema = CalciteTests.createMockRootSchema(conglomerate, walker, plannerConfig, AuthTestUtils.TEST_AUTHORIZER_MAPPER);
    DruidMeta smallFrameDruidMeta = new DruidMeta(CalciteTests.createSqlLifecycleFactory(new PlannerFactory(rootSchema, CalciteTests.createMockQueryMakerFactory(walker, conglomerate), operatorTable, macroTable, plannerConfig, AuthTestUtils.TEST_AUTHORIZER_MAPPER, CalciteTests.getJsonMapper(), CalciteTests.DRUID_SCHEMA_NAME)), smallFrameConfig, new ErrorHandler(new ServerConfig()), injector) {

        @Override
        public Frame fetch(final StatementHandle statement, final long offset, final int fetchMaxRowCount) throws NoSuchStatementException, MissingResultsException {
            // overriding fetch allows us to track how many frames are processed after the first frame
            Frame frame = super.fetch(statement, offset, fetchMaxRowCount);
            frames.add(frame);
            return frame;
        }
    };
    final AbstractAvaticaHandler handler = this.getAvaticaHandler(smallFrameDruidMeta);
    final int port = ThreadLocalRandom.current().nextInt(9999) + 20000;
    Server smallFrameServer = new Server(new InetSocketAddress("127.0.0.1", port));
    smallFrameServer.setHandler(handler);
    smallFrameServer.start();
    String smallFrameUrl = this.getJdbcConnectionString(port);
    Connection smallFrameClient = DriverManager.getConnection(smallFrameUrl, "regularUser", "druid");
    final ResultSet resultSet = smallFrameClient.createStatement().executeQuery("SELECT dim1 FROM druid.foo");
    List<Map<String, Object>> rows = getRows(resultSet);
    Assert.assertEquals(2, frames.size());
    Assert.assertEquals(ImmutableList.of(ImmutableMap.of("dim1", ""), ImmutableMap.of("dim1", "10.1"), ImmutableMap.of("dim1", "2"), ImmutableMap.of("dim1", "1"), ImmutableMap.of("dim1", "def"), ImmutableMap.of("dim1", "abc")), rows);
}
Also used : Server(org.eclipse.jetty.server.Server) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) AbstractAvaticaHandler(org.apache.calcite.avatica.server.AbstractAvaticaHandler) DruidOperatorTable(org.apache.druid.sql.calcite.planner.DruidOperatorTable) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) ServerConfig(org.apache.druid.server.initialization.ServerConfig) PlannerConfig(org.apache.druid.sql.calcite.planner.PlannerConfig) DruidSchemaCatalog(org.apache.druid.sql.calcite.schema.DruidSchemaCatalog) ResultSet(java.sql.ResultSet) PlannerFactory(org.apache.druid.sql.calcite.planner.PlannerFactory) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 25 with ServerConfig

use of org.apache.druid.server.initialization.ServerConfig in project druid by druid-io.

the class ErrorHandlerTest method testErrorHandlerDefaultErrorResponseTransformStrategySanitizesErrorAsExpected.

@Test
public void testErrorHandlerDefaultErrorResponseTransformStrategySanitizesErrorAsExpected() {
    ServerConfig serverConfig = new ServerConfig();
    ErrorHandler errorHandler = new ErrorHandler(serverConfig);
    QueryInterruptedException input = new QueryInterruptedException("error", "error messagez", "error class", "host");
    RuntimeException output = errorHandler.sanitize(input);
    Assert.assertEquals("error messagez", output.getMessage());
}
Also used : ServerConfig(org.apache.druid.server.initialization.ServerConfig) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) Test(org.junit.Test)

Aggregations

ServerConfig (org.apache.druid.server.initialization.ServerConfig)33 Test (org.junit.Test)26 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 IOException (java.io.IOException)11 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)11 AllowedRegexErrorResponseTransformStrategy (org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy)10 QueryException (org.apache.druid.query.QueryException)10 QueryInterruptedException (org.apache.druid.query.QueryInterruptedException)9 Properties (java.util.Properties)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 DefaultGenericQueryMetricsFactory (org.apache.druid.query.DefaultGenericQueryMetricsFactory)7 MapQueryToolChestWarehouse (org.apache.druid.query.MapQueryToolChestWarehouse)7 NoopRequestLogger (org.apache.druid.server.log.NoopRequestLogger)7 AuthenticatorMapper (org.apache.druid.server.security.AuthenticatorMapper)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Before (org.junit.Before)5 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)4 Query (org.apache.druid.query.Query)4