Search in sources :

Example 16 with ServerConfig

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

the class AsyncQueryForwardingServletTest method verifyServletCallsForQuery.

/**
 * Verifies that the Servlet calls the right methods the right number of times.
 */
private void verifyServletCallsForQuery(Object query, boolean isSql, QueryHostFinder hostFinder, Properties properties) throws Exception {
    final ObjectMapper jsonMapper = TestHelper.makeJsonMapper();
    final HttpServletRequest requestMock = EasyMock.createMock(HttpServletRequest.class);
    final ByteArrayInputStream inputStream = new ByteArrayInputStream(jsonMapper.writeValueAsBytes(query));
    final ServletInputStream servletInputStream = new ServletInputStream() {

        private boolean finished;

        @Override
        public boolean isFinished() {
            return finished;
        }

        @Override
        public boolean isReady() {
            return true;
        }

        @Override
        public void setReadListener(final ReadListener readListener) {
        // do nothing
        }

        @Override
        public int read() {
            final int b = inputStream.read();
            if (b < 0) {
                finished = true;
            }
            return b;
        }
    };
    EasyMock.expect(requestMock.getContentType()).andReturn("application/json").times(2);
    requestMock.setAttribute("org.apache.druid.proxy.objectMapper", jsonMapper);
    EasyMock.expectLastCall();
    EasyMock.expect(requestMock.getRequestURI()).andReturn(isSql ? "/druid/v2/sql" : "/druid/v2/");
    EasyMock.expect(requestMock.getMethod()).andReturn("POST");
    EasyMock.expect(requestMock.getInputStream()).andReturn(servletInputStream);
    requestMock.setAttribute(isSql ? "org.apache.druid.proxy.sqlQuery" : "org.apache.druid.proxy.query", query);
    requestMock.setAttribute("org.apache.druid.proxy.to.host", "1.2.3.4:9999");
    requestMock.setAttribute("org.apache.druid.proxy.to.host.scheme", "http");
    EasyMock.expectLastCall();
    EasyMock.replay(requestMock);
    final AtomicLong didService = new AtomicLong();
    final AsyncQueryForwardingServlet servlet = new AsyncQueryForwardingServlet(new MapQueryToolChestWarehouse(ImmutableMap.of()), jsonMapper, TestHelper.makeSmileMapper(), hostFinder, null, null, new NoopServiceEmitter(), new NoopRequestLogger(), new DefaultGenericQueryMetricsFactory(), new AuthenticatorMapper(ImmutableMap.of()), properties, new ServerConfig()) {

        @Override
        protected void doService(final HttpServletRequest request, final HttpServletResponse response) {
            didService.incrementAndGet();
        }
    };
    servlet.service(requestMock, null);
    // This test is mostly about verifying that the servlet calls the right methods the right number of times.
    EasyMock.verify(hostFinder, requestMock);
    Assert.assertEquals(1, didService.get());
}
Also used : NoopRequestLogger(org.apache.druid.server.log.NoopRequestLogger) HttpServletResponse(javax.servlet.http.HttpServletResponse) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) ReadListener(javax.servlet.ReadListener) HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticatorMapper(org.apache.druid.server.security.AuthenticatorMapper) ServerConfig(org.apache.druid.server.initialization.ServerConfig) AtomicLong(java.util.concurrent.atomic.AtomicLong) ServletInputStream(javax.servlet.ServletInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MapQueryToolChestWarehouse(org.apache.druid.query.MapQueryToolChestWarehouse) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 17 with ServerConfig

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

the class CuratorDruidNodeAnnouncerAndDiscoveryTest method testAnnouncementAndDiscovery.

@Test(timeout = 60_000L)
public void testAnnouncementAndDiscovery() throws Exception {
    ObjectMapper objectMapper = new DefaultObjectMapper();
    // additional setup to serde DruidNode
    objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ServerConfig.class, new ServerConfig()).addValue("java.lang.String", "dummy").addValue("java.lang.Integer", 1234).addValue(ObjectMapper.class, objectMapper));
    curator.start();
    curator.blockUntilConnected();
    Announcer announcer = new Announcer(curator, Execs.directExecutor());
    announcer.start();
    CuratorDruidNodeAnnouncer druidNodeAnnouncer = new CuratorDruidNodeAnnouncer(announcer, new ZkPathsConfig(), objectMapper);
    DiscoveryDruidNode coordinatorNode1 = new DiscoveryDruidNode(new DruidNode("s1", "h1", false, 8080, null, true, false), NodeRole.COORDINATOR, ImmutableMap.of());
    DiscoveryDruidNode coordinatorNode2 = new DiscoveryDruidNode(new DruidNode("s2", "h2", false, 8080, null, true, false), NodeRole.COORDINATOR, ImmutableMap.of());
    DiscoveryDruidNode overlordNode1 = new DiscoveryDruidNode(new DruidNode("s3", "h3", false, 8080, null, true, false), NodeRole.OVERLORD, ImmutableMap.of());
    DiscoveryDruidNode overlordNode2 = new DiscoveryDruidNode(new DruidNode("s4", "h4", false, 8080, null, true, false), NodeRole.OVERLORD, ImmutableMap.of());
    druidNodeAnnouncer.announce(coordinatorNode1);
    druidNodeAnnouncer.announce(overlordNode1);
    CuratorDruidNodeDiscoveryProvider druidNodeDiscoveryProvider = new CuratorDruidNodeDiscoveryProvider(curator, new ZkPathsConfig(), objectMapper);
    druidNodeDiscoveryProvider.start();
    DruidNodeDiscovery coordDiscovery = druidNodeDiscoveryProvider.getForNodeRole(NodeRole.COORDINATOR);
    BooleanSupplier coord1NodeDiscovery = druidNodeDiscoveryProvider.getForNode(coordinatorNode1.getDruidNode(), NodeRole.COORDINATOR);
    DruidNodeDiscovery overlordDiscovery = druidNodeDiscoveryProvider.getForNodeRole(NodeRole.OVERLORD);
    BooleanSupplier overlord1NodeDiscovery = druidNodeDiscoveryProvider.getForNode(overlordNode1.getDruidNode(), NodeRole.OVERLORD);
    while (!checkNodes(ImmutableSet.of(coordinatorNode1), coordDiscovery.getAllNodes()) && !coord1NodeDiscovery.getAsBoolean()) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(overlordNode1), overlordDiscovery.getAllNodes()) && !overlord1NodeDiscovery.getAsBoolean()) {
        Thread.sleep(100);
    }
    HashSet<DiscoveryDruidNode> coordNodes = new HashSet<>();
    coordDiscovery.registerListener(createSetAggregatingListener(coordNodes));
    HashSet<DiscoveryDruidNode> overlordNodes = new HashSet<>();
    overlordDiscovery.registerListener(createSetAggregatingListener(overlordNodes));
    while (!checkNodes(ImmutableSet.of(coordinatorNode1), coordNodes)) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(overlordNode1), overlordNodes)) {
        Thread.sleep(100);
    }
    druidNodeAnnouncer.announce(coordinatorNode2);
    druidNodeAnnouncer.announce(overlordNode2);
    while (!checkNodes(ImmutableSet.of(coordinatorNode1, coordinatorNode2), coordDiscovery.getAllNodes())) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(overlordNode1, overlordNode2), overlordDiscovery.getAllNodes())) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(coordinatorNode1, coordinatorNode2), coordNodes)) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(overlordNode1, overlordNode2), overlordNodes)) {
        Thread.sleep(100);
    }
    druidNodeAnnouncer.unannounce(coordinatorNode1);
    druidNodeAnnouncer.unannounce(coordinatorNode2);
    druidNodeAnnouncer.unannounce(overlordNode1);
    druidNodeAnnouncer.unannounce(overlordNode2);
    while (!checkNodes(ImmutableSet.of(), coordDiscovery.getAllNodes())) {
        Thread.sleep(100);
    }
    while (!checkNodes(ImmutableSet.of(), overlordDiscovery.getAllNodes())) {
        Thread.sleep(100);
    }
    while (!coordNodes.isEmpty()) {
        Thread.sleep(100);
    }
    while (!overlordNodes.isEmpty()) {
        Thread.sleep(100);
    }
    druidNodeDiscoveryProvider.stop();
    announcer.stop();
}
Also used : DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) ServerConfig(org.apache.druid.server.initialization.ServerConfig) Announcer(org.apache.druid.curator.announcement.Announcer) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) ZkPathsConfig(org.apache.druid.server.initialization.ZkPathsConfig) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) DruidNode(org.apache.druid.server.DruidNode) BooleanSupplier(java.util.function.BooleanSupplier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with ServerConfig

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

the class WorkerTaskMonitorTest method createTaskMonitor.

private WorkerTaskMonitor createTaskMonitor() {
    final TaskConfig taskConfig = new TaskConfig(FileUtils.createTempDir().toString(), null, null, 0, null, false, null, null, null, false, false, TaskConfig.BATCH_PROCESSING_MODE_DEFAULT.name());
    TaskActionClientFactory taskActionClientFactory = EasyMock.createNiceMock(TaskActionClientFactory.class);
    TaskActionClient taskActionClient = EasyMock.createNiceMock(TaskActionClient.class);
    EasyMock.expect(taskActionClientFactory.create(EasyMock.anyObject())).andReturn(taskActionClient).anyTimes();
    SegmentHandoffNotifierFactory notifierFactory = EasyMock.createNiceMock(SegmentHandoffNotifierFactory.class);
    EasyMock.replay(taskActionClientFactory, taskActionClient, notifierFactory);
    return new WorkerTaskMonitor(jsonMapper, new SingleTaskBackgroundRunner(new TaskToolboxFactory(taskConfig, null, taskActionClientFactory, null, null, null, null, null, null, null, notifierFactory, null, null, NoopJoinableFactory.INSTANCE, null, new SegmentCacheManagerFactory(jsonMapper), jsonMapper, indexIO, null, null, null, indexMergerV9, null, null, null, null, new NoopTestTaskReportFileWriter(), null, AuthTestUtils.TEST_AUTHORIZER_MAPPER, new NoopChatHandlerProvider(), testUtils.getRowIngestionMetersFactory(), new TestAppenderatorsManager(), new NoopIndexingServiceClient(), null, null, null), taskConfig, new NoopServiceEmitter(), DUMMY_NODE, new ServerConfig()), taskConfig, cf, workerCuratorCoordinator, EasyMock.createNiceMock(DruidLeaderClient.class));
}
Also used : NoopChatHandlerProvider(org.apache.druid.segment.realtime.firehose.NoopChatHandlerProvider) SegmentCacheManagerFactory(org.apache.druid.indexing.common.SegmentCacheManagerFactory) TaskActionClientFactory(org.apache.druid.indexing.common.actions.TaskActionClientFactory) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) DruidLeaderClient(org.apache.druid.discovery.DruidLeaderClient) SegmentHandoffNotifierFactory(org.apache.druid.segment.handoff.SegmentHandoffNotifierFactory) ServerConfig(org.apache.druid.server.initialization.ServerConfig) TaskActionClient(org.apache.druid.indexing.common.actions.TaskActionClient) NoopIndexingServiceClient(org.apache.druid.client.indexing.NoopIndexingServiceClient) TaskToolboxFactory(org.apache.druid.indexing.common.TaskToolboxFactory) NoopTestTaskReportFileWriter(org.apache.druid.indexing.common.task.NoopTestTaskReportFileWriter) TestAppenderatorsManager(org.apache.druid.indexing.common.task.TestAppenderatorsManager) SingleTaskBackgroundRunner(org.apache.druid.indexing.overlord.SingleTaskBackgroundRunner)

