mirror of https://github.com/apache/druid.git
support jdbc even if trailing / is missing (#11737)
* support jdbc even if trailing / is missing * fix tests
This commit is contained in:
parent
335b582377
commit
11017ef00a
|
@ -445,12 +445,14 @@ public abstract class AbstractAuthConfigurationTest
|
||||||
public void test_avaticaQuery_broker()
|
public void test_avaticaQuery_broker()
|
||||||
{
|
{
|
||||||
testAvaticaQuery(getBrokerAvacticaUrl());
|
testAvaticaQuery(getBrokerAvacticaUrl());
|
||||||
|
testAvaticaQuery(StringUtils.maybeRemoveTrailingSlash(getBrokerAvacticaUrl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_avaticaQuery_router()
|
public void test_avaticaQuery_router()
|
||||||
{
|
{
|
||||||
testAvaticaQuery(getRouterAvacticaUrl());
|
testAvaticaQuery(getRouterAvacticaUrl());
|
||||||
|
testAvaticaQuery(StringUtils.maybeRemoveTrailingSlash(getRouterAvacticaUrl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -59,7 +59,9 @@ public class RouterJettyServerInitializer implements JettyServerInitializer
|
||||||
// The router will keep the connection context in the forwarded message, and the broker is responsible for
|
// The router will keep the connection context in the forwarded message, and the broker is responsible for
|
||||||
// performing the auth checks.
|
// performing the auth checks.
|
||||||
DruidAvaticaJsonHandler.AVATICA_PATH,
|
DruidAvaticaJsonHandler.AVATICA_PATH,
|
||||||
DruidAvaticaProtobufHandler.AVATICA_PATH
|
DruidAvaticaJsonHandler.AVATICA_PATH_NO_TRAILING_SLASH,
|
||||||
|
DruidAvaticaProtobufHandler.AVATICA_PATH,
|
||||||
|
DruidAvaticaProtobufHandler.AVATICA_PATH_NO_TRAILING_SLASH
|
||||||
);
|
);
|
||||||
|
|
||||||
private final DruidHttpClientConfig routerHttpClientConfig;
|
private final DruidHttpClientConfig routerHttpClientConfig;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.calcite.avatica.remote.LocalService;
|
||||||
import org.apache.calcite.avatica.remote.Service;
|
import org.apache.calcite.avatica.remote.Service;
|
||||||
import org.apache.calcite.avatica.server.AvaticaJsonHandler;
|
import org.apache.calcite.avatica.server.AvaticaJsonHandler;
|
||||||
import org.apache.druid.guice.annotations.Self;
|
import org.apache.druid.guice.annotations.Self;
|
||||||
|
import org.apache.druid.java.util.common.StringUtils;
|
||||||
import org.apache.druid.server.DruidNode;
|
import org.apache.druid.server.DruidNode;
|
||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ import java.io.IOException;
|
||||||
public class DruidAvaticaJsonHandler extends AvaticaJsonHandler
|
public class DruidAvaticaJsonHandler extends AvaticaJsonHandler
|
||||||
{
|
{
|
||||||
public static final String AVATICA_PATH = "/druid/v2/sql/avatica/";
|
public static final String AVATICA_PATH = "/druid/v2/sql/avatica/";
|
||||||
|
public static final String AVATICA_PATH_NO_TRAILING_SLASH = "/druid/v2/sql/avatica";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DruidAvaticaJsonHandler(
|
public DruidAvaticaJsonHandler(
|
||||||
|
@ -55,7 +57,7 @@ public class DruidAvaticaJsonHandler extends AvaticaJsonHandler
|
||||||
final HttpServletResponse response
|
final HttpServletResponse response
|
||||||
) throws IOException, ServletException
|
) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
if (request.getRequestURI().equals(AVATICA_PATH)) {
|
if (AVATICA_PATH_NO_TRAILING_SLASH.equals(StringUtils.maybeRemoveTrailingSlash(request.getRequestURI()))) {
|
||||||
super.handle(target, baseRequest, request, response);
|
super.handle(target, baseRequest, request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.calcite.avatica.remote.LocalService;
|
||||||
import org.apache.calcite.avatica.remote.Service;
|
import org.apache.calcite.avatica.remote.Service;
|
||||||
import org.apache.calcite.avatica.server.AvaticaProtobufHandler;
|
import org.apache.calcite.avatica.server.AvaticaProtobufHandler;
|
||||||
import org.apache.druid.guice.annotations.Self;
|
import org.apache.druid.guice.annotations.Self;
|
||||||
|
import org.apache.druid.java.util.common.StringUtils;
|
||||||
import org.apache.druid.server.DruidNode;
|
import org.apache.druid.server.DruidNode;
|
||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ import java.io.IOException;
|
||||||
public class DruidAvaticaProtobufHandler extends AvaticaProtobufHandler
|
public class DruidAvaticaProtobufHandler extends AvaticaProtobufHandler
|
||||||
{
|
{
|
||||||
public static final String AVATICA_PATH = "/druid/v2/sql/avatica-protobuf/";
|
public static final String AVATICA_PATH = "/druid/v2/sql/avatica-protobuf/";
|
||||||
|
public static final String AVATICA_PATH_NO_TRAILING_SLASH = "/druid/v2/sql/avatica-protobuf";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DruidAvaticaProtobufHandler(
|
public DruidAvaticaProtobufHandler(
|
||||||
|
@ -55,7 +57,7 @@ public class DruidAvaticaProtobufHandler extends AvaticaProtobufHandler
|
||||||
final HttpServletResponse response
|
final HttpServletResponse response
|
||||||
) throws IOException, ServletException
|
) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
if (request.getRequestURI().equals(AVATICA_PATH)) {
|
if (AVATICA_PATH_NO_TRAILING_SLASH.equals(StringUtils.maybeRemoveTrailingSlash(request.getRequestURI()))) {
|
||||||
super.handle(target, baseRequest, request, response);
|
super.handle(target, baseRequest, request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ public abstract class DruidAvaticaHandlerTest extends CalciteTestBase
|
||||||
public int getMaxConnections()
|
public int getMaxConnections()
|
||||||
{
|
{
|
||||||
// This must match the number of Connection objects created in setUp()
|
// This must match the number of Connection objects created in setUp()
|
||||||
return 3;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -156,6 +156,7 @@ public abstract class DruidAvaticaHandlerTest extends CalciteTestBase
|
||||||
private SpecificSegmentsQuerySegmentWalker walker;
|
private SpecificSegmentsQuerySegmentWalker walker;
|
||||||
private Server server;
|
private Server server;
|
||||||
private Connection client;
|
private Connection client;
|
||||||
|
private Connection clientNoTrailingSlash;
|
||||||
private Connection superuserClient;
|
private Connection superuserClient;
|
||||||
private Connection clientLosAngeles;
|
private Connection clientLosAngeles;
|
||||||
private DruidMeta druidMeta;
|
private DruidMeta druidMeta;
|
||||||
|
@ -221,6 +222,7 @@ public abstract class DruidAvaticaHandlerTest extends CalciteTestBase
|
||||||
url = this.getJdbcConnectionString(port);
|
url = this.getJdbcConnectionString(port);
|
||||||
client = DriverManager.getConnection(url, "regularUser", "druid");
|
client = DriverManager.getConnection(url, "regularUser", "druid");
|
||||||
superuserClient = DriverManager.getConnection(url, CalciteTests.TEST_SUPERUSER_NAME, "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();
|
final Properties propertiesLosAngeles = new Properties();
|
||||||
propertiesLosAngeles.setProperty("sqlTimeZone", "America/Los_Angeles");
|
propertiesLosAngeles.setProperty("sqlTimeZone", "America/Los_Angeles");
|
||||||
|
@ -234,11 +236,13 @@ public abstract class DruidAvaticaHandlerTest extends CalciteTestBase
|
||||||
{
|
{
|
||||||
client.close();
|
client.close();
|
||||||
clientLosAngeles.close();
|
clientLosAngeles.close();
|
||||||
|
clientNoTrailingSlash.close();
|
||||||
server.stop();
|
server.stop();
|
||||||
walker.close();
|
walker.close();
|
||||||
walker = null;
|
walker = null;
|
||||||
client = null;
|
client = null;
|
||||||
clientLosAngeles = null;
|
clientLosAngeles = null;
|
||||||
|
clientNoTrailingSlash = null;
|
||||||
server = null;
|
server = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +259,19 @@ public abstract class DruidAvaticaHandlerTest extends CalciteTestBase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSelectCountNoTrailingSlash() throws Exception
|
||||||
|
{
|
||||||
|
final ResultSet resultSet = clientNoTrailingSlash.createStatement().executeQuery("SELECT COUNT(*) AS cnt FROM druid.foo");
|
||||||
|
final List<Map<String, Object>> rows = getRows(resultSet);
|
||||||
|
Assert.assertEquals(
|
||||||
|
ImmutableList.of(
|
||||||
|
ImmutableMap.of("cnt", 6L)
|
||||||
|
),
|
||||||
|
rows
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSelectCountAlternateStyle() throws Exception
|
public void testSelectCountAlternateStyle() throws Exception
|
||||||
{
|
{
|
||||||
|
@ -811,19 +828,15 @@ public abstract class DruidAvaticaHandlerTest extends CalciteTestBase
|
||||||
@Test
|
@Test
|
||||||
public void testTooManyConnections() throws Exception
|
public void testTooManyConnections() throws Exception
|
||||||
{
|
{
|
||||||
final Connection connection1 = DriverManager.getConnection(url);
|
client.createStatement();
|
||||||
final Statement statement1 = connection1.createStatement();
|
clientLosAngeles.createStatement();
|
||||||
|
superuserClient.createStatement();
|
||||||
final Connection connection2 = DriverManager.getConnection(url);
|
clientNoTrailingSlash.createStatement();
|
||||||
final Statement statement2 = connection2.createStatement();
|
|
||||||
|
|
||||||
final Connection connection3 = DriverManager.getConnection(url);
|
|
||||||
final Statement statement3 = connection3.createStatement();
|
|
||||||
|
|
||||||
expectedException.expect(AvaticaClientRuntimeException.class);
|
expectedException.expect(AvaticaClientRuntimeException.class);
|
||||||
expectedException.expectMessage("Too many connections, limit is[3]");
|
expectedException.expectMessage("Too many connections, limit is[4]");
|
||||||
|
|
||||||
final Connection connection4 = DriverManager.getConnection(url);
|
final Connection connection5 = DriverManager.getConnection(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue