|
56 | 56 | import javax.xml.namespace.QName;
|
57 | 57 | import org.apache.commons.io.ByteOrderMark;
|
58 | 58 | import org.apache.commons.lang3.tuple.Pair;
|
| 59 | +import org.jetbrains.annotations.NotNull; |
59 | 60 | import org.junit.jupiter.api.BeforeEach;
|
60 | 61 | import org.junit.jupiter.api.Test;
|
61 | 62 | import org.junit.jupiter.api.io.TempDir;
|
@@ -155,15 +156,7 @@ public void testMdibVersionOverflow(@TempDir final File dir) throws IOException,
|
155 | 156 | 1, false, true, mock(MessageFactory.class), new HibernateConfigImpl(dir), this.testRunObserver)) {
|
156 | 157 | final ListMultimap<String, String> multimap = ArrayListMultimap.create();
|
157 | 158 |
|
158 |
| - final String transactionId = "transactionId"; |
159 |
| - final String requestUri = "requestUri"; |
160 |
| - |
161 |
| - final X509Certificate certificate = CertificateUtil.getDummyCert(); |
162 |
| - final CommunicationContext headerContext = new CommunicationContext( |
163 |
| - new HttpApplicationInfo(multimap, transactionId, requestUri), |
164 |
| - new TransportInfo( |
165 |
| - Constants.HTTPS_SCHEME, null, null, null, null, Collections.singletonList(certificate)), |
166 |
| - null); |
| 159 | + final CommunicationContext headerContext = getCommunicationContext(multimap); |
167 | 160 |
|
168 | 161 | try (final Message message = new Message(
|
169 | 162 | CommunicationLog.Direction.INBOUND,
|
@@ -196,15 +189,7 @@ public void testMdibVersionCloseToOverflow(@TempDir final File dir) throws IOExc
|
196 | 189 | 1, false, true, mock(MessageFactory.class), new HibernateConfigImpl(dir), this.testRunObserver)) {
|
197 | 190 | final ListMultimap<String, String> multimap = ArrayListMultimap.create();
|
198 | 191 |
|
199 |
| - final String transactionId = "transactionId"; |
200 |
| - final String requestUri = "requestUri"; |
201 |
| - |
202 |
| - final X509Certificate certificate = CertificateUtil.getDummyCert(); |
203 |
| - final CommunicationContext headerContext = new CommunicationContext( |
204 |
| - new HttpApplicationInfo(multimap, transactionId, requestUri), |
205 |
| - new TransportInfo( |
206 |
| - Constants.HTTPS_SCHEME, null, null, null, null, Collections.singletonList(certificate)), |
207 |
| - null); |
| 192 | + final CommunicationContext headerContext = getCommunicationContext(multimap); |
208 | 193 |
|
209 | 194 | try (final Message message = new Message(
|
210 | 195 | CommunicationLog.Direction.INBOUND,
|
@@ -248,15 +233,7 @@ public void testGetUniqueSequenceIds(@TempDir final File dir) throws IOException
|
248 | 233 | 1, false, true, mock(MessageFactory.class), new HibernateConfigImpl(dir), this.testRunObserver)) {
|
249 | 234 | final ListMultimap<String, String> multimap = ArrayListMultimap.create();
|
250 | 235 |
|
251 |
| - final String transactionId = "transactionId"; |
252 |
| - final String requestUri = "requestUri"; |
253 |
| - |
254 |
| - final X509Certificate certificate = CertificateUtil.getDummyCert(); |
255 |
| - final CommunicationContext headerContext = new CommunicationContext( |
256 |
| - new HttpApplicationInfo(multimap, transactionId, requestUri), |
257 |
| - new TransportInfo( |
258 |
| - Constants.HTTPS_SCHEME, null, null, null, null, Collections.singletonList(certificate)), |
259 |
| - null); |
| 236 | + final CommunicationContext headerContext = getCommunicationContext(multimap); |
260 | 237 |
|
261 | 238 | try (final Message message = new Message(
|
262 | 239 | CommunicationLog.Direction.INBOUND,
|
@@ -302,6 +279,78 @@ public void testGetUniqueSequenceIds(@TempDir final File dir) throws IOException
|
302 | 279 | }
|
303 | 280 | }
|
304 | 281 |
|
| 282 | + /** |
| 283 | + * Tests whether SequenceId values are ordered by the timestamp of the first message they appear in. |
| 284 | + * |
| 285 | + * @param dir message storage directory |
| 286 | + * @throws IOException on io exceptions |
| 287 | + * @throws CertificateException on certificate exceptions |
| 288 | + */ |
| 289 | + @Test |
| 290 | + public void testGetUniqueSequenceIdsOrdering(@TempDir final File dir) throws IOException, CertificateException { |
| 291 | + try (final MessageStorage messageStorage = new MessageStorage( |
| 292 | + 1, false, true, mock(MessageFactory.class), new HibernateConfigImpl(dir), this.testRunObserver)) { |
| 293 | + final ListMultimap<String, String> multimap = ArrayListMultimap.create(); |
| 294 | + |
| 295 | + final CommunicationContext headerContext = getCommunicationContext(multimap); |
| 296 | + |
| 297 | + try (final Message message = new Message( |
| 298 | + CommunicationLog.Direction.INBOUND, |
| 299 | + CommunicationLog.MessageType.REQUEST, |
| 300 | + headerContext, |
| 301 | + messageStorage)) { |
| 302 | + message.write(String.format( |
| 303 | + BASE_MESSAGE_STRING, "action", String.format(SEQUENCE_ID_METRIC_BODY_STRING, "3", "3")) |
| 304 | + .getBytes(StandardCharsets.UTF_8)); |
| 305 | + } |
| 306 | + messageStorage.flush(); |
| 307 | + |
| 308 | + try (final Message message = new Message( |
| 309 | + CommunicationLog.Direction.INBOUND, |
| 310 | + CommunicationLog.MessageType.REQUEST, |
| 311 | + headerContext, |
| 312 | + messageStorage)) { |
| 313 | + message.write(String.format( |
| 314 | + BASE_MESSAGE_STRING, "action", String.format(SEQUENCE_ID_METRIC_BODY_STRING, "3", "2")) |
| 315 | + .getBytes(StandardCharsets.UTF_8)); |
| 316 | + } |
| 317 | + messageStorage.flush(); |
| 318 | + |
| 319 | + try (final Message message = new Message( |
| 320 | + CommunicationLog.Direction.INBOUND, |
| 321 | + CommunicationLog.MessageType.REQUEST, |
| 322 | + headerContext, |
| 323 | + messageStorage)) { |
| 324 | + message.write(String.format( |
| 325 | + BASE_MESSAGE_STRING, "action", String.format(SEQUENCE_ID_METRIC_BODY_STRING, "3", "1")) |
| 326 | + .getBytes(StandardCharsets.UTF_8)); |
| 327 | + } |
| 328 | + messageStorage.flush(); |
| 329 | + |
| 330 | + try (final Stream<String> sequenceIdStream = messageStorage.getUniqueSequenceIds()) { |
| 331 | + assertEquals(List.of("urn:uuid:3", "urn:uuid:2", "urn:uuid:1"), sequenceIdStream.toList()); |
| 332 | + } |
| 333 | + |
| 334 | + try (final MessageStorage.GetterResult<MessageContent> inboundMessages = |
| 335 | + messageStorage.getInboundMessages()) { |
| 336 | + assertEquals(3, inboundMessages.getStream().count()); |
| 337 | + } |
| 338 | + } |
| 339 | + } |
| 340 | + |
| 341 | + private static @NotNull CommunicationContext getCommunicationContext(final ListMultimap<String, String> multimap) |
| 342 | + throws CertificateException, IOException { |
| 343 | + final String transactionId = "transactionId"; |
| 344 | + final String requestUri = "requestUri"; |
| 345 | + |
| 346 | + final X509Certificate certificate = CertificateUtil.getDummyCert(); |
| 347 | + return new CommunicationContext( |
| 348 | + new HttpApplicationInfo(multimap, transactionId, requestUri), |
| 349 | + new TransportInfo( |
| 350 | + Constants.HTTPS_SCHEME, null, null, null, null, Collections.singletonList(certificate)), |
| 351 | + null); |
| 352 | + } |
| 353 | + |
305 | 354 | /**
|
306 | 355 | * Tests whether headers and the transaction id are stored properly.
|
307 | 356 | *
|
|
0 commit comments