-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ISSUE-70 Send all the failed message to the error reporter topic #69
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -47,6 +47,7 @@ public class AEPSinkConnectorErrorReporterTest extends AbstractConnectorTest { | |
private static final String AEP_KAFKA_ERROR_CONNECTOR_CONFIG = "aep-connector-error-reporter.json"; | ||
private static final String AEP_KAFKA_ERROR_CONNECTOR_HEADER_CONFIG = "aep-connector-error-reporter-header.json"; | ||
private static final String XDM_PAYLOAD_FILE = "xdm-data.json"; | ||
private static final String XDM_MULTI_MESSAGE_PAYLOAD_FILE = "xdm-data-multiple-messages.json"; | ||
private static final String DEAD_LETTER_TOPIC = "errors.deadletterqueue.topic.name"; | ||
private static final String ERROR_CLASS_NAME = "__connect.errors.exception.class.name"; | ||
private static final String ERROR_HEADER_MESSAGE = "__connect.errors.exception.message"; | ||
|
@@ -70,7 +71,7 @@ public void kafkaErrorReporterTest() throws HttpException, IOException, Interrup | |
LOG.info("Starting connector cluster with connector : {}", CONNECTOR_NAME); | ||
getConnect().configureConnector(CONNECTOR_NAME, connectorConfig); | ||
|
||
String xdmData = xdmData(); | ||
String xdmData = xdmData(XDM_PAYLOAD_FILE); | ||
getConnect().kafka().produce(TOPIC_NAME, xdmData); | ||
waitForConnectorStart(CONNECTOR_NAME, 1, 8000); | ||
|
||
|
@@ -87,7 +88,89 @@ public void kafkaErrorReporterTest() throws HttpException, IOException, Interrup | |
|
||
// Verify inlet endpoint received 1 XDM record | ||
getWiremockServer().verify(postRequestedFor(urlEqualTo(getRelativeUrl())) | ||
.withRequestBody(equalToJson(payloadReceivedXdmData()))); | ||
.withRequestBody(equalToJson(payloadReceivedXdmData(XDM_PAYLOAD_FILE)))); | ||
} | ||
|
||
@Test | ||
public void kafkaErrorReporterMultiMessageTest() throws HttpException, IOException, InterruptedException { | ||
inletMultiStatusSuccessfulResponse(); | ||
getConnect().kafka().createTopic(TOPIC_NAME, TOPIC_PARTITION); | ||
|
||
// Create error topic to dump failed data | ||
Map<String, String> connectorConfig = connectorConfig(AEP_KAFKA_ERROR_CONNECTOR_CONFIG); | ||
getConnect().kafka().createTopic(connectorConfig.get(DEAD_LETTER_TOPIC), TOPIC_PARTITION); | ||
|
||
LOG.info("Starting connector cluster with connector : {}", CONNECTOR_NAME); | ||
getConnect().configureConnector(CONNECTOR_NAME, connectorConfig); | ||
|
||
String xdmData = xdmData(XDM_MULTI_MESSAGE_PAYLOAD_FILE); | ||
ArrayNode xdmDataValues = (ArrayNode)JacksonFactory.OBJECT_MAPPER.readTree(xdmData); | ||
String failedMessage = xdmDataValues.get(0).toString(); | ||
String successMessage = xdmDataValues.get(1).toString(); | ||
|
||
getConnect().kafka().produce(TOPIC_NAME, failedMessage); | ||
getConnect().kafka().produce(TOPIC_NAME, successMessage); | ||
|
||
waitForConnectorStart(CONNECTOR_NAME, 1, 8000); | ||
|
||
// Check if error record sent to error topic | ||
ConsumerRecords<byte[], byte[]> consumerRecords = getConnect().kafka() | ||
.consume(1, 8000, connectorConfig.get(DEAD_LETTER_TOPIC)); | ||
|
||
Assertions.assertEquals(1, consumerRecords.count()); | ||
|
||
ConsumerRecord<byte[], byte[]> consumerRecord = consumerRecords.iterator().next(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add following properties to connector config and test if headers have all error information -
|
||
JsonNode record = JacksonFactory.OBJECT_MAPPER.readTree(consumerRecord.value()); | ||
|
||
Assertions.assertEquals(JacksonFactory.OBJECT_MAPPER.readTree(failedMessage).toString(), record.toString()); | ||
|
||
// Verify inlet endpoint received 2 XDM record | ||
getWiremockServer().verify(postRequestedFor(urlEqualTo(getRelativeUrl())) | ||
.withRequestBody(equalToJson(payloadReceivedMultiMessageXdmData(XDM_MULTI_MESSAGE_PAYLOAD_FILE)))); | ||
} | ||
|
||
@Test | ||
public void kafkaErrorReporterMultiMessageWithHeadersTest() throws HttpException, IOException, InterruptedException { | ||
inletMultiStatusSuccessfulResponse(); | ||
|
||
getConnect().kafka().createTopic(TOPIC_NAME, TOPIC_PARTITION); | ||
|
||
// Create error topic to dump failed data | ||
Map<String, String> connectorConfig = connectorConfig(AEP_KAFKA_ERROR_CONNECTOR_HEADER_CONFIG); | ||
getConnect().kafka().createTopic(connectorConfig.get(DEAD_LETTER_TOPIC), TOPIC_PARTITION); | ||
|
||
LOG.info("Starting connector cluster with connector : {}", CONNECTOR_NAME); | ||
getConnect().configureConnector(CONNECTOR_NAME, connectorConfig); | ||
|
||
String xdmData = xdmData(XDM_MULTI_MESSAGE_PAYLOAD_FILE); | ||
ArrayNode xdmDataValues = (ArrayNode)JacksonFactory.OBJECT_MAPPER.readTree(xdmData); | ||
String failedMessage = xdmDataValues.get(0).toString(); | ||
String successMessage = xdmDataValues.get(1).toString(); | ||
getConnect().kafka().produce(TOPIC_NAME, failedMessage); | ||
getConnect().kafka().produce(TOPIC_NAME, successMessage); | ||
|
||
waitForConnectorStart(CONNECTOR_NAME, 1, 8000); | ||
|
||
// Check if error record sent to error topic | ||
ConsumerRecords<byte[], byte[]> consumerRecords = getConnect().kafka() | ||
.consume(1, 8000, connectorConfig.get(DEAD_LETTER_TOPIC)); | ||
|
||
Assertions.assertEquals(1, consumerRecords.count()); | ||
|
||
ConsumerRecord<byte[], byte[]> consumerRecord = consumerRecords.iterator().next(); | ||
JsonNode record = JacksonFactory.OBJECT_MAPPER.readTree(consumerRecord.value()); | ||
|
||
Assertions.assertEquals(JacksonFactory.OBJECT_MAPPER.readTree(failedMessage).toString(), record.toString()); | ||
|
||
final Headers errorHeaders = consumerRecord.headers(); | ||
errorHeaders.headers(ERROR_CLASS_NAME) | ||
.forEach(header -> Assertions.assertEquals(EXPECTED_EXCEPTION_CLASS, new String(header.value()))); | ||
errorHeaders.headers(ERROR_HEADER_MESSAGE).forEach(header -> | ||
Assertions.assertTrue(new String(header.value()).contains(String.valueOf(HTTP_BAD_REQUEST_ERROR_CODE)))); | ||
|
||
// Verify inlet endpoint received 2 XDM record | ||
getWiremockServer().verify(postRequestedFor(urlEqualTo(getRelativeUrl())) | ||
.withRequestBody(equalToJson(payloadReceivedMultiMessageXdmData(XDM_MULTI_MESSAGE_PAYLOAD_FILE)))); | ||
} | ||
|
||
@Test | ||
|
@@ -101,7 +184,7 @@ public void kafkaErrorReporterWithHeadersTest() throws HttpException, IOExceptio | |
LOG.info("Starting connector cluster with connector : {}", CONNECTOR_NAME); | ||
getConnect().configureConnector(CONNECTOR_NAME, connectorConfig); | ||
|
||
String xdmData = xdmData(); | ||
String xdmData = xdmData(XDM_PAYLOAD_FILE); | ||
getConnect().kafka().produce(TOPIC_NAME, xdmData); | ||
waitForConnectorStart(CONNECTOR_NAME, 1, 8000); | ||
|
||
|
@@ -122,13 +205,21 @@ public void kafkaErrorReporterWithHeadersTest() throws HttpException, IOExceptio | |
errorHeaders.headers(ERROR_HEADER_MESSAGE).forEach(header -> | ||
Assertions.assertTrue(new String(header.value()).contains(String.valueOf(HTTP_SERVER_SIDE_ERROR_CODE)))); | ||
|
||
// Verify inlet endpoint received 1 XDM record | ||
// Verify inlet endpoint received 2 XDM record | ||
getWiremockServer().verify(postRequestedFor(urlEqualTo(getRelativeUrl())) | ||
.withRequestBody(equalToJson(payloadReceivedXdmData()))); | ||
.withRequestBody(equalToJson(payloadReceivedXdmData(XDM_PAYLOAD_FILE)))); | ||
} | ||
|
||
public String payloadReceivedXdmData() throws HttpException, JsonProcessingException { | ||
String xdmData = xdmData(); | ||
public String payloadReceivedMultiMessageXdmData(String payloadfile) throws HttpException, JsonProcessingException { | ||
String xdmData = xdmData(payloadfile); | ||
ObjectNode messageNode = JacksonFactory.OBJECT_MAPPER.createObjectNode(); | ||
ArrayNode xdmDataValues = (ArrayNode)JacksonFactory.OBJECT_MAPPER.readTree(xdmData); | ||
messageNode.set("messages", xdmDataValues); | ||
return JacksonFactory.OBJECT_MAPPER.writeValueAsString(messageNode); | ||
} | ||
|
||
public String payloadReceivedXdmData(String payloadfile) throws HttpException, JsonProcessingException { | ||
String xdmData = xdmData(payloadfile); | ||
ObjectNode messageNode = JacksonFactory.OBJECT_MAPPER.createObjectNode(); | ||
ArrayNode xdmDataValues = JacksonFactory.OBJECT_MAPPER.createArrayNode(); | ||
xdmDataValues.add(JacksonFactory.OBJECT_MAPPER.readTree(xdmData)); | ||
|
@@ -137,8 +228,8 @@ public String payloadReceivedXdmData() throws HttpException, JsonProcessingExcep | |
return JacksonFactory.OBJECT_MAPPER.writeValueAsString(messageNode); | ||
} | ||
|
||
public String xdmData() throws HttpException { | ||
return HttpUtil.streamToString(this.getClass().getClassLoader().getResourceAsStream(XDM_PAYLOAD_FILE)); | ||
public String xdmData(String payloadfile) throws HttpException { | ||
return HttpUtil.streamToString(this.getClass().getClassLoader().getResourceAsStream(payloadfile)); | ||
} | ||
|
||
public Map<String, String> connectorConfig(String configFile) throws HttpException, JsonProcessingException { | ||
|
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
15 changes: 15 additions & 0 deletions
15
streaming-connect-sink/src/test/resources/aep-connector-inlet-multi-message-response.json
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,15 @@ | ||
{ | ||
"inletId": "9b0cb233972f3b0092992284c7353f5eead496218e8441a79b25e9421ea127f5", | ||
"batchId": "1565638336649:1750:244", | ||
"receivedTimeMs": 1565638336705, | ||
"responses": [ | ||
{ | ||
"xactionId":"9341f8eb-494a-4c89-9879-4d06a58d2dc7-0", | ||
"status":400, | ||
"message":"The 'header' field is mandatory. Provide a valid 'header' value and try again." | ||
}, | ||
{ | ||
"xactionId": "9341f8eb-494a-4c89-9879-4d06a58d2dc7-1" | ||
} | ||
] | ||
} |
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
39 changes: 39 additions & 0 deletions
39
streaming-connect-sink/src/test/resources/xdm-data-multiple-messages.json
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,39 @@ | ||
[ | ||
{ | ||
"body": { | ||
"xdmMeta": { | ||
"schemaRef": { | ||
"id": "https://ns.adobe.com/{TENANT_ID}/schemas/{SCHEMA_ID}", | ||
"contentType": "application/vnd.adobe.xed-full+json;version={SCHEMA_VERSION}" | ||
} | ||
}, | ||
"xdmEntity": { | ||
"firstname": "abc", | ||
"lastname": "def" | ||
} | ||
} | ||
}, | ||
{ | ||
"header": { | ||
"schemaRef": { | ||
"id": "https://ns.adobe.com/{TENANT_ID}/schemas/{SCHEMA_ID}", | ||
"contentType": "application/vnd.adobe.xed-full+json;version={SCHEMA_VERSION}" | ||
}, | ||
"source": { | ||
"name": "aep-sink-connector" | ||
} | ||
}, | ||
"body": { | ||
"xdmMeta": { | ||
"schemaRef": { | ||
"id": "https://ns.adobe.com/{TENANT_ID}/schemas/{SCHEMA_ID}", | ||
"contentType": "application/vnd.adobe.xed-full+json;version={SCHEMA_VERSION}" | ||
} | ||
}, | ||
"xdmEntity": { | ||
"firstname": "abc", | ||
"lastname": "def" | ||
} | ||
} | ||
} | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add notes in the end that in case of Authentication error such as 401 and 403 connector will stop irrespective of what error tolerance value is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DOne