small cleanup

This commit is contained in:
Zoltan Haindrich 2024-05-28 15:54:29 +00:00
parent 295c09a03c
commit ff7abeb0f1
4 changed files with 28 additions and 26 deletions

View File

@ -26,19 +26,22 @@ import org.apache.druid.sql.calcite.SqlTestFrameworkConfig;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.ConfigurationInstance; import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.ConfigurationInstance;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.SqlTestFrameworkConfigStore; import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.SqlTestFrameworkConfigStore;
import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework;
import java.sql.SQLException;
public class Launcher public class Launcher
{ {
static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore(); static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore(
x -> new ExposedAsBrokerQueryComponentSupplierWrapper(x)
);
private static final String QUIDEM_URI = "quidem.uri";
private static Logger log = new Logger(Launcher.class); private static Logger log = new Logger(Launcher.class);
private final SqlTestFramework framework; private final SqlTestFramework framework;
private final ConfigurationInstance configurationInstance; private final ConfigurationInstance configurationInstance;
private Lifecycle lifecycle; private Lifecycle lifecycle;
public Launcher() throws Exception public Launcher(String uri) throws Exception
{ {
configurationInstance = getConfigurationInstance(); SqlTestFrameworkConfig config = SqlTestFrameworkConfig.fromURL(uri);
configurationInstance = CONFIG_STORE.getConfigurationInstance(config);
framework = configurationInstance.framework; framework = configurationInstance.framework;
} }
@ -52,14 +55,12 @@ public class Launcher
lifecycle.stop(); lifecycle.stop();
} }
private static ConfigurationInstance getConfigurationInstance() throws SQLException, Exception public static void main(String[] args) throws Exception
{ {
SqlTestFrameworkConfig config = SqlTestFrameworkConfig.fromURL("druidtest:///"); String quidemUri = System.getProperty(QUIDEM_URI, "druidtest:///");
ConfigurationInstance ci = CONFIG_STORE.getConfigurationInstance( Launcher launcher = new Launcher(quidemUri );
config, launcher.start();
x -> new ExposedAsBrokerQueryComponentSupplierWrapper(x) launcher.lifecycle.join();
);
return ci;
} }
} }

View File

@ -18,7 +18,6 @@
*/ */
package org.apache.druid.quidem; package org.apache.druid.quidem;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.SqlTestFrameworkConfigStore;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -33,14 +32,12 @@ import static org.testng.Assert.assertEquals;
public class LauncherSmokeTest public class LauncherSmokeTest
{ {
static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore();
private static Launcher launcher; private static Launcher launcher;
@BeforeClass @BeforeClass
public static void setUp() throws Exception public static void setUp() throws Exception
{ {
launcher = new Launcher(); launcher = new Launcher("druidtest:///");
launcher.start(); launcher.start();
} }

View File

@ -93,7 +93,9 @@ public class DruidAvaticaTestDriver implements Driver
public static final String URI_PREFIX = "druidtest://"; public static final String URI_PREFIX = "druidtest://";
public static final String DEFAULT_URI = URI_PREFIX + "/"; public static final String DEFAULT_URI = URI_PREFIX + "/";
static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore(); static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore(
x -> new AvaticaBasedTestConnectionSupplier(x)
);
public DruidAvaticaTestDriver() public DruidAvaticaTestDriver()
{ {
@ -107,12 +109,7 @@ public class DruidAvaticaTestDriver implements Driver
} }
try { try {
SqlTestFrameworkConfig config = SqlTestFrameworkConfig.fromURL(url); SqlTestFrameworkConfig config = SqlTestFrameworkConfig.fromURL(url);
ConfigurationInstance ci = CONFIG_STORE.getConfigurationInstance(config);
ConfigurationInstance ci = CONFIG_STORE.getConfigurationInstance(
config,
x -> new AvaticaBasedTestConnectionSupplier(x)
);
AvaticaJettyServer server = ci.framework.injector().getInstance(AvaticaJettyServer.class); AvaticaJettyServer server = ci.framework.injector().getInstance(AvaticaJettyServer.class);
return server.getConnection(info); return server.getConnection(info);
} }

View File

@ -230,11 +230,18 @@ public class SqlTestFrameworkConfig
public static class SqlTestFrameworkConfigStore implements Closeable public static class SqlTestFrameworkConfigStore implements Closeable
{ {
private final Function<QueryComponentSupplier, QueryComponentSupplier> queryComponentSupplierWrapper;
public SqlTestFrameworkConfigStore(
Function<QueryComponentSupplier, QueryComponentSupplier> queryComponentSupplierWrapper)
{
this.queryComponentSupplierWrapper = queryComponentSupplierWrapper;
}
Map<SqlTestFrameworkConfig, ConfigurationInstance> configMap = new HashMap<>(); Map<SqlTestFrameworkConfig, ConfigurationInstance> configMap = new HashMap<>();
public ConfigurationInstance getConfigurationInstance( public ConfigurationInstance getConfigurationInstance(
SqlTestFrameworkConfig config, SqlTestFrameworkConfig config) throws Exception
Function<QueryComponentSupplier, QueryComponentSupplier> queryComponentSupplierWrapper) throws Exception
{ {
ConfigurationInstance ret = configMap.get(config); ConfigurationInstance ret = configMap.get(config);
if (!configMap.containsKey(config)) { if (!configMap.containsKey(config)) {
@ -273,7 +280,7 @@ public class SqlTestFrameworkConfig
*/ */
public static class Rule implements AfterAllCallback, BeforeEachCallback public static class Rule implements AfterAllCallback, BeforeEachCallback
{ {
SqlTestFrameworkConfigStore configStore = new SqlTestFrameworkConfigStore(); SqlTestFrameworkConfigStore configStore = new SqlTestFrameworkConfigStore(Function.identity());
private SqlTestFrameworkConfig config; private SqlTestFrameworkConfig config;
private Method method; private Method method;
private String testName; private String testName;
@ -324,7 +331,7 @@ public class SqlTestFrameworkConfig
public SqlTestFramework get() throws Exception public SqlTestFramework get() throws Exception
{ {
return configStore.getConfigurationInstance(config, Function.identity()).framework; return configStore.getConfigurationInstance(config).framework;
} }
public <T extends Annotation> T getAnnotation(Class<T> annotationType) public <T extends Annotation> T getAnnotation(Class<T> annotationType)