Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

package org.apache.druid.msq.quidem;

import org.apache.druid.quidem.DruidQuidemCommandHandler;
import org.apache.druid.quidem.DruidQuidemTestBase;
import org.apache.druid.quidem.ProjectPathUtils;

import java.io.File;

public class MSQQuidemTest extends DruidQuidemTestBase
{
public MSQQuidemTest()
{
super();
super(new DruidQuidemCommandHandler());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.apache.druid.msq.test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Injector;
import org.apache.druid.guice.IndexingServiceTuningConfigModule;
import org.apache.druid.guice.JoinableFactoryModule;
import org.apache.druid.initialization.DruidModule;
Expand All @@ -29,7 +27,6 @@
import org.apache.druid.msq.guice.MSQIndexingModule;
import org.apache.druid.msq.sql.MSQTaskSqlEngine;
import org.apache.druid.msq.test.CalciteMSQTestsHelper.MSQTestModule;
import org.apache.druid.server.QueryLifecycleFactory;
import org.apache.druid.sql.calcite.run.SqlEngine;
import org.apache.druid.sql.calcite.util.DruidModuleCollection;
import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier;
Expand Down Expand Up @@ -61,17 +58,15 @@ public DruidModule getCoreModule()
}

@Override
public SqlEngine createEngine(
QueryLifecycleFactory qlf,
ObjectMapper queryJsonMapper,
Injector injector)
public Class<? extends SqlEngine> getSqlEngineClass()
{
return injector.getInstance(MSQTaskSqlEngine.class);
return MSQTaskSqlEngine.class;
}

@Override
public Boolean isExplainSupported()
{
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.msq.test;

import org.apache.druid.sql.calcite.MultiComponentSupplier;
import org.apache.druid.sql.calcite.MultiComponentSupplier.ComponentSuppliers;
import org.apache.druid.sql.calcite.util.SqlTestFramework.StandardComponentSupplier;

@ComponentSuppliers({
StandardComponentSupplier.class,
DartComponentSupplier.class,
StandardMSQComponentSupplier.class})
public class AllDruidEnginesComponentSupplier extends MultiComponentSupplier
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@
import org.apache.druid.msq.guice.MSQExternalDataSourceModule;
import org.apache.druid.msq.guice.MSQIndexingModule;
import org.apache.druid.msq.querykit.DataSegmentProvider;
import org.apache.druid.query.DruidProcessingConfig;
import org.apache.druid.query.ForwardingQueryProcessingPool;
import org.apache.druid.query.QueryProcessingPool;
import org.apache.druid.query.groupby.GroupByQueryConfig;
import org.apache.druid.query.groupby.GroupByQueryRunnerTest;
import org.apache.druid.query.groupby.GroupingEngine;
import org.apache.druid.query.groupby.TestGroupByBuffers;
import org.apache.druid.segment.CompleteSegment;
import org.apache.druid.segment.TestIndex;
Expand Down Expand Up @@ -98,15 +94,6 @@ public void configure(Binder binder)
{
}).annotatedWith(Self.class).toInstance(ImmutableSet.of(NodeRole.PEON));

DruidProcessingConfig druidProcessingConfig = new DruidProcessingConfig()
{
@Override
public String getFormatString()
{
return "test";
}
};
binder.bind(DruidProcessingConfig.class).toInstance(druidProcessingConfig);
binder.bind(QueryProcessingPool.class)
.toInstance(new ForwardingQueryProcessingPool(Execs.singleThreaded("Test-runner-processing-pool")));

Expand Down Expand Up @@ -174,26 +161,13 @@ public Supplier<ResourceHolder<CompleteSegment>> fetchSegment(
CompleteSegment a = walker.getSegment(segmentId);
return () -> new ReferenceCountingResourceHolder<>(a, Closer.create());
}

}

@Provides
public DataServerQueryHandlerFactory provideDataServerQueryHandlerFactory()
{
return getTestDataServerQueryHandlerFactory();
}

@Provides
@LazySingleton
GroupingEngine getGroupingEngine(GroupByQueryConfig groupByQueryConfig, TestGroupByBuffers groupByBuffers)
{
GroupingEngine groupingEngine = GroupByQueryRunnerTest.makeQueryRunnerFactory(
groupByQueryConfig,
groupByBuffers
).getGroupingEngine();
return groupingEngine;
}

}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

