Skip to content

Commit

Permalink
Fix SegmentMetaDataLoader to use provided headers for requests (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyluoex authored and cdeszaq committed Nov 22, 2016
1 parent 5bd948b commit 9859fec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Current

### Changed:

- [SegmentMetadataLoader include provided request headers](https://github.com/yahoo/fili/pull/106)
* `SegmentMetadataLoader` sends requests with the provided request headers in `AsyncDruidWebservice` now
* Refactored `AsyncDruidWebserviceSpec` test and added test for checking `getJsonData` includes request headers as well

- [Include physical table name in warning log message for logicalToPhysical mapping](https://github.com/yahoo/fili/pull/94)
* Without this name, it's hard to know what table seems to be misconfigured.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,15 @@ public void getJsonObject(
String resourcePath
) {
String url = String.format("%s%s", serviceConfig.getUrl(), resourcePath);

BoundRequestBuilder requestBuilder = webClient.prepareGet(url);
headersToAppend.get().forEach(requestBuilder::addHeader);

sendRequest(
success,
error,
failure,
webClient.prepareGet(url),
requestBuilder,
DRUID_SEGMENT_METADATA_TIMER,
new AtomicLong(1)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,53 @@ import spock.lang.Specification
import java.util.function.Supplier

class AsyncDruidWebServiceImplSpec extends Specification {
def "Ensure that headersToAppend are added"() {
def "Ensure that headersToAppend are added to request when calling postDruidQuery"() {
setup:
WeightEvaluationQuery weightEvaluationQuery = Mock(WeightEvaluationQuery)
QueryContext queryContext = Mock(QueryContext)
weightEvaluationQuery.getContext() >> { queryContext }
queryContext.numberOfQueries() >> { 1 }
queryContext.getSequenceNumber() >> { 1 }
weightEvaluationQuery.getContext() >> queryContext

and:
Map<String, String> expectedHeaders = new HashMap<>()
expectedHeaders.put("k1", "v1")
expectedHeaders.put("k2", "v2")
Supplier<Map<String, String>> supplier = new Supplier<Map<String, String>>() {
@Override
Map<String, String> get() {
return expectedHeaders
}
Map<String, String> expectedHeaders = [
k1: "v1",
k2: "v2"
]
Supplier<Map<String, String>> supplier = Mock()
supplier.get() >> expectedHeaders

AsyncDruidWebServiceImplWrapper webServiceImplWrapper = new AsyncDruidWebServiceImplWrapper(
DruidClientConfigHelper.getNonUiServiceConfig(),
new ObjectMapper(),
supplier
)

when:
webServiceImplWrapper.postDruidQuery(null, null, null, null, weightEvaluationQuery);

then:
HttpHeaders actualHeaders = webServiceImplWrapper.getHeaders()
for (Map.Entry<String, String> header : expectedHeaders) {
assert actualHeaders.get(header.getKey()) == header.getValue()
}
}

def "Ensure that headersToAppend are added to request when calling getJsonObject"() {
setup:
Map<String, String> expectedHeaders = [
k1: "v1",
k2: "v2"
]
Supplier<Map<String, String>> supplier = Mock()
supplier.get() >> expectedHeaders

AsyncDruidWebServiceImplWrapper webServiceImplWrapper = new AsyncDruidWebServiceImplWrapper(
DruidClientConfigHelper.getNonUiServiceConfig(),
new ObjectMapper(),
supplier
)

when:
webServiceImplWrapper.postDruidQuery(
null,
null,
null,
null,
weightEvaluationQuery
);
webServiceImplWrapper.getJsonObject(null, null, null, null);

then:
HttpHeaders actualHeaders = webServiceImplWrapper.getHeaders()
Expand Down

0 comments on commit 9859fec

Please sign in to comment.