### Question:
RedundancyCalculator { public Layout updateLayoutAfterRedundancyRestoration( List<TransferSegment> segments, Layout initLayout) { return segments .stream() .reduce(initLayout, (layout, segment) -> restoreRedundancyForSegment(segment, layout), (oldLayout, newLayout) -> newLayout); }  Layout updateLayoutAfterRedundancyRestoration(
            List<TransferSegment> segments, Layout initLayout); static boolean canRestoreRedundancy(Layout layout, String server); static boolean canMergeSegments(Layout layout); static boolean canRestoreRedundancyOrMergeSegments(Layout layout, String server); ImmutableList<TransferSegment> createStateList(Layout layout, long trimMark); ImmutableList<TransferSegment> getTrimmedNotRestoredSegments(Layout layout, long trimMark); ImmutableList<TransferSegmentRange> prepareTransferWorkload(
            ImmutableList<TransferSegment> transferSegmentList,
            Optional<Long> committedTail);  }### Answer:
@Test public void testUpdateLayoutAfterRedundancyRestoration() { LayoutStripe stripe1 = new LayoutStripe(Collections.singletonList("A")); LayoutStripe stripe2 = new LayoutStripe(Collections.singletonList("C")); LayoutStripe stripe3 = new LayoutStripe(Collections.singletonList("D")); LayoutSegment segment1 = new LayoutSegment(CHAIN_REPLICATION, 0L, 21L, Arrays.asList(stripe1, stripe2, stripe3)); LayoutStripe stripe11 = new LayoutStripe(Arrays.asList("C", "D")); LayoutStripe stripe22 = new LayoutStripe(Collections.singletonList("C")); LayoutStripe stripe33 = new LayoutStripe(Collections.singletonList("D")); LayoutSegment segment2 = new LayoutSegment(CHAIN_REPLICATION, 21L, 51L, Arrays.asList(stripe11, stripe22, stripe33)); LayoutStripe stripe111 = new LayoutStripe(Arrays.asList("E", "F")); LayoutStripe stripe222 = new LayoutStripe(Collections.singletonList("G")); LayoutStripe stripe333 = new LayoutStripe(Collections.singletonList("H")); LayoutSegment segment3 = new LayoutSegment(CHAIN_REPLICATION, 51L, 61L, Arrays.asList(stripe111, stripe222, stripe333)); List<LayoutSegment> layoutSegments = Arrays.asList(segment1, segment2, segment3); Layout testLayout = createTestLayout(layoutSegments); List<TransferSegment> transferSegments = Arrays.asList (createTransferSegment(0L, 20L, RESTORED), createTransferSegment(21L, 50L, RESTORED), createTransferSegment(51L, 60L, RESTORED)); RedundancyCalculator calculator = new RedundancyCalculator("localhost"); Layout consolidatedLayout = calculator.updateLayoutAfterRedundancyRestoration(transferSegments, testLayout); assertThat(consolidatedLayout.getSegments().stream()) .allMatch(segment -> segment.getFirstStripe().getLogServers().contains("localhost")); }