package org.apache.druid.msq.test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Binder;
import com.google.inject.Injector;
import com.google.inject.Provides;
import org.apache.druid.collections.NonBlockingPool;
import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
Expand All @@ -41,7 +39,6 @@
import org.apache.druid.query.TestBufferPool;
import org.apache.druid.rpc.ServiceClientFactory;
import org.apache.druid.rpc.guice.ServiceClientModule;
import org.apache.druid.server.QueryLifecycleFactory;
import org.apache.druid.sql.avatica.DartDruidMeta;
import org.apache.druid.sql.avatica.DruidMeta;
import org.apache.druid.sql.calcite.TempDirProducer;
Expand Down Expand Up @@ -90,12 +87,9 @@ public DruidModule getOverrideModule()
}

@Override
public SqlEngine createEngine(
QueryLifecycleFactory qlf,
ObjectMapper queryJsonMapper,
Injector injector)
public Class<? extends SqlEngine> getSqlEngineClass()
{
return injector.getInstance(DartSqlEngine.class);
return DartSqlEngine.class;
}

static class DartTestCoreModule implements DruidModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ public static void sleepFor(long sleepTime, TimeUnit unit) throws InterruptedExc
}
}

private Threads()
/**
* Temporarily renames the thread.
*
* Preferred usage should be via try-with-resources clauses.
*
* @return a {@link AutoCloseable} to rename the thread back to its original name.
*/
public static AutoCloseable withThreadName(String name)
{
final Thread thread = Thread.currentThread();
final String oldThreadName = thread.getName();
thread.setName(name);
return () -> {
thread.setName(oldThreadName);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
package org.apache.druid.initialization;

import com.fasterxml.jackson.databind.Module;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.util.Modules;
import org.apache.druid.guice.annotations.ExtensionPoint;

import java.util.Collections;
Expand All @@ -36,6 +40,35 @@
@ExtensionPoint
public interface DruidModule extends com.google.inject.Module
{
static DruidModule override(com.google.inject.Module baseModule, com.google.inject.Module overrideGuiceModule)
{
return new DruidModule()
{
@SuppressWarnings("unused")
@Inject
public void injectMe(Injector injector)
{
injector.injectMembers(baseModule);
injector.injectMembers(overrideGuiceModule);
}

@Override
public void configure(Binder binder)
{
binder.install(Modules.override(baseModule).with(overrideGuiceModule));
}

@Override
public List<? extends Module> getJacksonModules()
{
if (baseModule instanceof DruidModule) {
return ((DruidModule) baseModule).getJacksonModules();
}
return Collections.emptyList();
}
};
}

default List<? extends Module> getJacksonModules()
{
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.concurrent;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ThreadsTest
{
@Test
public void testThreadRename() throws Exception
{
String oldName = Thread.currentThread().getName();
String newName = "testThreadRename-was:" + oldName;
try (AutoCloseable renameBack = Threads.withThreadName(newName)) {
assertEquals(newName, Thread.currentThread().getName());
}
assertEquals(oldName, Thread.currentThread().getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.initialization;

import com.fasterxml.jackson.databind.Module;
import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provides;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DruidModuleTest
{
@Test
public void testOverride()
{
Injector initInjector = Guice.createInjector(new LocalProviderModule(10));
DruidModule overrideModule = DruidModule.override(new LocalProviderModule(1), new LocalProviderModule(2));
initInjector.injectMembers(overrideModule);
Injector injector = Guice.createInjector(overrideModule);
Integer val = injector.getInstance(Integer.class);
assertEquals(12, val);
}

@Test
public void testOverrideJacksonModules()
{
Injector initInjector = Guice.createInjector(new LocalProviderModule(10));
DruidModule overrideModule = DruidModule.override(new LocalProviderModule(1), new LocalProviderModule(2));
initInjector.injectMembers(overrideModule);
List<? extends Module> jacksonModules = overrideModule.getJacksonModules();
// Even thru it was overridden, the base module should still provide these.
assertEquals(1, jacksonModules.size());
}

static class LocalProviderModule implements DruidModule
{
private int val;
private int baseVal = 0;

@Inject
public void injectInteger(Integer baseVal)
{
this.baseVal = baseVal;
}

public LocalProviderModule(int i)
{
val = i;
}

@Override
public void configure(Binder binder)
{
}

@Provides
public Integer getVal()
{
return val + baseVal;
}

@Override
public List<? extends Module> getJacksonModules()
{
List<? extends Module> li = new ArrayList<>();
for (int i = 0; i < val; i++) {
li.add(null);
}
return li;
}

}

}
Loading
Loading