@Override public Result run() { try { queue.clear(); } catch (MailQueue.MailQueueException e) { LOGGER.error("Clear MailQueue got an exception", e); return Result.PARTIAL; } return Result.COMPLETED; }
@Override public long flush() throws Exception { try { return queue.flush(); } catch (MailQueueException e) { throw new Exception(e.getMessage()); } }
@Override public List<CompositeData> browse() throws Exception { MailQueueIterator it = queue.browse(); List<CompositeData> data = new ArrayList<>(); String[] names = new String[]{"name", "sender", "state", "recipients", "size", "lastUpdated", "remoteAddress", "remoteHost", "errorMessage", "attributes", "nextDelivery"};
@Override public long removeWithRecipient(String address) throws Exception { try { return queue.remove(Type.Recipient, address); } catch (MailQueueException e) { throw new Exception(e.getMessage()); } }
public long getRemainingSize() { try { return queue.getSize(); } catch (MailQueue.MailQueueException e) { throw new RuntimeException(e); } } }
public ClearMailQueueTask(ManageableMailQueue queue) { this.queue = queue; additionalInformation = new AdditionalInformation(queue.getName(), this::getRemainingSize); }
private List<MailQueueItemDTO> listMails(ManageableMailQueue queue, Optional<Boolean> isDelayed, Limit limit) { try { return limit.applyOnStream(Iterators.toStream(queue.browse())) .map(Throwing.function(MailQueueItemDTO::from).sneakyThrow()) .filter(item -> filter(item, isDelayed)) .collect(Guavate.toImmutableList()); } catch (MailQueueException e) { throw ErrorResponder.builder() .statusCode(HttpStatus.BAD_REQUEST_400) .type(ErrorType.INVALID_ARGUMENT) .message("Invalid request for listing the mails from the mail queue " + queue) .cause(e) .haltError(); } }
@Override public long removeWithSender(String address) throws Exception { try { return queue.remove(Type.Sender, address); } catch (MailQueueException e) { throw new Exception(e.getMessage()); } }
private long getRemainingSize() { try { return queue.getSize(); } catch (MailQueue.MailQueueException e) { throw new RuntimeException(e); } } }
public DeleteMailsFromMailQueueTask(ManageableMailQueue queue, Optional<MailAddress> maybeSender, Optional<String> maybeName, Optional<MailAddress> maybeRecipient) { Preconditions.checkArgument( Booleans.countTrue(maybeSender.isPresent(), maybeName.isPresent(), maybeRecipient.isPresent()) == 1, "You should provide one and only one of the query parameters 'sender', 'name' or 'recipient'."); this.queue = queue; this.maybeSender = maybeSender; this.maybeName = maybeName; this.maybeRecipient = maybeRecipient; additionalInformation = new AdditionalInformation(queue.getName(), this::getRemainingSize, maybeSender, maybeName, maybeRecipient); }
@Test public void reprocessingShouldNotFailOnConcurrentDeletion() throws Exception { MailRepository repository = mailRepositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(PATH, MEMORY_PROTOCOL)); repository.store(mail1); repository.store(mail2); repository.store(mail3); AtomicBoolean shouldPerformRemove = new AtomicBoolean(true); ConsumerChainer<MailKey> concurrentRemoveConsumer = Throwing.consumer(key -> { if (shouldPerformRemove.get()) { shouldPerformRemove.set(false); MailKey toRemove = ImmutableList.of(NAME_1, NAME_2, NAME_3) .stream() .map(MailKey::new) .filter(candidateForRemoval -> !candidateForRemoval.equals(key)) .findFirst() .get(); repository.remove(toRemove); } }); reprocessingService.reprocessAll(PATH, NO_TARGET_PROCESSOR, SPOOL, concurrentRemoveConsumer); assertThat(queueFactory.getQueue(SPOOL).get() .browse()) .hasSize(2); }
@Override public long removeWithName(String name) throws Exception { try { return queue.remove(Type.Name, name); } catch (MailQueueException e) { throw new Exception(e.getMessage()); } }
@Override public long getSize() throws Exception { try { return queue.getSize(); } catch (MailQueueException e) { throw new Exception(e.getMessage()); } }
private Response forceDelayedMailsDelivery(Request request, Response response) throws JsonExtractException, MailQueueException { assertDelayedParamIsTrue(request); assertPayloadContainsDelayedEntry(request); ManageableMailQueue mailQueue = assertMailQueueExists(request); mailQueue.flush(); response.status(HttpStatus.NO_CONTENT_204); return response; }
@Override public long clear() throws Exception { try { return queue.clear(); } catch (MailQueueException e) { throw new Exception(e.getMessage()); } }
@Test public void reprocessingOneShouldEnqueueMail() throws Exception { MailRepository repository = mailRepositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(PATH, MEMORY_PROTOCOL)); repository.store(mail1); repository.store(mail2); repository.store(mail3); reprocessingService.reprocess(PATH, KEY_2, NO_TARGET_PROCESSOR, SPOOL); assertThat(queueFactory.getQueue(SPOOL).get() .browse()) .extracting(item -> item.getMail().getName()) .containsOnly(NAME_2); }
@Override public Result run() { maybeSender.ifPresent(Throwing.consumer( (MailAddress sender) -> queue.remove(ManageableMailQueue.Type.Sender, sender.asString()))); maybeName.ifPresent(Throwing.consumer( (String name) -> queue.remove(ManageableMailQueue.Type.Name, name))); maybeRecipient.ifPresent(Throwing.consumer( (MailAddress recipient) -> queue.remove(ManageableMailQueue.Type.Recipient, recipient.asString()))); return Result.COMPLETED; }
@Test public void reprocessingShouldEnqueueAllMails() throws Exception { MailRepository repository = mailRepositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(PATH, MEMORY_PROTOCOL)); repository.store(mail1); repository.store(mail2); repository.store(mail3); reprocessingService.reprocessAll(PATH, NO_TARGET_PROCESSOR, SPOOL, NOOP_CONSUMER); assertThat(queueFactory.getQueue(SPOOL).get() .browse()) .extracting(item -> item.getMail().getName()) .containsOnly(NAME_1, NAME_2, NAME_3); }
@Test public void remoteDeliveryShouldNotForwardMailsWithNoRecipients() throws Exception { remoteDelivery.init(FakeMailetConfig.builder() .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") .build()); Mail mail = FakeMail.builder().name(MAIL_NAME).build(); remoteDelivery.service(mail); assertThat(mailQueue.browse()).isEmpty(); }