@Test public void delegateExceptionIsPropogated() throws Exception { List<Function<Integer, Integer>> delegates = Arrays.asList(i -> { throw new RuntimeException(Integer.toString(i)); }); try (MessagePartitioner<Integer, Integer> partitioner = new MessagePartitioner<>(() -> i -> 1, delegates)) { try { partitioner.apply(1); fail("Should throw exception before reaching this point"); } catch (RuntimeException e) { assertThat(e.getMessage(), is("1")); } } }
@Override public RESPONSE apply(MESSAGE message) { int partitionNumber = Math.abs(hasherSupplier.get().apply(message)) % delegates.size(); return delegates.get(partitionNumber).apply(message); }
MessagePartitioner implements CloseableFunction<MESSAGE, RESPONSE> { @Override public RESPONSE apply(MESSAGE message) { int partitionNumber = Math.abs(hasherSupplier.get().apply(message)) % delegates.size(); return delegates.get(partitionNumber).apply(message); } }
MessagePartitioner implements CloseableFunction<MESSAGE, RESPONSE> { @Override public RESPONSE apply(MESSAGE message) { int partitionNumber = Math.abs(hasherSupplier.get().apply(message)) % delegates.size(); return delegates.get(partitionNumber).apply(message); } MessagePartitioner(
      @NonNull Supplier<Function<MESSAGE, Integer>> hasherSupplier,
      @NonNull List<Function<MESSAGE, RESPONSE>> delegates); }
MessagePartitioner implements CloseableFunction<MESSAGE, RESPONSE> { @Override public RESPONSE apply(MESSAGE message) { int partitionNumber = Math.abs(hasherSupplier.get().apply(message)) % delegates.size(); return delegates.get(partitionNumber).apply(message); } MessagePartitioner(
      @NonNull Supplier<Function<MESSAGE, Integer>> hasherSupplier,
      @NonNull List<Function<MESSAGE, RESPONSE>> delegates); @Override RESPONSE apply(MESSAGE message); @Override void close(); }
MessagePartitioner implements CloseableFunction<MESSAGE, RESPONSE> { @Override public RESPONSE apply(MESSAGE message) { int partitionNumber = Math.abs(hasherSupplier.get().apply(message)) % delegates.size(); return delegates.get(partitionNumber).apply(message); } MessagePartitioner(
      @NonNull Supplier<Function<MESSAGE, Integer>> hasherSupplier,
      @NonNull List<Function<MESSAGE, RESPONSE>> delegates); @Override RESPONSE apply(MESSAGE message); @Override void close();  }