GenericAstrixSetReducer implements RemoteResultReducer<Set<T>> { @Override public Set<T> reduce(List<AstrixRemoteResult<Set<T>>> results) { Set<T> set = new HashSet<>(); for (AstrixRemoteResult<Set<T>> result : results) { set.addAll(result.getResult()); } return set; }  @Override Set<T> reduce(List<AstrixRemoteResult<Set<T>>> results);  }
@Test public void reducedSetContainsUniqueElements() { Set<String> first = Collections.singleton("1"); Set<String> second = Collections.singleton("1"); Set<String> third = Collections.singleton("2"); Set<String> reduced = reducer.reduce(Arrays.<AstrixRemoteResult<Set<String>>>asList( AstrixRemoteResult.successful(first), AstrixRemoteResult.successful(second), AstrixRemoteResult.successful(third))); assertThat(reduced.size(), is(2)); assertTrue(reduced.containsAll(first)); assertTrue(reduced.containsAll(third)); }
@Test(expected = MyRuntimeException.class) public void exceptionIsRethrown() throws Exception { reducer.reduce(Arrays.asList( AstrixRemoteResult.successful(Collections.singleton("hello world")), AstrixRemoteResult.<Set<String>>failure(new MyRuntimeException(), CorrelationId.undefined()))); }