gemmellr commented on code in PR #5138:
URL: https://github.com/apache/activemq-artemis/pull/5138#discussion_r1714032187
##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpFlowControlFailDispositionTests.java:
##########
@@ -105,4 +108,51 @@ public void testAddressFullDisposition() throws Exception {
connection.close();
}
}
+
+ @TestTemplate
+ @Timeout(60)
+ public void testFailedLargeMessageSendWhenNoSpaceCleansUpLargeFile() throws
Exception {
+ AmqpClient client = createAmqpClient(getBrokerAmqpConnectionURI());
+ AmqpConnection connection = client.connect();
+
+ int expectedRemainingLargeMessageFiles = 0;
+
+ try {
+ AmqpSession session = connection.createSession();
+ AmqpSender sender = session.createSender(getQueueName(), null, null,
outcomes);
+ AmqpMessage message = createAmqpLargeMessageWithNoBody();
+ boolean rejected = false;
+
+ for (int i = 0; i < 1000; i++) {
+ try {
+ sender.send(message);
+ expectedRemainingLargeMessageFiles++;
+ } catch (IOException e) {
+ rejected = true;
+ assertTrue(e.getMessage().contains(expectedMessage),
+ String.format("Unexpected message expected %s to
contain %s", e.getMessage(), expectedMessage));
+ break;
+ }
+ }
+
+ assertTrue(rejected, "Expected messages to be refused by broker");
+ } finally {
+ connection.close();
+ }
+
+ validateNoFilesOnLargeDir(getLargeMessagesDir(),
expectedRemainingLargeMessageFiles);
+ }
+
+ private AmqpMessage createAmqpLargeMessageWithNoBody() {
+ AmqpMessage message = new AmqpMessage();
+
+ byte[] payload = new byte[32 * 1024];
Review Comment:
Would be good to tie this to the constant size so that it remains 'large' in
the case anyone ever changed that config (e.g as you just did) without also
updating this bit....test would still pass, but no longer cover what was
intended.
##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpSecurityTest.java:
##########
@@ -277,4 +286,79 @@ public void inspectOpenedResource(Sender sender) {
connection.close();
}
}
+
+ @Test
+ @Timeout(30)
+ public void
testAnonymousRelayLargeMessageSendFailsWithNotAuthorizedCleansUpLargeMessageFile()
throws Exception {
+ CountDownLatch latch = new CountDownLatch(1);
+
+ AmqpClient client = createAmqpClient(guestPass, guestUser);
+ client.setValidator(new AmqpValidator() {
+
+ @Override
+ public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
+ DeliveryState state = delivery.getRemoteState();
+
+ if (!delivery.remotelySettled()) {
+ markAsInvalid("delivery is not remotely settled");
+ }
+
+ if (state instanceof Rejected) {
+ Rejected rejected = (Rejected) state;
+ if (rejected.getError() == null ||
rejected.getError().getCondition() == null) {
+ markAsInvalid("Delivery should have been Rejected with an
error condition");
+ } else {
+ ErrorCondition error = rejected.getError();
+ if
(!error.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
+ markAsInvalid("Should have been tagged with unauthorized
access error");
+ }
+ }
+ } else {
+ markAsInvalid("Delivery should have been Rejected");
+ }
+
+ latch.countDown();
+ }
+ });
+
+ final AmqpConnection connection = client.connect();
+
+ try {
+ final AmqpSession session = connection.createSession();
+ final AmqpSender sender = session.createAnonymousSender();
+ final AmqpMessage message = createAmqpLargeMessageWithNoBody();
+
+ message.setAddress(getQueueName());
+ message.setMessageId("msg" + 1);
+
+ try {
+ sender.send(message);
+ fail("Should not be able to send, message should be rejected");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ } finally {
+ sender.close();
+ }
+
+ assertTrue(latch.await(5, TimeUnit.SECONDS));
+ connection.getStateInspector().assertValid();
+ } finally {
+ connection.close();
+ }
+
+ validateNoFilesOnLargeDir();
+ }
+
+ private AmqpMessage createAmqpLargeMessageWithNoBody() {
+ AmqpMessage message = new AmqpMessage();
+
+ byte[] payload = new byte[64 * 1024];
Review Comment:
Similarly here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact