Search in sources :

Example 1 with TestRequestLogger

use of org.apache.druid.server.log.TestRequestLogger in project druid by druid-io.

the class DruidAvaticaHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder.newFolder());
    final PlannerConfig plannerConfig = new PlannerConfig();
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    final ExprMacroTable macroTable = CalciteTests.createExprMacroTable();
    final DruidSchemaCatalog rootSchema = CalciteTests.createMockRootSchema(conglomerate, walker, plannerConfig, CalciteTests.TEST_AUTHORIZER_MAPPER);
    testRequestLogger = new TestRequestLogger();
    injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
            binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1);
            binder.bind(AuthenticatorMapper.class).toInstance(CalciteTests.TEST_AUTHENTICATOR_MAPPER);
            binder.bind(AuthorizerMapper.class).toInstance(CalciteTests.TEST_AUTHORIZER_MAPPER);
            binder.bind(Escalator.class).toInstance(CalciteTests.TEST_AUTHENTICATOR_ESCALATOR);
            binder.bind(RequestLogger.class).toInstance(testRequestLogger);
            binder.bind(DruidSchemaCatalog.class).toInstance(rootSchema);
            for (NamedSchema schema : rootSchema.getNamedSchemas().values()) {
                Multibinder.newSetBinder(binder, NamedSchema.class).addBinding().toInstance(schema);
            }
            binder.bind(QueryLifecycleFactory.class).toInstance(CalciteTests.createMockQueryLifecycleFactory(walker, conglomerate));
            binder.bind(DruidOperatorTable.class).toInstance(operatorTable);
            binder.bind(ExprMacroTable.class).toInstance(macroTable);
            binder.bind(PlannerConfig.class).toInstance(plannerConfig);
            binder.bind(String.class).annotatedWith(DruidSchemaName.class).toInstance(CalciteTests.DRUID_SCHEMA_NAME);
            binder.bind(AvaticaServerConfig.class).toInstance(AVATICA_CONFIG);
            binder.bind(ServiceEmitter.class).to(NoopServiceEmitter.class);
            binder.bind(QuerySchedulerProvider.class).in(LazySingleton.class);
            binder.bind(QueryScheduler.class).toProvider(QuerySchedulerProvider.class).in(LazySingleton.class);
            binder.bind(QueryMakerFactory.class).to(NativeQueryMakerFactory.class);
        }
    }));
    druidMeta = injector.getInstance(DruidMeta.class);
    final AbstractAvaticaHandler handler = this.getAvaticaHandler(druidMeta);
    final int port = ThreadLocalRandom.current().nextInt(9999) + 10000;
    server = new Server(new InetSocketAddress("127.0.0.1", port));
    server.setHandler(handler);
    server.start();
    url = this.getJdbcConnectionString(port);
    client = DriverManager.getConnection(url, "regularUser", "druid");
    superuserClient = DriverManager.getConnection(url, CalciteTests.TEST_SUPERUSER_NAME, "druid");
    clientNoTrailingSlash = DriverManager.getConnection(StringUtils.maybeRemoveTrailingSlash(url), CalciteTests.TEST_SUPERUSER_NAME, "druid");
    final Properties propertiesLosAngeles = new Properties();
    propertiesLosAngeles.setProperty("sqlTimeZone", "America/Los_Angeles");
    propertiesLosAngeles.setProperty("user", "regularUserLA");
    propertiesLosAngeles.setProperty(BaseQuery.SQL_QUERY_ID, DUMMY_SQL_QUERY_ID);
    clientLosAngeles = DriverManager.getConnection(url, propertiesLosAngeles);
}
Also used : QueryScheduler(org.apache.druid.server.QueryScheduler) Server(org.eclipse.jetty.server.Server) InetSocketAddress(java.net.InetSocketAddress) AbstractAvaticaHandler(org.apache.calcite.avatica.server.AbstractAvaticaHandler) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) NamedSchema(org.apache.druid.sql.calcite.schema.NamedSchema) Properties(java.util.Properties) DruidOperatorTable(org.apache.druid.sql.calcite.planner.DruidOperatorTable) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) TestRequestLogger(org.apache.druid.server.log.TestRequestLogger) Binder(com.google.inject.Binder) LazySingleton(org.apache.druid.guice.LazySingleton) PlannerConfig(org.apache.druid.sql.calcite.planner.PlannerConfig) DruidSchemaCatalog(org.apache.druid.sql.calcite.schema.DruidSchemaCatalog) NativeQueryMakerFactory(org.apache.druid.sql.calcite.run.NativeQueryMakerFactory) Module(com.google.inject.Module) Before(org.junit.Before)

