Skip to content

Commit 650c8e2

Browse files
authored
fix: fix success response code and postgre integration test checkstyle (#212)
1 parent 5f0d292 commit 650c8e2

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

dagger-core/src/main/java/io/odpf/dagger/core/processors/external/http/HttpResponseHandler.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
import java.util.ArrayList;
2626
import java.util.Collections;
2727
import java.util.Map;
28-
29-
import static org.apache.http.HttpStatus.SC_OK;
28+
import java.util.regex.Pattern;
3029

3130
/**
3231
* The Http response handler.
3332
*/
3433
public class HttpResponseHandler extends AsyncCompletionHandler<Object> {
3534
private static final Logger LOGGER = LoggerFactory.getLogger(HttpResponseHandler.class.getName());
35+
36+
protected static final String SUCCESS_CODE_PATTERN = "^2.*";
3637
private final RowManager rowManager;
3738
private ColumnNameManager columnNameManager;
3839
private Descriptors.Descriptor descriptor;
@@ -80,7 +81,8 @@ public void startTimer() {
8081
@Override
8182
public Object onCompleted(Response response) {
8283
int statusCode = response.getStatusCode();
83-
if (statusCode == SC_OK) {
84+
boolean isSuccess = Pattern.compile(SUCCESS_CODE_PATTERN).matcher(String.valueOf(statusCode)).matches();
85+
if (isSuccess) {
8486
successHandler(response);
8587
} else {
8688
postResponseTelemetry.validateResponseCode(meterStatsManager, statusCode);

dagger-core/src/test/java/io/odpf/dagger/core/processors/external/http/HttpResponseHandlerTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,29 @@ public void shouldNotPopulateResultAsObjectIfTypeIsNotPassedAndRetainResponseTyp
400400
verify(meterStatsManager, times(1)).updateHistogram(any(Aspects.class), any(Long.class));
401401
verify(resultFuture, times(1)).complete(Collections.singleton(resultStreamData));
402402
}
403+
404+
@Test
405+
public void shouldHandleAnySuccessResponseCodeOtherThan200() {
406+
outputMapping.put("surge_factor", new OutputMapping("$.surge"));
407+
outputColumnNames = Collections.singletonList("surge_factor");
408+
columnNameManager = new ColumnNameManager(inputColumnNames, outputColumnNames);
409+
httpSourceConfig = new HttpSourceConfig("http://localhost:8080/test", "POST", "{\"key\": \"%s\"}", "customer_id", "", "", "123", "234", false, httpConfigType, "345", headers, outputMapping, "metricId_02", false);
410+
HttpResponseHandler httpResponseHandler = new HttpResponseHandler(httpSourceConfig, meterStatsManager, rowManager, columnNameManager, descriptor, resultFuture, errorReporter, new PostResponseTelemetry());
411+
Row resultStreamData = new Row(2);
412+
Row outputData = new Row(2);
413+
outputData.setField(0, 0.732f);
414+
resultStreamData.setField(0, inputData);
415+
resultStreamData.setField(1, outputData);
416+
when(response.getStatusCode()).thenReturn(201);
417+
when(response.getResponseBody()).thenReturn("{\n"
418+
+ " \"surge\": 0.732\n"
419+
+ "}");
420+
421+
httpResponseHandler.startTimer();
422+
httpResponseHandler.onCompleted(response);
423+
424+
verify(meterStatsManager, times(1)).markEvent(SUCCESS_RESPONSE);
425+
verify(meterStatsManager, times(1)).updateHistogram(any(Aspects.class), any(Long.class));
426+
verify(resultFuture, times(1)).complete(Collections.singleton(resultStreamData));
427+
}
403428
}

dagger-tests/src/integrationtest/java/io/odpf/dagger/integrationtest/PostGresExternalPostProcessorIntegrationTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void shouldPopulateFieldFromPostgresWithCorrespondingDataType() throws Ex
191191
+ "}";
192192

193193
configurationMap.put(PROCESSOR_POSTPROCESSOR_CONFIG_KEY, postProcessorConfigString);
194-
Configuration configuration = new Configuration(ParameterTool.fromMap(configurationMap));
194+
configuration = new Configuration(ParameterTool.fromMap(configurationMap));
195195
stencilClientOrchestrator = new StencilClientOrchestrator(configuration);
196196

197197
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
@@ -249,7 +249,7 @@ public void shouldPopulateFieldFromPostgresWithSuccessResponseWithExternalAndInt
249249
+ "}";
250250

251251
configurationMap.put(PROCESSOR_POSTPROCESSOR_CONFIG_KEY, postProcessorConfigWithInternalSourceString);
252-
Configuration configuration = new Configuration(ParameterTool.fromMap(configurationMap));
252+
configuration = new Configuration(ParameterTool.fromMap(configurationMap));
253253
stencilClientOrchestrator = new StencilClientOrchestrator(configuration);
254254

255255
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
@@ -324,7 +324,7 @@ public void shouldPopulateFieldFromPostgresOnSuccessResponseWithAllThreeSourcesI
324324
+ "}";
325325

326326
configurationMap.put(PROCESSOR_POSTPROCESSOR_CONFIG_KEY, postProcessorConfigWithTransformerString);
327-
Configuration configuration = new Configuration(ParameterTool.fromMap(configurationMap));
327+
configuration = new Configuration(ParameterTool.fromMap(configurationMap));
328328
stencilClientOrchestrator = new StencilClientOrchestrator(configuration);
329329

330330
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.6.0
1+
0.6.1

0 commit comments

Comments
 (0)