jihoonson commented on a change in pull request #10980:
URL: https://github.com/apache/druid/pull/10980#discussion_r616360076
##########
File path:
integration-tests/src/main/java/org/apache/druid/testing/clients/QueryResourceTestClient.java
##########
@@ -50,4 +62,23 @@ public String getBrokerURL()
);
}
+ /**
+ * clone a new instance of current object with given encoding.
+ * Note: For {@link AbstractQueryResourceTestClient#queryAsync(String,
Object)} operation, contentType could only be application/json
+ *
+ * @param contentType Content-Type header of request. Cannot be NULL. Both
application/json and application/x-jackson-smile are allowed
+ * @param accept Accept header of request. Both application/json and
application/x-jackson-smile are allowed
+ */
+ public QueryResourceTestClient withEncoding(String contentType, String
accept)
Review comment:
nit: please add `@Nullable` for `accept`.
##########
File path:
integration-tests/src/main/java/org/apache/druid/testing/clients/AbstractQueryResourceTestClient.java
##########
@@ -21,67 +21,157 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
import com.google.inject.Inject;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.http.client.HttpClient;
import org.apache.druid.java.util.http.client.Request;
+import
org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
import org.apache.druid.java.util.http.client.response.StatusResponseHandler;
import org.apache.druid.java.util.http.client.response.StatusResponseHolder;
-import org.apache.druid.testing.IntegrationTestingConfig;
import org.apache.druid.testing.guice.TestClient;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
public abstract class AbstractQueryResourceTestClient<QueryType>
{
- private final ObjectMapper jsonMapper;
- private final HttpClient httpClient;
+ private String contentTypeHeader = MediaType.APPLICATION_JSON;
+
+ /**
+ * a 'null' means the Content-Type in response defaults to Content-Type of
request
+ */
+ private String acceptHeader = null;
+
+ final ObjectMapper jsonMapper;
+ final ObjectMapper smileMapper;
+ final HttpClient httpClient;
final String routerUrl;
+ final Map<String, EncoderDecoder<QueryType>> encoderDecoderMap;
+
+ protected void setContentTypeHeader(String contentTypeHeader)
Review comment:
I find mutable variables confusing because it makes the class to be
stateful. This method is called only in
`QueryResourceTestClient.withEncoding()`. Can we set `contentTypeHeader` and
`acceptHeader` in the constructor and make them final? If you did this because
of `SqlResourceTestClient` not supporting smile format, I think it's OK to make
`SqlResourceTestClient` ugly (like its constructor accepts `contentTypeHeader`
and `acceptHeader` but their values must be json) because we will eventually
want to support smile for sqls.
##########
File path:
integration-tests/src/main/java/org/apache/druid/testing/clients/AbstractQueryResourceTestClient.java
##########
@@ -21,67 +21,157 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
import com.google.inject.Inject;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.http.client.HttpClient;
import org.apache.druid.java.util.http.client.Request;
+import
org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
import org.apache.druid.java.util.http.client.response.StatusResponseHandler;
import org.apache.druid.java.util.http.client.response.StatusResponseHolder;
-import org.apache.druid.testing.IntegrationTestingConfig;
import org.apache.druid.testing.guice.TestClient;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
public abstract class AbstractQueryResourceTestClient<QueryType>
{
- private final ObjectMapper jsonMapper;
- private final HttpClient httpClient;
+ private String contentTypeHeader = MediaType.APPLICATION_JSON;
+
+ /**
+ * a 'null' means the Content-Type in response defaults to Content-Type of
request
+ */
+ private String acceptHeader = null;
+
+ final ObjectMapper jsonMapper;
+ final ObjectMapper smileMapper;
+ final HttpClient httpClient;
final String routerUrl;
+ final Map<String, EncoderDecoder<QueryType>> encoderDecoderMap;
Review comment:
nit: out of curiosity, are this map and the fancy `EncoderDecoder`
interface for more extendable structure where we want to support new formats in
the future?
##########
File path:
integration-tests/src/main/java/org/apache/druid/testing/clients/AbstractQueryResourceTestClient.java
##########
@@ -21,67 +21,157 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
import com.google.inject.Inject;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.http.client.HttpClient;
import org.apache.druid.java.util.http.client.Request;
+import
org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
import org.apache.druid.java.util.http.client.response.StatusResponseHandler;
import org.apache.druid.java.util.http.client.response.StatusResponseHolder;
-import org.apache.druid.testing.IntegrationTestingConfig;
import org.apache.druid.testing.guice.TestClient;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
public abstract class AbstractQueryResourceTestClient<QueryType>
{
- private final ObjectMapper jsonMapper;
- private final HttpClient httpClient;
+ private String contentTypeHeader = MediaType.APPLICATION_JSON;
+
+ /**
+ * a 'null' means the Content-Type in response defaults to Content-Type of
request
+ */
+ private String acceptHeader = null;
+
+ final ObjectMapper jsonMapper;
+ final ObjectMapper smileMapper;
+ final HttpClient httpClient;
final String routerUrl;
+ final Map<String, EncoderDecoder<QueryType>> encoderDecoderMap;
+
+ protected void setContentTypeHeader(String contentTypeHeader)
+ {
+ if (!this.encoderDecoderMap.containsKey(contentTypeHeader)) {
+ throw new IAE("Invalid Content-Type[%s]", contentTypeHeader);
+ }
+ this.contentTypeHeader = contentTypeHeader;
+ }
+
+ protected void setAcceptHeader(String acceptHeader)
+ {
+ if (acceptHeader != null) {
+ if (!this.encoderDecoderMap.containsKey(acceptHeader)) {
+ throw new IAE("Invalid Accept[%s]", acceptHeader);
+ }
+ }
+ this.acceptHeader = acceptHeader;
+ }
+
+ /**
+ * A encoder/decoder encodes/decods request/response based on value of
Content-Type
Review comment:
```suggestion
* A encoder/decoder that encodes/decodes requests/responses based on
Content-Type.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]