Example 2 with TestRequestLogger

use of org.apache.druid.server.log.TestRequestLogger in project druid by druid-io.

the class SqlResourceTest method setUp.

@Before
public void setUp() throws Exception {
    final QueryScheduler scheduler = new QueryScheduler(5, ManualQueryPrioritizationStrategy.INSTANCE, new HiLoQueryLaningStrategy(40), new ServerConfig()) {

        @Override
        public <T> Sequence<T> run(Query<?> query, Sequence<T> resultSequence) {
            return super.run(query, new LazySequence<T>(() -> {
                if (sleep) {
                    try {
                        // pretend to be a query that is waiting on results
                        Thread.sleep(500);
                    } catch (InterruptedException ignored) {
                    }
                }
                return resultSequence;
            }));
        }
    };
    executorService = MoreExecutors.listeningDecorator(Execs.multiThreaded(8, "test_sql_resource_%s"));
    walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder.newFolder(), scheduler);
    final PlannerConfig plannerConfig = new PlannerConfig() {

        @Override
        public boolean shouldSerializeComplexValues() {
            return false;
        }
    };
    final DruidSchemaCatalog rootSchema = CalciteTests.createMockRootSchema(conglomerate, walker, plannerConfig, CalciteTests.TEST_AUTHORIZER_MAPPER);
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    final ExprMacroTable macroTable = CalciteTests.createExprMacroTable();
    req = EasyMock.createStrictMock(HttpServletRequest.class);
    EasyMock.expect(req.getRemoteAddr()).andReturn(null).once();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(CalciteTests.REGULAR_USER_AUTH_RESULT).anyTimes();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).anyTimes();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(CalciteTests.REGULAR_USER_AUTH_RESULT).anyTimes();
    req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(CalciteTests.REGULAR_USER_AUTH_RESULT).anyTimes();
    EasyMock.replay(req);
    testRequestLogger = new TestRequestLogger();
    final PlannerFactory plannerFactory = new PlannerFactory(rootSchema, CalciteTests.createMockQueryMakerFactory(walker, conglomerate), operatorTable, macroTable, plannerConfig, CalciteTests.TEST_AUTHORIZER_MAPPER, CalciteTests.getJsonMapper(), CalciteTests.DRUID_SCHEMA_NAME);
    lifecycleManager = new SqlLifecycleManager() {

        @Override
        public void add(String sqlQueryId, SqlLifecycle lifecycle) {
            super.add(sqlQueryId, lifecycle);
            if (lifecycleAddLatch != null) {
                lifecycleAddLatch.countDown();
            }
        }
    };
    final ServiceEmitter emitter = new NoopServiceEmitter();
    sqlLifecycleFactory = new SqlLifecycleFactory(plannerFactory, emitter, testRequestLogger, scheduler) {

        @Override
        public SqlLifecycle factorize() {
            return new TestSqlLifecycle(plannerFactory, emitter, testRequestLogger, scheduler, System.currentTimeMillis(), System.nanoTime(), validateAndAuthorizeLatchSupplier, planLatchSupplier, executeLatchSupplier, sequenceMapFnSupplier);
        }
    };
    resource = new SqlResource(JSON_MAPPER, CalciteTests.TEST_AUTHORIZER_MAPPER, sqlLifecycleFactory, lifecycleManager, new ServerConfig());
}
Also used : SqlLifecycleManager(org.apache.druid.sql.SqlLifecycleManager) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) QueryScheduler(org.apache.druid.server.QueryScheduler) BaseQuery(org.apache.druid.query.BaseQuery) Query(org.apache.druid.query.Query) HiLoQueryLaningStrategy(org.apache.druid.server.scheduling.HiLoQueryLaningStrategy) SqlLifecycle(org.apache.druid.sql.SqlLifecycle) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) Sequence(org.apache.druid.java.util.common.guava.Sequence) LazySequence(org.apache.druid.java.util.common.guava.LazySequence) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) DruidOperatorTable(org.apache.druid.sql.calcite.planner.DruidOperatorTable) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) TestRequestLogger(org.apache.druid.server.log.TestRequestLogger) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConfig(org.apache.druid.server.initialization.ServerConfig) PlannerConfig(org.apache.druid.sql.calcite.planner.PlannerConfig) DruidSchemaCatalog(org.apache.druid.sql.calcite.schema.DruidSchemaCatalog) PlannerFactory(org.apache.druid.sql.calcite.planner.PlannerFactory) SqlLifecycleFactory(org.apache.druid.sql.SqlLifecycleFactory) Before(org.junit.Before)

