GenericAstrixMapReducer implements RemoteResultReducer<Map<K, V>> { @Override public Map<K, V> reduce(List<AstrixRemoteResult<Map<K, V>>> results) { Map<K, V> map = new HashMap<K, V>(); for (AstrixRemoteResult<Map<K, V>> result : results) { map.putAll(result.getResult()); } return map; }  @Override Map<K, V> reduce(List<AstrixRemoteResult<Map<K, V>>> results);  }
@Test public void reduce_flattensMaps() throws Exception { GenericAstrixMapReducer<String, Integer> reducer = new GenericAstrixMapReducer<String, Integer>(); assertEquals(newMap("a", 1).build(), reducer.reduce(Arrays.asList(AstrixRemoteResult.successful(newMap("a", 1).build())))); assertEquals(newMap("a", 1).with("b", 2).build(), reducer.reduce(Arrays.asList( AstrixRemoteResult.successful(newMap("a", 1).build()), AstrixRemoteResult.successful(newMap("b", 2).build())))); assertEquals(newMap("a", 1).with("b", 2).with("c", 3).build(), reducer.reduce(Arrays.asList( AstrixRemoteResult.successful(newMap("a", 1).with("c", 3).build()), AstrixRemoteResult.successful(newMap("b", 2).build())))); }
@Test(expected = MyRuntimeException.class) public void reduce_rethrowsException() throws Exception { GenericAstrixMapReducer<String, Integer> reducer = new GenericAstrixMapReducer<>(); reducer.reduce(Arrays.asList( AstrixRemoteResult.successful(newMap("a", 1).build()), AstrixRemoteResult.<Map<String, Integer>>failure(new MyRuntimeException(), CorrelationId.undefined()))); }