This commit is contained in:
Zoltan Haindrich 2024-05-28 15:09:42 +00:00
parent b20ee99371
commit a1b7f981fb
4 changed files with 31 additions and 64 deletions

View File

@ -26,23 +26,15 @@ import org.apache.druid.sql.calcite.SqlTestFrameworkConfig;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.ConfigurationInstance;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.SqlTestFrameworkConfigStore;
import org.apache.druid.sql.calcite.util.SqlTestFramework;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.junit.Test;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertNotEquals;
public class Launcher
@ -51,24 +43,6 @@ public class Launcher
private static Logger log = new Logger(Launcher.class);
public static SqlTestFrameworkConfig buildConfigfromURIParams(String url) throws SQLException
{
Map<String, String> queryParams;
queryParams = new HashMap<>();
try {
List<NameValuePair> params = URLEncodedUtils.parse(new URI(url), StandardCharsets.UTF_8);
for (NameValuePair pair : params) {
queryParams.put(pair.getName(), pair.getValue());
}
// possible caveat: duplicate entries overwrite earlier ones
}
catch (URISyntaxException e) {
throw new SQLException("Can't decode URI", e);
}
return new SqlTestFrameworkConfig(queryParams);
}
@Test
public void runIt() throws Exception
{
@ -77,7 +51,7 @@ public class Launcher
private static ConfigurationInstance getCI2() throws SQLException, Exception
{
SqlTestFrameworkConfig config = buildConfigfromURIParams("druidtest:///");
SqlTestFrameworkConfig config = SqlTestFrameworkConfig.fromURL("druidtest:///");
ConfigurationInstance ci = CONFIG_STORE.getConfigurationInstance(
config,
@ -91,18 +65,14 @@ public class Launcher
SqlTestFramework framework = getCI2().framework;
if (true) {
Lifecycle lifecycle = GuiceRunnable.initLifecycle(framework.injector(), log);
Lifecycle lifecycle = GuiceRunnable.initLifecycle(framework.injector(), log);
chk1();
chkStatus();
chk1();
chkStatus();
System.out.println("-------------------booted up-------------------");
System.out.println("-------------------booted up-------------------");
lifecycle.join();
} else {
}
lifecycle.join();
}

View File

@ -19,6 +19,7 @@
package org.apache.druid.quidem;
import org.apache.druid.sql.calcite.SqlTestFrameworkConfig;
import org.junit.jupiter.api.Test;
import java.sql.Connection;
@ -51,6 +52,6 @@ public class DruidAvaticaDriverTest
@Test
public void testURIParse() throws SQLException
{
DruidAvaticaTestDriver.buildConfigfromURIParams("druidtest:///");
SqlTestFrameworkConfig.fromURL("druidtest:///");
}
}

View File

@ -70,25 +70,17 @@ import org.apache.druid.sql.calcite.util.SqlTestFramework.Builder;
import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier;
import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier;
import org.apache.druid.sql.guice.SqlModule;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.client.utils.URLEncodedUtils;
import org.eclipse.jetty.server.Server;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;
@ -114,7 +106,7 @@ public class DruidAvaticaTestDriver implements Driver
return null;
}
try {
SqlTestFrameworkConfig config = buildConfigfromURIParams(url);
SqlTestFrameworkConfig config = SqlTestFrameworkConfig.fromURL(url);
ConfigurationInstance ci = CONFIG_STORE.getConfigurationInstance(
config,
@ -349,24 +341,6 @@ public class DruidAvaticaTestDriver implements Driver
return tempDir;
}
public static SqlTestFrameworkConfig buildConfigfromURIParams(String url) throws SQLException
{
Map<String, String> queryParams;
queryParams = new HashMap<>();
try {
List<NameValuePair> params = URLEncodedUtils.parse(new URI(url), StandardCharsets.UTF_8);
for (NameValuePair pair : params) {
queryParams.put(pair.getName(), pair.getValue());
}
// possible caveat: duplicate entries overwrite earlier ones
}
catch (URISyntaxException e) {
throw new SQLException("Can't decode URI", e);
}
return new SqlTestFrameworkConfig(queryParams);
}
private void register()
{
try {

View File

@ -35,7 +35,9 @@ import org.apache.druid.sql.calcite.util.CacheTestHelperModule.ResultCacheMode;
import org.apache.druid.sql.calcite.util.SqlTestFramework;
import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier;
import org.apache.druid.sql.calcite.util.SqlTestFramework.StandardComponentSupplier;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.client.utils.URLEncodedUtils;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
@ -53,6 +55,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -417,6 +421,24 @@ public class SqlTestFrameworkConfig
return map;
}
public static SqlTestFrameworkConfig fromURL(String url) throws SQLException
{
Map<String, String> queryParams;
queryParams = new HashMap<>();
try {
List<NameValuePair> params = URLEncodedUtils.parse(new URI(url), StandardCharsets.UTF_8);
for (NameValuePair pair : params) {
queryParams.put(pair.getName(), pair.getValue());
}
// possible caveat: duplicate entries overwrite earlier ones
}
catch (URISyntaxException e) {
throw new SQLException("Can't decode URI", e);
}
return new SqlTestFrameworkConfig(queryParams);
}
abstract static class ConfigOptionProcessor<T>
{
final Class<? extends Annotation> annotationClass;