-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding unit test for the druid request headers.
- Loading branch information
1 parent
b632d50
commit bfebe62
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...st/groovy/com/yahoo/bard/webservice/druid/client/impl/AsyncDruidWebServiceImplSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.yahoo.bard.webservice.druid.client.impl | ||
|
||
import com.yahoo.bard.webservice.druid.client.DruidClientConfigHelper | ||
import com.yahoo.bard.webservice.druid.model.query.QueryContext | ||
import com.yahoo.bard.webservice.druid.model.query.WeightEvaluationQuery | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
|
||
import io.netty.handler.codec.http.HttpHeaders | ||
import spock.lang.Specification | ||
|
||
import java.util.function.Supplier | ||
|
||
class AsyncDruidWebServiceImplSpec extends Specification { | ||
def "Ensure that headersToAppend are added"() { | ||
setup: | ||
WeightEvaluationQuery weightEvaluationQuery = Mock(WeightEvaluationQuery) | ||
QueryContext queryContext = Mock(QueryContext) | ||
weightEvaluationQuery.getContext() >> { queryContext } | ||
queryContext.numberOfQueries() >> { 1 } | ||
queryContext.getSequenceNumber() >> { 1 } | ||
|
||
when: | ||
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 | ||
} | ||
} | ||
|
||
AsyncDruidWebServiceImplWrapper webServiceImplWrapper = new AsyncDruidWebServiceImplWrapper( | ||
DruidClientConfigHelper.getNonUiServiceConfig(), | ||
new ObjectMapper(), | ||
supplier | ||
) | ||
webServiceImplWrapper.postDruidQuery( | ||
null, | ||
null, | ||
null, | ||
null, | ||
weightEvaluationQuery | ||
); | ||
|
||
then: | ||
HttpHeaders actualHeaders = webServiceImplWrapper.getHeaders() | ||
for (Map.Entry<String, String> header : expectedHeaders) { | ||
actualHeaders.get(header.getKey()) == header.getValue() | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...est/java/com/yahoo/bard/webservice/druid/client/impl/AsyncDruidWebServiceImplWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2016 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.druid.client.impl; | ||
|
||
import com.yahoo.bard.webservice.druid.client.DruidServiceConfig; | ||
import com.yahoo.bard.webservice.druid.client.FailureCallback; | ||
import com.yahoo.bard.webservice.druid.client.HttpErrorCallback; | ||
import com.yahoo.bard.webservice.druid.client.SuccessCallback; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import org.asynchttpclient.BoundRequestBuilder; | ||
import org.asynchttpclient.Request; | ||
|
||
import io.netty.handler.codec.http.HttpHeaders; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Used for testing AsyncDruidWebServiceImpl. | ||
*/ | ||
public class AsyncDruidWebServiceImplWrapper extends AsyncDruidWebServiceImpl { | ||
public Request request; | ||
|
||
/** | ||
* Constructor wrapper. | ||
* | ||
* @param serviceConfig Service config | ||
* @param mapper Mapper | ||
* @param headersToAppend Headers | ||
*/ | ||
public AsyncDruidWebServiceImplWrapper( | ||
DruidServiceConfig serviceConfig, | ||
ObjectMapper mapper, | ||
Supplier<Map<String, String>> headersToAppend | ||
) { | ||
super(serviceConfig, mapper, headersToAppend); | ||
} | ||
|
||
/** | ||
* Capture arguments to test for expected values. | ||
* | ||
* @param success callback for handling successful requests. | ||
* @param error callback for handling http errors. | ||
* @param failure callback for handling exception failures. | ||
* @param requestBuilder The bound request builder for the request to be sent. | ||
* @param timerName The name that distinguishes this request as part of a druid query or segment metadata request | ||
* @param outstanding The counter that keeps track of the outstanding (in flight) requests for the top level query | ||
*/ | ||
@Override | ||
protected void sendRequest( | ||
final SuccessCallback success, | ||
final HttpErrorCallback error, | ||
final FailureCallback failure, | ||
final BoundRequestBuilder requestBuilder, | ||
final String timerName, | ||
final AtomicLong outstanding | ||
) { | ||
this.request = requestBuilder.build(); | ||
} | ||
|
||
public HttpHeaders getHeaders() { | ||
return request.getHeaders(); | ||
} | ||
} |