Skip to content

Commit

Permalink
ARTEMIS-4171/ARTEMIS-4233 Large Message Send
Browse files Browse the repository at this point in the history
In case a Throwable happened, we should also deal with the file in the file system.
  • Loading branch information
clebertsuconic committed Apr 7, 2023
1 parent d23ced5 commit de772ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1131,13 +1131,15 @@ private void sendContinuations(final int packetSize,
try {
session.send(session.getCurrentTransaction(), EmbedMessageUtil.extractEmbedded((ICoreMessage) message.toMessage(), storageManager), false, producers.get(senderID), false);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
message.deleteFile();
throw e;
} catch (Throwable e) {
logger.warn("********************************************************************************");
logger.warn("Throwable on currentLargeMessage {}", message.getMessageID(), e);
logger.warn("********************************************************************************");

logger.warn(e.getMessage(), e);
message.deleteFile();
ActiveMQException e2 = new ActiveMQException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ public void testDeleteOnNoBinding() throws Exception {

@Test
public void testFileRemovalOnFailure() throws Exception {
internalFileRemoveOnFailure(false);
}

@Test
public void testFileRemovalOnFailureThrowable() throws Exception {
internalFileRemoveOnFailure(true);
}

private void internalFileRemoveOnFailure(boolean useError) throws Exception {
final AtomicBoolean throwException = new AtomicBoolean(false);
final String queueName = RandomUtil.randomString();
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
Expand All @@ -344,7 +353,11 @@ public void testFileRemovalOnFailure() throws Exception {
@Override
public void beforeMessageRoute(Message message, RoutingContext context, boolean direct, boolean rejectDuplicates) throws ActiveMQException {
if (throwException.get()) {
throw new ActiveMQException();
if (useError) {
throw new OutOfMemoryError();
} else {
throw new ActiveMQException();
}
}
}
});
Expand Down

0 comments on commit de772ac

Please sign in to comment.