Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;

import static org.apache.http.HttpStatus.SC_OK;
import java.util.regex.Pattern;

/**
* The Http response handler.
*/
public class HttpResponseHandler extends AsyncCompletionHandler<Object> {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpResponseHandler.class.getName());

protected static final String SUCCESS_CODE_PATTERN = "^2.*";
private final RowManager rowManager;
private ColumnNameManager columnNameManager;
private Descriptors.Descriptor descriptor;
Expand Down Expand Up @@ -80,7 +81,8 @@ public void startTimer() {
@Override
public Object onCompleted(Response response) {
int statusCode = response.getStatusCode();
if (statusCode == SC_OK) {
boolean isSuccess = Pattern.compile(SUCCESS_CODE_PATTERN).matcher(String.valueOf(statusCode)).matches();
if (isSuccess) {
successHandler(response);
} else {
postResponseTelemetry.validateResponseCode(meterStatsManager, statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,29 @@ public void shouldNotPopulateResultAsObjectIfTypeIsNotPassedAndRetainResponseTyp
verify(meterStatsManager, times(1)).updateHistogram(any(Aspects.class), any(Long.class));
verify(resultFuture, times(1)).complete(Collections.singleton(resultStreamData));
}

@Test
public void shouldHandleAnySuccessResponseCodeOtherThan200() {
outputMapping.put("surge_factor", new OutputMapping("$.surge"));
outputColumnNames = Collections.singletonList("surge_factor");
columnNameManager = new ColumnNameManager(inputColumnNames, outputColumnNames);
httpSourceConfig = new HttpSourceConfig("http://localhost:8080/test", "POST", "{\"key\": \"%s\"}", "customer_id", "", "", "123", "234", false, httpConfigType, "345", headers, outputMapping, "metricId_02", false);
HttpResponseHandler httpResponseHandler = new HttpResponseHandler(httpSourceConfig, meterStatsManager, rowManager, columnNameManager, descriptor, resultFuture, errorReporter, new PostResponseTelemetry());
Row resultStreamData = new Row(2);
Row outputData = new Row(2);
outputData.setField(0, 0.732f);
resultStreamData.setField(0, inputData);
resultStreamData.setField(1, outputData);
when(response.getStatusCode()).thenReturn(201);
when(response.getResponseBody()).thenReturn("{\n"
+ " \"surge\": 0.732\n"
+ "}");

httpResponseHandler.startTimer();
httpResponseHandler.onCompleted(response);

verify(meterStatsManager, times(1)).markEvent(SUCCESS_RESPONSE);
verify(meterStatsManager, times(1)).updateHistogram(any(Aspects.class), any(Long.class));
verify(resultFuture, times(1)).complete(Collections.singleton(resultStreamData));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void shouldPopulateFieldFromPostgresWithCorrespondingDataType() throws Ex
+ "}";

configurationMap.put(PROCESSOR_POSTPROCESSOR_CONFIG_KEY, postProcessorConfigString);
Configuration configuration = new Configuration(ParameterTool.fromMap(configurationMap));
configuration = new Configuration(ParameterTool.fromMap(configurationMap));
stencilClientOrchestrator = new StencilClientOrchestrator(configuration);

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
Expand Down Expand Up @@ -249,7 +249,7 @@ public void shouldPopulateFieldFromPostgresWithSuccessResponseWithExternalAndInt
+ "}";

configurationMap.put(PROCESSOR_POSTPROCESSOR_CONFIG_KEY, postProcessorConfigWithInternalSourceString);
Configuration configuration = new Configuration(ParameterTool.fromMap(configurationMap));
configuration = new Configuration(ParameterTool.fromMap(configurationMap));
stencilClientOrchestrator = new StencilClientOrchestrator(configuration);

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
Expand Down Expand Up @@ -324,7 +324,7 @@ public void shouldPopulateFieldFromPostgresOnSuccessResponseWithAllThreeSourcesI
+ "}";

configurationMap.put(PROCESSOR_POSTPROCESSOR_CONFIG_KEY, postProcessorConfigWithTransformerString);
Configuration configuration = new Configuration(ParameterTool.fromMap(configurationMap));
configuration = new Configuration(ParameterTool.fromMap(configurationMap));
stencilClientOrchestrator = new StencilClientOrchestrator(configuration);

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.6.1