Example 19 with ServerConfig

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

the class SingleTaskBackgroundRunnerTest method setup.

@Before
public void setup() throws IOException {
    final TestUtils utils = new TestUtils();
    final DruidNode node = new DruidNode("testServer", "testHost", false, 1000, null, true, false);
    final TaskConfig taskConfig = new TaskConfig(temporaryFolder.newFile().toString(), null, null, 50000, null, true, null, null, null, false, false, TaskConfig.BATCH_PROCESSING_MODE_DEFAULT.name());
    final ServiceEmitter emitter = new NoopServiceEmitter();
    EmittingLogger.registerEmitter(emitter);
    final TaskToolboxFactory toolboxFactory = new TaskToolboxFactory(taskConfig, null, EasyMock.createMock(TaskActionClientFactory.class), emitter, new NoopDataSegmentPusher(), new NoopDataSegmentKiller(), new NoopDataSegmentMover(), new NoopDataSegmentArchiver(), new NoopDataSegmentAnnouncer(), null, null, null, null, NoopJoinableFactory.INSTANCE, null, new SegmentCacheManagerFactory(utils.getTestObjectMapper()), utils.getTestObjectMapper(), utils.getTestIndexIO(), null, null, null, utils.getTestIndexMergerV9(), null, node, null, null, new SingleFileTaskReportFileWriter(new File("fake")), null, AuthTestUtils.TEST_AUTHORIZER_MAPPER, new NoopChatHandlerProvider(), utils.getRowIngestionMetersFactory(), new TestAppenderatorsManager(), new NoopIndexingServiceClient(), null, null, null);
    runner = new SingleTaskBackgroundRunner(toolboxFactory, taskConfig, emitter, node, new ServerConfig());
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) NoopDataSegmentArchiver(org.apache.druid.segment.loading.NoopDataSegmentArchiver) SingleFileTaskReportFileWriter(org.apache.druid.indexing.common.SingleFileTaskReportFileWriter) NoopDataSegmentPusher(org.apache.druid.segment.loading.NoopDataSegmentPusher) NoopDataSegmentKiller(org.apache.druid.segment.loading.NoopDataSegmentKiller) NoopDataSegmentAnnouncer(org.apache.druid.server.coordination.NoopDataSegmentAnnouncer) NoopChatHandlerProvider(org.apache.druid.segment.realtime.firehose.NoopChatHandlerProvider) SegmentCacheManagerFactory(org.apache.druid.indexing.common.SegmentCacheManagerFactory) TaskActionClientFactory(org.apache.druid.indexing.common.actions.TaskActionClientFactory) NoopDataSegmentMover(org.apache.druid.segment.loading.NoopDataSegmentMover) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) TestUtils(org.apache.druid.indexing.common.TestUtils) AuthTestUtils(org.apache.druid.server.security.AuthTestUtils) ServerConfig(org.apache.druid.server.initialization.ServerConfig) NoopIndexingServiceClient(org.apache.druid.client.indexing.NoopIndexingServiceClient) TaskToolboxFactory(org.apache.druid.indexing.common.TaskToolboxFactory) DruidNode(org.apache.druid.server.DruidNode) File(java.io.File) TestAppenderatorsManager(org.apache.druid.indexing.common.task.TestAppenderatorsManager) Before(org.junit.Before)

Example 20 with ServerConfig

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

the class TaskLifecycleTest method setUpThreadPoolTaskRunner.

private TaskRunner setUpThreadPoolTaskRunner(TaskToolboxFactory tb) {
    Preconditions.checkNotNull(taskConfig);
    Preconditions.checkNotNull(emitter);
    return new SingleTaskBackgroundRunner(tb, taskConfig, emitter, druidNode, new ServerConfig());
}
Also used : ServerConfig(org.apache.druid.server.initialization.ServerConfig)

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