@Test void taskShouldThrowWhenRunOnAnUnknownQueue() { MailQueueFactory<ManageableMailQueue> mailQueueFactory = mock(MailQueueFactory.class); when(mailQueueFactory.getQueue(any(MailQueueName.class))).thenReturn(Optional.empty()); JsonTaskSerializer testee = JsonTaskSerializer.of(ClearMailQueueTaskDTO.module(mailQueueFactory)); String serializedJson = "{\"type\": \"clear-mail-queue\", \"queue\": \"anyQueue\"}"; assertThatThrownBy(() -> testee.deserialize(serializedJson).run()) .isInstanceOf(ClearMailQueueTask.UnknownSerializedQueue.class); }
@Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); queue.clear(); this.lastAdditionalInformation = details(); } catch (MailQueue.MailQueueException | IOException e) { LOGGER.error("Clear MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } return Result.COMPLETED; }
ClearMailQueueTask implements Task { @Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); queue.clear(); this.lastAdditionalInformation = details(); } catch (MailQueue.MailQueueException | IOException e) { LOGGER.error("Clear MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } return Result.COMPLETED; } }
ClearMailQueueTask implements Task { @Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); queue.clear(); this.lastAdditionalInformation = details(); } catch (MailQueue.MailQueueException | IOException e) { LOGGER.error("Clear MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } return Result.COMPLETED; } ClearMailQueueTask(MailQueueName queueName, ClearMailQueueTask.MailQueueFactory factory); }
ClearMailQueueTask implements Task { @Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); queue.clear(); this.lastAdditionalInformation = details(); } catch (MailQueue.MailQueueException | IOException e) { LOGGER.error("Clear MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } return Result.COMPLETED; } ClearMailQueueTask(MailQueueName queueName, ClearMailQueueTask.MailQueueFactory factory); @Override Result run(); @Override TaskType type(); @Override Optional<TaskExecutionDetails.AdditionalInformation> details(); }
ClearMailQueueTask implements Task { @Override public Result run() { try (ManageableMailQueue queue = factory.create(queueName)) { this.initialCount = Optional.of(getRemainingSize(queue)); this.queue = Optional.of(queue); queue.clear(); this.lastAdditionalInformation = details(); } catch (MailQueue.MailQueueException | IOException e) { LOGGER.error("Clear MailQueue got an exception", e); return Result.PARTIAL; } finally { this.queue = Optional.empty(); } return Result.COMPLETED; } ClearMailQueueTask(MailQueueName queueName, ClearMailQueueTask.MailQueueFactory factory); @Override Result run(); @Override TaskType type(); @Override Optional<TaskExecutionDetails.AdditionalInformation> details(); static final TaskType TYPE; }