@Test void batchMessagesShouldWorkWithNonZeroBatchedSize() throws Exception { MessageBatcher messageBatcher = new MessageBatcher(5); assertThat(messageBatcher.batchMessages(MessageRange.range(MessageUid.of(1), MessageUid.of(10)), incrementBatcher)) .containsOnly(MessageRange.range(MessageUid.of(2), MessageUid.of(6)), MessageRange.range(MessageUid.of(7), MessageUid.of(11))); }
public List<MessageRange> batchMessages(MessageRange set, BatchedOperation batchedOperation) throws MailboxException { if (batchSize > 0) { return set.split(batchSize) .stream() .flatMap(Throwing.function(range -> batchedOperation.execute(range) .stream())) .collect(Guavate.toImmutableList()); } else { return batchedOperation.execute(set); } }
MessageBatcher { public List<MessageRange> batchMessages(MessageRange set, BatchedOperation batchedOperation) throws MailboxException { if (batchSize > 0) { return set.split(batchSize) .stream() .flatMap(Throwing.function(range -> batchedOperation.execute(range) .stream())) .collect(Guavate.toImmutableList()); } else { return batchedOperation.execute(set); } } }
MessageBatcher { public List<MessageRange> batchMessages(MessageRange set, BatchedOperation batchedOperation) throws MailboxException { if (batchSize > 0) { return set.split(batchSize) .stream() .flatMap(Throwing.function(range -> batchedOperation.execute(range) .stream())) .collect(Guavate.toImmutableList()); } else { return batchedOperation.execute(set); } } MessageBatcher(int batchSize); }
MessageBatcher { public List<MessageRange> batchMessages(MessageRange set, BatchedOperation batchedOperation) throws MailboxException { if (batchSize > 0) { return set.split(batchSize) .stream() .flatMap(Throwing.function(range -> batchedOperation.execute(range) .stream())) .collect(Guavate.toImmutableList()); } else { return batchedOperation.execute(set); } } MessageBatcher(int batchSize); int getBatchSize(); List<MessageRange> batchMessages(MessageRange set, BatchedOperation batchedOperation); }
MessageBatcher { public List<MessageRange> batchMessages(MessageRange set, BatchedOperation batchedOperation) throws MailboxException { if (batchSize > 0) { return set.split(batchSize) .stream() .flatMap(Throwing.function(range -> batchedOperation.execute(range) .stream())) .collect(Guavate.toImmutableList()); } else { return batchedOperation.execute(set); } } MessageBatcher(int batchSize); int getBatchSize(); List<MessageRange> batchMessages(MessageRange set, BatchedOperation batchedOperation); static final int NO_BATCH_SIZE; }