### Question:
RedundancyCalculator { @VisibleForTesting Layout restoreRedundancyForSegment(TransferSegment transferSegment, Layout layout) { List<LayoutSegment> segments = layout.getSegments().stream().map(layoutSegment -> { if (layoutSegment.getEnd() == transferSegment.getEndAddress() + 1L) { List<LayoutStripe> newStripes = layoutSegment.getStripes() .stream() .map(stripe -> { if (layoutSegment.getFirstStripe().equals(stripe)) { ImmutableList<String> servers = new ImmutableList .Builder<String>() .addAll(stripe.getLogServers()) .add(server) .build(); return new LayoutStripe(servers); } return stripe; }) .collect(Collectors.toList()); return new LayoutSegment( layoutSegment.getReplicationMode(), layoutSegment.getStart(), layoutSegment.getEnd(), newStripes); } else { return new LayoutSegment( layoutSegment.getReplicationMode(), layoutSegment.getStart(), layoutSegment.getEnd(), layoutSegment.getStripes()); } }).collect(Collectors.toList()); Layout newLayout = new Layout(layout); LayoutBuilder builder = new LayoutBuilder(newLayout); return builder.setSegments(segments).build(); }  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 testRestoreRedundancyForSegment() { TransferSegment segment = createTransferSegment(0L, 20L, RESTORED); 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)); List<LayoutSegment> layoutSegments = Arrays.asList(segment1, segment2); Layout testLayout = createTestLayout(layoutSegments); RedundancyCalculator calculator = new RedundancyCalculator("localhost"); Layout layout = calculator.restoreRedundancyForSegment(segment, testLayout); assertThat(layout.getFirstSegment().getFirstStripe().getLogServers()) .contains("localhost"); }