@@ -47,6 +47,7 @@ public class AEPSinkConnectorErrorReporterTest extends AbstractConnectorTest {
47
47
private static final String AEP_KAFKA_ERROR_CONNECTOR_CONFIG = "aep-connector-error-reporter.json" ;
48
48
private static final String AEP_KAFKA_ERROR_CONNECTOR_HEADER_CONFIG = "aep-connector-error-reporter-header.json" ;
49
49
private static final String XDM_PAYLOAD_FILE = "xdm-data.json" ;
50
+ private static final String XDM_MULTI_MESSAGE_PAYLOAD_FILE = "xdm-data-multiple-messages.json" ;
50
51
private static final String DEAD_LETTER_TOPIC = "errors.deadletterqueue.topic.name" ;
51
52
private static final String ERROR_CLASS_NAME = "__connect.errors.exception.class.name" ;
52
53
private static final String ERROR_HEADER_MESSAGE = "__connect.errors.exception.message" ;
@@ -70,7 +71,7 @@ public void kafkaErrorReporterTest() throws HttpException, IOException, Interrup
70
71
LOG .info ("Starting connector cluster with connector : {}" , CONNECTOR_NAME );
71
72
getConnect ().configureConnector (CONNECTOR_NAME , connectorConfig );
72
73
73
- String xdmData = xdmData ();
74
+ String xdmData = xdmData (XDM_PAYLOAD_FILE );
74
75
getConnect ().kafka ().produce (TOPIC_NAME , xdmData );
75
76
waitForConnectorStart (CONNECTOR_NAME , 1 , 8000 );
76
77
@@ -87,7 +88,89 @@ public void kafkaErrorReporterTest() throws HttpException, IOException, Interrup
87
88
88
89
// Verify inlet endpoint received 1 XDM record
89
90
getWiremockServer ().verify (postRequestedFor (urlEqualTo (getRelativeUrl ()))
90
- .withRequestBody (equalToJson (payloadReceivedXdmData ())));
91
+ .withRequestBody (equalToJson (payloadReceivedXdmData (XDM_PAYLOAD_FILE ))));
92
+ }
93
+
94
+ @ Test
95
+ public void kafkaErrorReporterMultiMessageTest () throws HttpException , IOException , InterruptedException {
96
+ inletMultiStatusSuccessfulResponse ();
97
+ getConnect ().kafka ().createTopic (TOPIC_NAME , TOPIC_PARTITION );
98
+
99
+ // Create error topic to dump failed data
100
+ Map <String , String > connectorConfig = connectorConfig (AEP_KAFKA_ERROR_CONNECTOR_CONFIG );
101
+ getConnect ().kafka ().createTopic (connectorConfig .get (DEAD_LETTER_TOPIC ), TOPIC_PARTITION );
102
+
103
+ LOG .info ("Starting connector cluster with connector : {}" , CONNECTOR_NAME );
104
+ getConnect ().configureConnector (CONNECTOR_NAME , connectorConfig );
105
+
106
+ String xdmData = xdmData (XDM_MULTI_MESSAGE_PAYLOAD_FILE );
107
+ ArrayNode xdmDataValues = (ArrayNode )JacksonFactory .OBJECT_MAPPER .readTree (xdmData );
108
+ String failedMessage = xdmDataValues .get (0 ).toString ();
109
+ String successMessage = xdmDataValues .get (1 ).toString ();
110
+
111
+ getConnect ().kafka ().produce (TOPIC_NAME , failedMessage );
112
+ getConnect ().kafka ().produce (TOPIC_NAME , successMessage );
113
+
114
+ waitForConnectorStart (CONNECTOR_NAME , 1 , 8000 );
115
+
116
+ // Check if error record sent to error topic
117
+ ConsumerRecords <byte [], byte []> consumerRecords = getConnect ().kafka ()
118
+ .consume (1 , 8000 , connectorConfig .get (DEAD_LETTER_TOPIC ));
119
+
120
+ Assertions .assertEquals (1 , consumerRecords .count ());
121
+
122
+ ConsumerRecord <byte [], byte []> consumerRecord = consumerRecords .iterator ().next ();
123
+ JsonNode record = JacksonFactory .OBJECT_MAPPER .readTree (consumerRecord .value ());
124
+
125
+ Assertions .assertEquals (JacksonFactory .OBJECT_MAPPER .readTree (failedMessage ).toString (), record .toString ());
126
+
127
+ // Verify inlet endpoint received 2 XDM record
128
+ getWiremockServer ().verify (postRequestedFor (urlEqualTo (getRelativeUrl ()))
129
+ .withRequestBody (equalToJson (payloadReceivedMultiMessageXdmData (XDM_MULTI_MESSAGE_PAYLOAD_FILE ))));
130
+ }
131
+
132
+ @ Test
133
+ public void kafkaErrorReporterMultiMessageWithHeadersTest () throws HttpException , IOException , InterruptedException {
134
+ inletMultiStatusSuccessfulResponse ();
135
+
136
+ getConnect ().kafka ().createTopic (TOPIC_NAME , TOPIC_PARTITION );
137
+
138
+ // Create error topic to dump failed data
139
+ Map <String , String > connectorConfig = connectorConfig (AEP_KAFKA_ERROR_CONNECTOR_HEADER_CONFIG );
140
+ getConnect ().kafka ().createTopic (connectorConfig .get (DEAD_LETTER_TOPIC ), TOPIC_PARTITION );
141
+
142
+ LOG .info ("Starting connector cluster with connector : {}" , CONNECTOR_NAME );
143
+ getConnect ().configureConnector (CONNECTOR_NAME , connectorConfig );
144
+
145
+ String xdmData = xdmData (XDM_MULTI_MESSAGE_PAYLOAD_FILE );
146
+ ArrayNode xdmDataValues = (ArrayNode )JacksonFactory .OBJECT_MAPPER .readTree (xdmData );
147
+ String failedMessage = xdmDataValues .get (0 ).toString ();
148
+ String successMessage = xdmDataValues .get (1 ).toString ();
149
+ getConnect ().kafka ().produce (TOPIC_NAME , failedMessage );
150
+ getConnect ().kafka ().produce (TOPIC_NAME , successMessage );
151
+
152
+ waitForConnectorStart (CONNECTOR_NAME , 1 , 8000 );
153
+
154
+ // Check if error record sent to error topic
155
+ ConsumerRecords <byte [], byte []> consumerRecords = getConnect ().kafka ()
156
+ .consume (1 , 8000 , connectorConfig .get (DEAD_LETTER_TOPIC ));
157
+
158
+ Assertions .assertEquals (1 , consumerRecords .count ());
159
+
160
+ ConsumerRecord <byte [], byte []> consumerRecord = consumerRecords .iterator ().next ();
161
+ JsonNode record = JacksonFactory .OBJECT_MAPPER .readTree (consumerRecord .value ());
162
+
163
+ Assertions .assertEquals (JacksonFactory .OBJECT_MAPPER .readTree (failedMessage ).toString (), record .toString ());
164
+
165
+ final Headers errorHeaders = consumerRecord .headers ();
166
+ errorHeaders .headers (ERROR_CLASS_NAME )
167
+ .forEach (header -> Assertions .assertEquals (EXPECTED_EXCEPTION_CLASS , new String (header .value ())));
168
+ errorHeaders .headers (ERROR_HEADER_MESSAGE ).forEach (header ->
169
+ Assertions .assertTrue (new String (header .value ()).contains (String .valueOf (HTTP_BAD_REQUEST_ERROR_CODE ))));
170
+
171
+ // Verify inlet endpoint received 2 XDM record
172
+ getWiremockServer ().verify (postRequestedFor (urlEqualTo (getRelativeUrl ()))
173
+ .withRequestBody (equalToJson (payloadReceivedMultiMessageXdmData (XDM_MULTI_MESSAGE_PAYLOAD_FILE ))));
91
174
}
92
175
93
176
@ Test
@@ -101,7 +184,7 @@ public void kafkaErrorReporterWithHeadersTest() throws HttpException, IOExceptio
101
184
LOG .info ("Starting connector cluster with connector : {}" , CONNECTOR_NAME );
102
185
getConnect ().configureConnector (CONNECTOR_NAME , connectorConfig );
103
186
104
- String xdmData = xdmData ();
187
+ String xdmData = xdmData (XDM_PAYLOAD_FILE );
105
188
getConnect ().kafka ().produce (TOPIC_NAME , xdmData );
106
189
waitForConnectorStart (CONNECTOR_NAME , 1 , 8000 );
107
190
@@ -122,13 +205,21 @@ public void kafkaErrorReporterWithHeadersTest() throws HttpException, IOExceptio
122
205
errorHeaders .headers (ERROR_HEADER_MESSAGE ).forEach (header ->
123
206
Assertions .assertTrue (new String (header .value ()).contains (String .valueOf (HTTP_SERVER_SIDE_ERROR_CODE ))));
124
207
125
- // Verify inlet endpoint received 1 XDM record
208
+ // Verify inlet endpoint received 2 XDM record
126
209
getWiremockServer ().verify (postRequestedFor (urlEqualTo (getRelativeUrl ()))
127
- .withRequestBody (equalToJson (payloadReceivedXdmData ())));
210
+ .withRequestBody (equalToJson (payloadReceivedXdmData (XDM_PAYLOAD_FILE ))));
128
211
}
129
212
130
- public String payloadReceivedXdmData () throws HttpException , JsonProcessingException {
131
- String xdmData = xdmData ();
213
+ public String payloadReceivedMultiMessageXdmData (String payloadfile ) throws HttpException , JsonProcessingException {
214
+ String xdmData = xdmData (payloadfile );
215
+ ObjectNode messageNode = JacksonFactory .OBJECT_MAPPER .createObjectNode ();
216
+ ArrayNode xdmDataValues = (ArrayNode )JacksonFactory .OBJECT_MAPPER .readTree (xdmData );
217
+ messageNode .set ("messages" , xdmDataValues );
218
+ return JacksonFactory .OBJECT_MAPPER .writeValueAsString (messageNode );
219
+ }
220
+
221
+ public String payloadReceivedXdmData (String payloadfile ) throws HttpException , JsonProcessingException {
222
+ String xdmData = xdmData (payloadfile );
132
223
ObjectNode messageNode = JacksonFactory .OBJECT_MAPPER .createObjectNode ();
133
224
ArrayNode xdmDataValues = JacksonFactory .OBJECT_MAPPER .createArrayNode ();
134
225
xdmDataValues .add (JacksonFactory .OBJECT_MAPPER .readTree (xdmData ));
@@ -137,8 +228,8 @@ public String payloadReceivedXdmData() throws HttpException, JsonProcessingExcep
137
228
return JacksonFactory .OBJECT_MAPPER .writeValueAsString (messageNode );
138
229
}
139
230
140
- public String xdmData () throws HttpException {
141
- return HttpUtil .streamToString (this .getClass ().getClassLoader ().getResourceAsStream (XDM_PAYLOAD_FILE ));
231
+ public String xdmData (String payloadfile ) throws HttpException {
232
+ return HttpUtil .streamToString (this .getClass ().getClassLoader ().getResourceAsStream (payloadfile ));
142
233
}
143
234
144
235
public Map <String , String > connectorConfig (String configFile ) throws HttpException , JsonProcessingException {
0 commit comments