Example 3 with TestRequestLogger

use of org.apache.druid.server.log.TestRequestLogger in project druid by druid-io.

the class QueryResourceTest method setup.

@Before
public void setup() {
    Injector injector = GuiceInjectors.makeStartupInjector();
    jsonMapper = injector.getInstance(ObjectMapper.class);
    smileMapper = injector.getInstance(Key.get(ObjectMapper.class, Smile.class));
    EasyMock.expect(testServletRequest.getContentType()).andReturn(MediaType.APPLICATION_JSON).anyTimes();
    EasyMock.expect(testServletRequest.getHeader("Accept")).andReturn(MediaType.APPLICATION_JSON).anyTimes();
    EasyMock.expect(testServletRequest.getHeader(QueryResource.HEADER_IF_NONE_MATCH)).andReturn(null).anyTimes();
    EasyMock.expect(testServletRequest.getRemoteAddr()).andReturn("localhost").anyTimes();
    queryScheduler = QueryStackTests.DEFAULT_NOOP_SCHEDULER;
    testRequestLogger = new TestRequestLogger();
    queryResource = createQueryResource(ResponseContextConfig.newConfig(true));
}
Also used : Injector(com.google.inject.Injector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) TestRequestLogger(org.apache.druid.server.log.TestRequestLogger) Before(org.junit.Before)

Example 4 with TestRequestLogger

use of org.apache.druid.server.log.TestRequestLogger in project druid by druid-io.

the class QueryResourceTest method createScheduledQueryResource.

