diff --git a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java index a07ef2c403fb..11e39bfa1267 100644 --- a/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java +++ b/extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java @@ -34,6 +34,7 @@ import org.apache.druid.msq.guice.MultiStageQuery; import org.apache.druid.msq.sql.MSQTaskSqlEngine; import org.apache.druid.query.QueryException; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.server.QueryResponse; import org.apache.druid.server.initialization.ServerConfig; import org.apache.druid.server.security.Access; @@ -47,7 +48,6 @@ import org.apache.druid.sql.http.ResultFormat; import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.sql.http.SqlResource; -import org.apache.druid.sql.http.SqlTaskStatus; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; diff --git a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java index 1a756910bf24..849ef1c4c2c0 100644 --- a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java +++ b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestAndQueryTest.java @@ -30,8 +30,8 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.query.QueryContexts; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; import org.apache.druid.testing.utils.DataLoaderHelper; import org.apache.druid.testing.utils.MsqTestQueryHelper; import org.apache.druid.testsEx.cluster.CatalogClient; diff --git a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java index e075462d0bb6..fa5489dca80c 100644 --- a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java +++ b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/catalog/ITCatalogIngestErrorTest.java @@ -27,8 +27,8 @@ import org.apache.druid.catalog.model.table.DatasourceDefn; import org.apache.druid.catalog.model.table.TableBuilder; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; import org.apache.druid.testing.utils.MsqTestQueryHelper; import org.apache.druid.testsEx.categories.Catalog; import org.apache.druid.testsEx.cluster.CatalogClient; diff --git a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java index b0dee9e713eb..8fb325b1c651 100644 --- a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java +++ b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITKeyStatisticsSketchMergeMode.java @@ -24,8 +24,8 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.msq.exec.ClusterStatisticsMergeMode; import org.apache.druid.msq.util.MultiStageQueryContext; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; import org.apache.druid.testing.clients.CoordinatorResourceTestClient; import org.apache.druid.testing.utils.DataLoaderHelper; import org.apache.druid.testing.utils.MsqTestQueryHelper; diff --git a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java index 13c3fdc38463..5cc405045fd1 100644 --- a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java +++ b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/ITMultiStageQueryWorkerFaultTolerance.java @@ -26,7 +26,7 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.msq.util.MultiStageQueryContext; -import org.apache.druid.sql.http.SqlTaskStatus; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.testing.clients.CoordinatorResourceTestClient; import org.apache.druid.testing.utils.DataLoaderHelper; import org.apache.druid.testing.utils.ITRetryUtil; diff --git a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/MultiStageQuery.java b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/MultiStageQuery.java index 3cdc57c37bfa..d77d5dfe2c99 100644 --- a/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/MultiStageQuery.java +++ b/integration-tests-ex/cases/src/test/java/org/apache/druid/testsEx/msq/MultiStageQuery.java @@ -29,7 +29,7 @@ import org.apache.druid.msq.indexing.report.MSQResultsReport; import org.apache.druid.msq.indexing.report.MSQTaskReport; import org.apache.druid.msq.indexing.report.MSQTaskReportPayload; -import org.apache.druid.sql.http.SqlTaskStatus; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.storage.local.LocalFileExportStorageProvider; import org.apache.druid.testing.clients.CoordinatorResourceTestClient; import org.apache.druid.testing.utils.DataLoaderHelper; diff --git a/integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java b/integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java index 2a4d04f42dbd..c4a70a475e5d 100644 --- a/integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java +++ b/integration-tests/src/main/java/org/apache/druid/testing/utils/MsqTestQueryHelper.java @@ -37,8 +37,8 @@ import org.apache.druid.msq.indexing.report.MSQResultsReport; import org.apache.druid.msq.indexing.report.MSQTaskReport; import org.apache.druid.msq.indexing.report.MSQTaskReportPayload; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; import org.apache.druid.testing.IntegrationTestingConfig; import org.apache.druid.testing.clients.OverlordResourceTestClient; import org.apache.druid.testing.clients.SqlResourceTestClient; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/ExplainAttributes.java b/processing/src/main/java/org/apache/druid/query/explain/ExplainAttributes.java similarity index 99% rename from sql/src/main/java/org/apache/druid/sql/calcite/planner/ExplainAttributes.java rename to processing/src/main/java/org/apache/druid/query/explain/ExplainAttributes.java index 533de7d58f2f..5c5a47356062 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/ExplainAttributes.java +++ b/processing/src/main/java/org/apache/druid/query/explain/ExplainAttributes.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.sql.calcite.planner; +package org.apache.druid.query.explain; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/sql/src/main/java/org/apache/druid/sql/http/ExplainPlan.java b/processing/src/main/java/org/apache/druid/query/explain/ExplainPlan.java similarity index 97% rename from sql/src/main/java/org/apache/druid/sql/http/ExplainPlan.java rename to processing/src/main/java/org/apache/druid/query/explain/ExplainPlan.java index 68defc4b2a4d..5e19aef7758d 100644 --- a/sql/src/main/java/org/apache/druid/sql/http/ExplainPlan.java +++ b/processing/src/main/java/org/apache/druid/query/explain/ExplainPlan.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.sql.http; +package org.apache.druid.query.explain; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; @@ -26,7 +26,6 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.apache.druid.sql.calcite.planner.ExplainAttributes; import java.io.IOException; import java.util.Objects; diff --git a/processing/src/main/java/org/apache/druid/query/http/ClientSqlParameter.java b/processing/src/main/java/org/apache/druid/query/http/ClientSqlParameter.java new file mode 100644 index 000000000000..cc562034e93a --- /dev/null +++ b/processing/src/main/java/org/apache/druid/query/http/ClientSqlParameter.java @@ -0,0 +1,76 @@ +/* + * 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.query.http; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +/** + * Client representation of {@link org.apache.druid.sql.http.SqlParameter}. This is effectively a lightweight POJO class + * for use by clients that excludes Calcite dependencies and server-side logic from the Broker. + */ +public class ClientSqlParameter +{ + @JsonProperty + private final String type; + + @JsonProperty + private final Object value; + + @JsonCreator + public ClientSqlParameter( + @JsonProperty("type") String type, + @JsonProperty("value") Object value + ) + { + this.type = type; + this.value = value; + } + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ClientSqlParameter that = (ClientSqlParameter) o; + return Objects.equals(type, that.type) && Objects.equals(value, that.value); + } + + @Override + public int hashCode() + { + return Objects.hash(type, value); + } + + @Override + public String toString() + { + return "ClientSqlParameter{" + + "type='" + type + '\'' + + ", value=" + value + + '}'; + } +} diff --git a/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java new file mode 100644 index 000000000000..3b3a2a239806 --- /dev/null +++ b/processing/src/main/java/org/apache/druid/query/http/ClientSqlQuery.java @@ -0,0 +1,151 @@ +/* + * 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.query.http; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Client representation of {@link org.apache.druid.sql.http.SqlQuery}. This is effectively a lightweight POJO class for + * use by clients such as {@link org.apache.druid.client.broker.BrokerClient} that doesn't bring in any of the + * Calcite dependencies and server-side logic from the Broker. + */ +public class ClientSqlQuery +{ + @JsonProperty + private final String query; + + @JsonProperty + private final String resultFormat; + + @JsonProperty + private final boolean header; + + @JsonProperty + private final boolean typesHeader; + + @JsonProperty + private final boolean sqlTypesHeader; + + @JsonProperty + private final Map context; + + @JsonProperty + private final List parameters; + + @JsonCreator + public ClientSqlQuery( + @JsonProperty("query") final String query, + @JsonProperty("resultFormat") final String resultFormat, + @JsonProperty("header") final boolean header, + @JsonProperty("typesHeader") final boolean typesHeader, + @JsonProperty("sqlTypesHeader") final boolean sqlTypesHeader, + @JsonProperty("context") final Map context, + @JsonProperty("parameters") final List parameters + ) + { + this.query = query; + this.resultFormat = resultFormat; + this.header = header; + this.typesHeader = typesHeader; + this.sqlTypesHeader = sqlTypesHeader; + this.context = context; + this.parameters = parameters; + } + + public String getQuery() + { + return query; + } + + public String getResultFormat() + { + return resultFormat; + } + + public boolean isHeader() + { + return header; + } + + public boolean isTypesHeader() + { + return typesHeader; + } + + public boolean isSqlTypesHeader() + { + return sqlTypesHeader; + } + + public Map getContext() + { + return context; + } + + public List getParameters() + { + return parameters; + } + + + @Override + public boolean equals(final Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ClientSqlQuery sqlQuery = (ClientSqlQuery) o; + return header == sqlQuery.header && + typesHeader == sqlQuery.typesHeader && + sqlTypesHeader == sqlQuery.sqlTypesHeader && + Objects.equals(query, sqlQuery.query) && + Objects.equals(resultFormat, sqlQuery.resultFormat) && + Objects.equals(context, sqlQuery.context) && + Objects.equals(parameters, sqlQuery.parameters); + } + + @Override + public int hashCode() + { + return Objects.hash(query, resultFormat, header, typesHeader, sqlTypesHeader, context, parameters); + } + + @Override + public String toString() + { + return "ClientSqlQuery{" + + "query='" + query + '\'' + + ", resultFormat=" + resultFormat + + ", header=" + header + + ", typesHeader=" + typesHeader + + ", sqlTypesHeader=" + sqlTypesHeader + + ", context=" + context + + ", parameters=" + parameters + + '}'; + } +} diff --git a/sql/src/main/java/org/apache/druid/sql/http/SqlTaskStatus.java b/processing/src/main/java/org/apache/druid/query/http/SqlTaskStatus.java similarity index 98% rename from sql/src/main/java/org/apache/druid/sql/http/SqlTaskStatus.java rename to processing/src/main/java/org/apache/druid/query/http/SqlTaskStatus.java index 765891ec20a1..557cc5a7db07 100644 --- a/sql/src/main/java/org/apache/druid/sql/http/SqlTaskStatus.java +++ b/processing/src/main/java/org/apache/druid/query/http/SqlTaskStatus.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.sql.http; +package org.apache.druid.query.http; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/planner/ExplainAttributesTest.java b/processing/src/test/java/org/apache/druid/query/explain/ExplainAttributesTest.java similarity index 98% rename from sql/src/test/java/org/apache/druid/sql/calcite/planner/ExplainAttributesTest.java rename to processing/src/test/java/org/apache/druid/query/explain/ExplainAttributesTest.java index d203dd340028..affaf6e3ddfb 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/planner/ExplainAttributesTest.java +++ b/processing/src/test/java/org/apache/druid/query/explain/ExplainAttributesTest.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.sql.calcite.planner; +package org.apache.druid.query.explain; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.druid.error.DruidException; @@ -38,7 +38,7 @@ public class ExplainAttributesTest public void testGetters() { final ExplainAttributes selectAttributes = new ExplainAttributes("SELECT", null, null, null, null); - Assert.assertEquals("SELECT", selectAttributes.getStatementType()); + assertEquals("SELECT", selectAttributes.getStatementType()); Assert.assertNull(selectAttributes.getTargetDataSource()); Assert.assertNull(selectAttributes.getPartitionedBy()); Assert.assertNull(selectAttributes.getClusteredBy()); diff --git a/sql/src/test/java/org/apache/druid/sql/http/ExplainPlanTest.java b/processing/src/test/java/org/apache/druid/query/explain/ExplainPlanTest.java similarity index 98% rename from sql/src/test/java/org/apache/druid/sql/http/ExplainPlanTest.java rename to processing/src/test/java/org/apache/druid/query/explain/ExplainPlanTest.java index e3385fc5f518..7ff56b7c6fd9 100644 --- a/sql/src/test/java/org/apache/druid/sql/http/ExplainPlanTest.java +++ b/processing/src/test/java/org/apache/druid/query/explain/ExplainPlanTest.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.sql.http; +package org.apache.druid.query.explain; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -27,7 +27,6 @@ import org.apache.druid.error.DruidException; import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.granularity.Granularities; -import org.apache.druid.sql.calcite.planner.ExplainAttributes; import org.junit.Test; import java.util.List; diff --git a/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java new file mode 100644 index 000000000000..10379b3146ac --- /dev/null +++ b/processing/src/test/java/org/apache/druid/query/http/ClientSqlQueryTest.java @@ -0,0 +1,62 @@ +/* + * 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.query.http; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import org.apache.druid.jackson.DefaultObjectMapper; +import org.junit.Assert; +import org.junit.Test; + +public class ClientSqlQueryTest +{ + @Test + public void testSerde() throws JsonProcessingException + { + final ObjectMapper jsonMapper = new DefaultObjectMapper(); + final ClientSqlQuery query = new ClientSqlQuery( + "SELECT 1", + "array", + true, + true, + true, + null, + null + ); + Assert.assertEquals(query, jsonMapper.readValue(jsonMapper.writeValueAsString(query), ClientSqlQuery.class)); + } + + @Test + public void testSerdeWithParameters() throws JsonProcessingException + { + final ObjectMapper jsonMapper = new DefaultObjectMapper(); + final ClientSqlQuery query = new ClientSqlQuery( + "SELECT 1", + "array", + true, + true, + true, + null, + ImmutableList.of(new ClientSqlParameter("ARRAY", ImmutableList.of(-25.7, 20.2, 36.85))) + ); + Assert.assertEquals(query, jsonMapper.readValue(jsonMapper.writeValueAsString(query), ClientSqlQuery.class)); + } +} diff --git a/sql/src/test/java/org/apache/druid/sql/http/SqlTaskStatusTest.java b/processing/src/test/java/org/apache/druid/query/http/SqlTaskStatusTest.java similarity index 98% rename from sql/src/test/java/org/apache/druid/sql/http/SqlTaskStatusTest.java rename to processing/src/test/java/org/apache/druid/query/http/SqlTaskStatusTest.java index c73e8d3cddbd..c587f44fdccd 100644 --- a/sql/src/test/java/org/apache/druid/sql/http/SqlTaskStatusTest.java +++ b/processing/src/test/java/org/apache/druid/query/http/SqlTaskStatusTest.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.sql.http; +package org.apache.druid.query.http; import com.fasterxml.jackson.databind.ObjectMapper; import nl.jqno.equalsverifier.EqualsVerifier; diff --git a/sql/src/main/java/org/apache/druid/sql/client/Broker.java b/server/src/main/java/org/apache/druid/client/broker/Broker.java similarity index 96% rename from sql/src/main/java/org/apache/druid/sql/client/Broker.java rename to server/src/main/java/org/apache/druid/client/broker/Broker.java index fb20c5166c8f..ac47c66a7cf5 100644 --- a/sql/src/main/java/org/apache/druid/sql/client/Broker.java +++ b/server/src/main/java/org/apache/druid/client/broker/Broker.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.sql.client; +package org.apache.druid.client.broker; import com.google.inject.BindingAnnotation; diff --git a/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java b/server/src/main/java/org/apache/druid/client/broker/BrokerClient.java similarity index 82% rename from sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java rename to server/src/main/java/org/apache/druid/client/broker/BrokerClient.java index 14cbbb7bff6a..611e6399ee69 100644 --- a/sql/src/main/java/org/apache/druid/sql/client/BrokerClient.java +++ b/server/src/main/java/org/apache/druid/client/broker/BrokerClient.java @@ -17,12 +17,12 @@ * under the License. */ -package org.apache.druid.sql.client; +package org.apache.druid.client.broker; import com.google.common.util.concurrent.ListenableFuture; -import org.apache.druid.sql.http.ExplainPlan; -import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; +import org.apache.druid.query.explain.ExplainPlan; +import org.apache.druid.query.http.ClientSqlQuery; +import org.apache.druid.query.http.SqlTaskStatus; import java.util.List; @@ -40,12 +40,12 @@ public interface BrokerClient /** * Submit the given {@code sqlQuery} to the Broker's SQL task endpoint. */ - ListenableFuture submitSqlTask(SqlQuery sqlQuery); + ListenableFuture submitSqlTask(ClientSqlQuery sqlQuery); /** * Fetches the explain plan for the given {@code sqlQuery} from the Broker's SQL task endpoint. * * @param sqlQuery the SQL query for which the {@code EXPLAIN PLAN FOR} information is to be fetched */ - ListenableFuture> fetchExplainPlan(SqlQuery sqlQuery); + ListenableFuture> fetchExplainPlan(ClientSqlQuery sqlQuery); } diff --git a/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java b/server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java similarity index 87% rename from sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java rename to server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java index b3e064341e63..012aea746181 100644 --- a/sql/src/main/java/org/apache/druid/sql/client/BrokerClientImpl.java +++ b/server/src/main/java/org/apache/druid/client/broker/BrokerClientImpl.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.druid.sql.client; +package org.apache.druid.client.broker; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -26,11 +26,11 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.jackson.JacksonUtils; import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler; +import org.apache.druid.query.explain.ExplainPlan; +import org.apache.druid.query.http.ClientSqlQuery; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.rpc.RequestBuilder; import org.apache.druid.rpc.ServiceClient; -import org.apache.druid.sql.http.ExplainPlan; -import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; import org.jboss.netty.handler.codec.http.HttpMethod; import java.util.List; @@ -47,7 +47,7 @@ public BrokerClientImpl(final ServiceClient client, final ObjectMapper jsonMappe } @Override - public ListenableFuture submitSqlTask(final SqlQuery sqlQuery) + public ListenableFuture submitSqlTask(final ClientSqlQuery sqlQuery) { return FutureUtils.transform( client.asyncRequest( @@ -60,9 +60,9 @@ public ListenableFuture submitSqlTask(final SqlQuery sqlQuery) } @Override - public ListenableFuture> fetchExplainPlan(final SqlQuery sqlQuery) + public ListenableFuture> fetchExplainPlan(final ClientSqlQuery sqlQuery) { - final SqlQuery explainSqlQuery = new SqlQuery( + final ClientSqlQuery explainSqlQuery = new ClientSqlQuery( StringUtils.format("EXPLAIN PLAN FOR %s", sqlQuery.getQuery()), null, false, diff --git a/server/src/main/java/org/apache/druid/rpc/guice/ServiceClientModule.java b/server/src/main/java/org/apache/druid/rpc/guice/ServiceClientModule.java index 94dfeb29d957..a0d9a5e3725c 100644 --- a/server/src/main/java/org/apache/druid/rpc/guice/ServiceClientModule.java +++ b/server/src/main/java/org/apache/druid/rpc/guice/ServiceClientModule.java @@ -22,6 +22,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Binder; import com.google.inject.Provides; +import org.apache.druid.client.broker.Broker; +import org.apache.druid.client.broker.BrokerClient; +import org.apache.druid.client.broker.BrokerClientImpl; import org.apache.druid.client.coordinator.Coordinator; import org.apache.druid.client.coordinator.CoordinatorClient; import org.apache.druid.client.coordinator.CoordinatorClientImpl; @@ -47,7 +50,7 @@ public class ServiceClientModule implements DruidModule { - public static final int CLIENT_MAX_ATTEMPTS = 6; + private static final int CLIENT_MAX_ATTEMPTS = 6; private static final int CONNECT_EXEC_THREADS = 4; @Override @@ -116,6 +119,32 @@ public CoordinatorClient makeCoordinatorClient( ); } + @Provides + @ManageLifecycle + @Broker + public ServiceLocator makeBrokerServiceLocator(final DruidNodeDiscoveryProvider discoveryProvider) + { + return new DiscoveryServiceLocator(discoveryProvider, NodeRole.BROKER); + } + + @Provides + @LazySingleton + public BrokerClient makeBrokerClient( + @Json final ObjectMapper jsonMapper, + @EscalatedGlobal final ServiceClientFactory clientFactory, + @Broker final ServiceLocator serviceLocator + ) + { + return new BrokerClientImpl( + clientFactory.makeClient( + NodeRole.BROKER.getJsonName(), + serviceLocator, + StandardRetryPolicy.builder().maxAttempts(ServiceClientModule.CLIENT_MAX_ATTEMPTS).build() + ), + jsonMapper + ); + } + public static ServiceClientFactory makeServiceClientFactory(@EscalatedGlobal final HttpClient httpClient) { final ScheduledExecutorService connectExec = diff --git a/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java b/server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java similarity index 88% rename from sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java rename to server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java index 51d66f03816d..90d1b49534d3 100644 --- a/sql/src/test/java/org/apache/druid/sql/client/BrokerClientImplTest.java +++ b/server/src/test/java/org/apache/druid/client/broker/BrokerClientImplTest.java @@ -17,24 +17,21 @@ * under the License. */ -package org.apache.druid.sql.client; +package org.apache.druid.client.broker; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import org.apache.calcite.avatica.SqlType; import org.apache.druid.indexer.TaskState; import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.Granularities; +import org.apache.druid.query.explain.ExplainAttributes; +import org.apache.druid.query.explain.ExplainPlan; +import org.apache.druid.query.http.ClientSqlQuery; +import org.apache.druid.query.http.SqlTaskStatus; import org.apache.druid.rpc.MockServiceClient; import org.apache.druid.rpc.RequestBuilder; -import org.apache.druid.sql.calcite.planner.ExplainAttributes; -import org.apache.druid.sql.http.ExplainPlan; -import org.apache.druid.sql.http.ResultFormat; -import org.apache.druid.sql.http.SqlParameter; -import org.apache.druid.sql.http.SqlQuery; -import org.apache.druid.sql.http.SqlTaskStatus; import org.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.junit.After; @@ -43,7 +40,6 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; - import java.util.List; import java.util.Map; @@ -72,14 +68,14 @@ public void tearDown() @Test public void testSubmitSqlTask() throws Exception { - final SqlQuery query = new SqlQuery( + final ClientSqlQuery query = new ClientSqlQuery( "REPLACE INTO foo OVERWRITE ALL SELECT * FROM bar PARTITIONED BY ALL", - ResultFormat.ARRAY, + null, true, true, true, ImmutableMap.of("useCache", false), - ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1)) + null ); final SqlTaskStatus taskStatus = new SqlTaskStatus("taskId1", TaskState.RUNNING, null); @@ -97,16 +93,16 @@ public void testSubmitSqlTask() throws Exception @Test public void testFetchExplainPlan() throws Exception { - final SqlQuery query = new SqlQuery( + final ClientSqlQuery query = new ClientSqlQuery( "REPLACE INTO foo OVERWRITE ALL SELECT * FROM bar PARTITIONED BY ALL", - ResultFormat.ARRAY, + null, true, true, true, ImmutableMap.of("useCache", false), - ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1)) + null ); - final SqlQuery explainQuery = new SqlQuery( + final ClientSqlQuery explainQuery = new ClientSqlQuery( StringUtils.format("EXPLAIN PLAN FOR %s", query.getQuery()), null, false, diff --git a/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java b/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java index 5d8a07d20a8a..94647fe64aef 100644 --- a/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java +++ b/server/src/test/java/org/apache/druid/rpc/guice/ServiceClientModuleTest.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList; import com.google.inject.Guice; import com.google.inject.Injector; +import org.apache.druid.client.broker.BrokerClient; import org.apache.druid.client.coordinator.CoordinatorClient; import org.apache.druid.discovery.DruidNodeDiscoveryProvider; import org.apache.druid.guice.DruidGuiceExtensions; @@ -96,4 +97,10 @@ public void testGetCoordinatorClient() { assertNotNull(injector.getInstance(CoordinatorClient.class)); } + + @Test + public void testGetBrokerClient() + { + assertNotNull(injector.getInstance(BrokerClient.class)); + } } diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java index 3569864cae78..49a943aded76 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/IngestHandler.java @@ -37,6 +37,7 @@ import org.apache.druid.error.DruidException; import org.apache.druid.error.InvalidSqlInput; import org.apache.druid.java.util.common.granularity.Granularity; +import org.apache.druid.query.explain.ExplainAttributes; import org.apache.druid.server.security.Action; import org.apache.druid.server.security.Resource; import org.apache.druid.server.security.ResourceAction; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java index c02cb3cd8bd7..51be1f93502a 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/PlannerContext.java @@ -39,6 +39,7 @@ import org.apache.druid.math.expr.ExprMacroTable; import org.apache.druid.query.QueryContext; import org.apache.druid.query.QueryContexts; +import org.apache.druid.query.explain.ExplainAttributes; import org.apache.druid.query.filter.InDimFilter; import org.apache.druid.query.filter.TypedInFilter; import org.apache.druid.query.lookup.LookupExtractor; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java index 67cc7f2f44c1..8481efdbcbd1 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java @@ -63,6 +63,7 @@ import org.apache.druid.java.util.emitter.EmittingLogger; import org.apache.druid.query.Query; import org.apache.druid.query.QueryContexts; +import org.apache.druid.query.explain.ExplainAttributes; import org.apache.druid.server.QueryResponse; import org.apache.druid.server.security.Action; import org.apache.druid.server.security.Resource; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java index 267feae1f0f3..393363587f7d 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/SqlStatementHandler.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.calcite.schema.SchemaPlus; import org.apache.druid.query.QueryContext; +import org.apache.druid.query.explain.ExplainAttributes; import org.apache.druid.server.security.ResourceAction; import org.apache.druid.sql.calcite.run.SqlEngine; import org.joda.time.DateTimeZone; diff --git a/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java b/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java deleted file mode 100644 index 05e022f83107..000000000000 --- a/sql/src/main/java/org/apache/druid/sql/guice/BrokerServiceModule.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.sql.guice; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.inject.Binder; -import com.google.inject.Provides; -import org.apache.druid.discovery.DruidNodeDiscoveryProvider; -import org.apache.druid.discovery.NodeRole; -import org.apache.druid.guice.LazySingleton; -import org.apache.druid.guice.ManageLifecycle; -import org.apache.druid.guice.annotations.EscalatedGlobal; -import org.apache.druid.guice.annotations.Json; -import org.apache.druid.initialization.DruidModule; -import org.apache.druid.java.util.http.client.HttpClient; -import org.apache.druid.rpc.DiscoveryServiceLocator; -import org.apache.druid.rpc.ServiceClientFactory; -import org.apache.druid.rpc.ServiceLocator; -import org.apache.druid.rpc.StandardRetryPolicy; -import org.apache.druid.rpc.guice.ServiceClientModule; -import org.apache.druid.sql.client.Broker; -import org.apache.druid.sql.client.BrokerClient; -import org.apache.druid.sql.client.BrokerClientImpl; - -/** - * Module that processes can install if they require a {@link BrokerClient}. - *

- * Similar to {@link ServiceClientModule}, but since {@link BrokerClient} depends - * on classes from the sql module, this is a separate module within the sql package. - *

- */ -public class BrokerServiceModule implements DruidModule -{ - @Override - public void configure(Binder binder) - { - // Nothing to do. - } - - @Provides - @LazySingleton - @EscalatedGlobal - public ServiceClientFactory getServiceClientFactory(@EscalatedGlobal final HttpClient httpClient) - { - return ServiceClientModule.makeServiceClientFactory(httpClient); - } - - @Provides - @ManageLifecycle - @Broker - public ServiceLocator makeBrokerServiceLocator(final DruidNodeDiscoveryProvider discoveryProvider) - { - return new DiscoveryServiceLocator(discoveryProvider, NodeRole.BROKER); - } - - @Provides - @LazySingleton - public BrokerClient makeBrokerClient( - @Json final ObjectMapper jsonMapper, - @EscalatedGlobal final ServiceClientFactory clientFactory, - @Broker final ServiceLocator serviceLocator - ) - { - return new BrokerClientImpl( - clientFactory.makeClient( - NodeRole.BROKER.getJsonName(), - serviceLocator, - StandardRetryPolicy.builder().maxAttempts(ServiceClientModule.CLIENT_MAX_ATTEMPTS).build() - ), - jsonMapper - ); - } -} - diff --git a/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java b/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java index 7e8e190d3efa..79c3a145fd61 100644 --- a/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java +++ b/sql/src/main/java/org/apache/druid/sql/http/SqlParameter.java @@ -34,6 +34,11 @@ import java.sql.Date; import java.util.Objects; +/** + * See {@link org.apache.druid.query.http.ClientSqlParameter} for the equivalent POJO class used on the client side. + * Note: The field {@link #type} relies on a Calcite data type, which prevents this class from being moved + * to the processing module for reuse. + */ public class SqlParameter { private final SqlType type; diff --git a/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java b/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java index 1364332aaa13..7b54ae39fadf 100644 --- a/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java +++ b/sql/src/main/java/org/apache/druid/sql/http/SqlQuery.java @@ -28,6 +28,7 @@ import org.apache.calcite.avatica.remote.TypedValue; import org.apache.druid.java.util.common.ISE; import org.apache.druid.query.QueryContext; +import org.apache.druid.query.http.ClientSqlQuery; import javax.annotation.Nullable; import java.util.List; @@ -35,6 +36,11 @@ import java.util.Objects; import java.util.stream.Collectors; +/** + * See {@link ClientSqlQuery} for the equivalent POJO class used on the client side to interact with the Broker. + * Note: The fields {@link #resultFormat} and {@link #parameters} rely on Calcite data types, + * preventing this class from being moved to the processing module for reuse. + */ public class SqlQuery { public static List getParameterList(List parameters) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java index f9c083864f34..fc62cb05fba7 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java @@ -19,11 +19,14 @@ package org.apache.druid.sql.calcite.http; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import nl.jqno.equalsverifier.EqualsVerifier; import org.apache.calcite.avatica.SqlType; +import org.apache.druid.query.http.ClientSqlParameter; +import org.apache.druid.query.http.ClientSqlQuery; import org.apache.druid.segment.TestHelper; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.http.ResultFormat; @@ -34,10 +37,11 @@ public class SqlQueryTest extends CalciteTestBase { + private static final ObjectMapper JSON_MAPPER = TestHelper.makeJsonMapper(); + @Test public void testSerde() throws Exception { - final ObjectMapper jsonMapper = TestHelper.makeJsonMapper(); final SqlQuery query = new SqlQuery( "SELECT ?", ResultFormat.ARRAY, @@ -47,7 +51,63 @@ public void testSerde() throws Exception ImmutableMap.of("useCache", false), ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1)) ); - Assert.assertEquals(query, jsonMapper.readValue(jsonMapper.writeValueAsString(query), SqlQuery.class)); + Assert.assertEquals(query, JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(query), SqlQuery.class)); + } + + @Test + public void testClientSqlQueryToSqlQueryConversion() throws JsonProcessingException + { + final ClientSqlQuery givenClientSqlQuery = new ClientSqlQuery( + "SELECT ?", + "array", + true, + true, + true, + ImmutableMap.of("useCache", false), + null + ); + + final SqlQuery expectedSqlQuery = new SqlQuery( + "SELECT ?", + ResultFormat.ARRAY, + true, + true, + true, + ImmutableMap.of("useCache", false), + null + ); + + final SqlQuery observedSqlQuery = + JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(givenClientSqlQuery), SqlQuery.class); + Assert.assertEquals(expectedSqlQuery, observedSqlQuery); + } + + @Test + public void testClientSqlQueryToSqlQueryConversion2() throws JsonProcessingException + { + final ClientSqlQuery givenClientSqlQuery = new ClientSqlQuery( + "SELECT ?", + "arrayLines", + false, + false, + false, + ImmutableMap.of("useCache", false), + ImmutableList.of(new ClientSqlParameter("INTEGER", 1), new ClientSqlParameter("VARCHAR", "foo")) + ); + + final SqlQuery expectedSqlQuery = new SqlQuery( + "SELECT ?", + ResultFormat.ARRAYLINES, + false, + false, + false, + ImmutableMap.of("useCache", false), + ImmutableList.of(new SqlParameter(SqlType.INTEGER, 1), new SqlParameter(SqlType.VARCHAR, "foo")) + ); + + final SqlQuery observedSqlQuery = + JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(givenClientSqlQuery), SqlQuery.class); + Assert.assertEquals(expectedSqlQuery, observedSqlQuery); } @Test diff --git a/sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java b/sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java deleted file mode 100644 index 9b59ad86733e..000000000000 --- a/sql/src/test/java/org/apache/druid/sql/guice/BrokerServiceModuleTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.sql.guice; - -import com.google.common.collect.ImmutableList; -import com.google.inject.ConfigurationException; -import com.google.inject.Guice; -import com.google.inject.Injector; -import org.apache.druid.client.coordinator.CoordinatorClient; -import org.apache.druid.discovery.DruidNodeDiscoveryProvider; -import org.apache.druid.guice.DruidGuiceExtensions; -import org.apache.druid.guice.LifecycleModule; -import org.apache.druid.guice.annotations.EscalatedGlobal; -import org.apache.druid.jackson.JacksonModule; -import org.apache.druid.java.util.http.client.HttpClient; -import org.apache.druid.rpc.ServiceClientFactory; -import org.apache.druid.rpc.ServiceLocator; -import org.apache.druid.rpc.indexing.OverlordClient; -import org.apache.druid.sql.client.BrokerClient; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; - -public class BrokerServiceModuleTest -{ - private Injector injector; - - @Rule - public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private HttpClient httpClient; - - @Mock - private DruidNodeDiscoveryProvider discoveryProvider; - - @Mock - private ServiceLocator serviceLocator; - - @Mock - private ServiceClientFactory serviceClientFactory; - - @Before - public void setUp() - { - injector = Guice.createInjector( - ImmutableList.of( - new DruidGuiceExtensions(), - new LifecycleModule(), - new JacksonModule(), - new BrokerServiceModule(), - binder -> { - binder.bind(HttpClient.class).annotatedWith(EscalatedGlobal.class).toInstance(httpClient); - binder.bind(ServiceLocator.class).toInstance(serviceLocator); - binder.bind(DruidNodeDiscoveryProvider.class).toInstance(discoveryProvider); - binder.bind(ServiceClientFactory.class).toInstance(serviceClientFactory); - } - ) - ); - } - - @Test - public void testGetServiceClientFactory() - { - assertNotNull(injector.getInstance(ServiceClientFactory.class)); - } - - @Test - public void testGetBrokerClient() - { - assertNotNull(injector.getInstance(BrokerClient.class)); - } - - @Test - public void testGetCoordinatorClient() - { - assertThrows( - ConfigurationException.class, - () -> injector.getInstance(CoordinatorClient.class) - ); - } - - @Test - public void testGetOverlordClient() - { - assertThrows( - ConfigurationException.class, - () -> injector.getInstance(OverlordClient.class) - ); - } -}