private void createScheduledQueryResource(QueryScheduler scheduler, Collection<CountDownLatch> beforeScheduler, Collection<CountDownLatch> inScheduler) {
    QuerySegmentWalker texasRanger = new QuerySegmentWalker() {

        @Override
        public <T> QueryRunner<T> getQueryRunnerForIntervals(Query<T> query, Iterable<Interval> intervals) {
            return (queryPlus, responseContext) -> {
                beforeScheduler.forEach(CountDownLatch::countDown);
                return scheduler.run(scheduler.prioritizeAndLaneQuery(queryPlus, ImmutableSet.of()), new LazySequence<T>(() -> {
                    inScheduler.forEach(CountDownLatch::countDown);
                    try {
                        // pretend to be a query that is waiting on results
                        Thread.sleep(500);
                    } catch (InterruptedException ignored) {
                    }
                    // all that waiting for nothing :(
                    return Sequences.empty();
                }));
            };
        }

        @Override
        public <T> QueryRunner<T> getQueryRunnerForSegments(Query<T> query, Iterable<SegmentDescriptor> specs) {
            return getQueryRunnerForIntervals(null, null);
        }
    };
    queryResource = new QueryResource(new QueryLifecycleFactory(WAREHOUSE, texasRanger, new DefaultGenericQueryMetricsFactory(), new NoopServiceEmitter(), testRequestLogger, new AuthConfig(), AuthTestUtils.TEST_AUTHORIZER_MAPPER, Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))), jsonMapper, smileMapper, scheduler, new AuthConfig(), null, ResponseContextConfig.newConfig(true), DRUID_NODE);
}
Also used : TimeBoundaryResultValue(org.apache.druid.query.timeboundary.TimeBoundaryResultValue) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) Key(com.google.inject.Key) Smile(org.apache.druid.guice.annotations.Smile) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) HttpStatus(org.apache.http.HttpStatus) MediaType(javax.ws.rs.core.MediaType) ByteArrayInputStream(java.io.ByteArrayInputStream) BadJsonQueryException(org.apache.druid.query.BadJsonQueryException) After(org.junit.After) QueryRunner(org.apache.druid.query.QueryRunner) QueryToolChestWarehouse(org.apache.druid.query.QueryToolChestWarehouse) ForbiddenException(org.apache.druid.server.security.ForbiddenException) AuthConfig(org.apache.druid.server.security.AuthConfig) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ManualQueryPrioritizationStrategy(org.apache.druid.server.scheduling.ManualQueryPrioritizationStrategy) HiLoQueryLaningStrategy(org.apache.druid.server.scheduling.HiLoQueryLaningStrategy) TestRequestLogger(org.apache.druid.server.log.TestRequestLogger) SmileMediaTypes(com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes) 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) Collection(java.util.Collection) MapQueryToolChestWarehouse(org.apache.druid.query.MapQueryToolChestWarehouse) StreamingOutput(javax.ws.rs.core.StreamingOutput) Action(org.apache.druid.server.security.Action) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) QueryTimeoutException(org.apache.druid.query.QueryTimeoutException) Response(javax.ws.rs.core.Response) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Authorizer(org.apache.druid.server.security.Authorizer) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) QueryException(org.apache.druid.query.QueryException) BeforeClass(org.junit.BeforeClass) ByteArrayOutputStream(java.io.ByteArrayOutputStream) QueryCapacityExceededException(org.apache.druid.query.QueryCapacityExceededException) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult) Interval(org.joda.time.Interval) HttpServletRequest(javax.servlet.http.HttpServletRequest) ImmutableList(com.google.common.collect.ImmutableList) Query(org.apache.druid.query.Query) Suppliers(com.google.common.base.Suppliers) AuthTestUtils(org.apache.druid.server.security.AuthTestUtils) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) Status(javax.ws.rs.core.Response.Status) Sequences(org.apache.druid.java.util.common.guava.Sequences) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) Before(org.junit.Before) Access(org.apache.druid.server.security.Access) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) ServerConfig(org.apache.druid.server.initialization.ServerConfig) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) EasyMock(org.easymock.EasyMock) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Injector(com.google.inject.Injector) Consumer(java.util.function.Consumer) Result(org.apache.druid.query.Result) ThresholdBasedQueryPrioritizationStrategy(org.apache.druid.server.scheduling.ThresholdBasedQueryPrioritizationStrategy) TruncatedResponseContextException(org.apache.druid.query.TruncatedResponseContextException) Resource(org.apache.druid.server.security.Resource) ResourceLimitExceededException(org.apache.druid.query.ResourceLimitExceededException) NoQueryLaningStrategy(org.apache.druid.server.scheduling.NoQueryLaningStrategy) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) SegmentDescriptor(org.apache.druid.query.SegmentDescriptor) Assert(org.junit.Assert) Collections(java.util.Collections) QueryUnsupportedException(org.apache.druid.query.QueryUnsupportedException) Query(org.apache.druid.query.Query) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) AuthConfig(org.apache.druid.server.security.AuthConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) LazySequence(org.apache.druid.java.util.common.guava.LazySequence)

Aggregations

TestRequestLogger (org.apache.druid.server.log.TestRequestLogger)4 Before (org.junit.Before)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Injector (com.google.inject.Injector)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)2 LazySequence (org.apache.druid.java.util.common.guava.LazySequence)2 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)2 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)2 QueryScheduler (org.apache.druid.server.QueryScheduler)2 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)2 DruidOperatorTable (org.apache.druid.sql.calcite.planner.DruidOperatorTable)2 PlannerConfig (org.apache.druid.sql.calcite.planner.PlannerConfig)2 DruidSchemaCatalog (org.apache.druid.sql.calcite.schema.DruidSchemaCatalog)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 SmileMediaTypes (com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes)1 Suppliers (com.google.common.base.Suppliers)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1