DLUtils { public static long computeStartSequenceId(List<LogSegmentMetadata> logSegmentDescList, LogSegmentMetadata segment) throws UnexpectedException { long startSequenceId = 0L; for (LogSegmentMetadata metadata : logSegmentDescList) { if (metadata.getLogSegmentSequenceNumber() >= segment.getLogSegmentSequenceNumber()) { continue; } else if (metadata.getLogSegmentSequenceNumber() < (segment.getLogSegmentSequenceNumber() - 1)) { break; } if (metadata.isInProgress()) { throw new UnexpectedException("Should not complete log segment " + segment.getLogSegmentSequenceNumber() + " since it's previous log segment is still inprogress : " + logSegmentDescList); } if (metadata.supportsSequenceId()) { startSequenceId = metadata.getStartSequenceId() + metadata.getRecordCount(); } } return startSequenceId; }  static String getZKServersFromDLUri(URI uri); static int findLogSegmentNotLessThanTxnId(List<LogSegmentMetadata> segments,
                                                     long transactionId); static Long nextLogSegmentSequenceNumber(List<LogSegmentMetadata> segmentListDesc); static long computeStartSequenceId(List<LogSegmentMetadata> logSegmentDescList,
                                              LogSegmentMetadata segment); static long deserializeLogSegmentSequenceNumber(byte[] data); static byte[] serializeLogSegmentSequenceNumber(long logSegmentSeqNo); static long deserializeTransactionId(byte[] data); static byte[] serializeTransactionId(long transactionId); static byte[] ledgerId2Bytes(long ledgerId); static long bytes2LedgerId(byte[] data);  }
@Test(timeout = 60000, expected = UnexpectedException.class) public void testUnexpectedExceptionOnComputeStartSequenceId() throws Exception { List<LogSegmentMetadata> segments = Lists.newArrayList( inprogressLogSegment(3L, 201L), inprogressLogSegment(2L, 101L), completedLogSegment(1L, 1L, 100L).mutator().setStartSequenceId(1L).build() ); DLUtils.computeStartSequenceId(segments, segments.get(0)); }
@Test(timeout = 60000) public void testComputeStartSequenceIdOnEmptyList() throws Exception { List<LogSegmentMetadata> emptyList = Lists.newArrayList(); assertEquals(0L, DLUtils.computeStartSequenceId(emptyList, inprogressLogSegment(1L, 1L))); }
@Test(timeout = 60000) public void testComputeStartSequenceIdOnLowerSequenceNumberSegment() throws Exception { List<LogSegmentMetadata> segments = Lists.newArrayList( completedLogSegment(3L, 201L, 300L).mutator().setStartSequenceId(201L).build(), completedLogSegment(2L, 101L, 200L).mutator().setStartSequenceId(101L).build() ); assertEquals(0L, DLUtils.computeStartSequenceId(segments, inprogressLogSegment(1L, 1L))); }
@Test(timeout = 60000) public void testComputeStartSequenceIdOnHigherSequenceNumberSegment() throws Exception { List<LogSegmentMetadata> segments = Lists.newArrayList( completedLogSegment(3L, 201L, 300L).mutator().setStartSequenceId(201L).build(), completedLogSegment(2L, 101L, 200L).mutator().setStartSequenceId(101L).build() ); assertEquals(0L, DLUtils.computeStartSequenceId(segments, inprogressLogSegment(5L, 401L))); }
@Test(timeout = 60000) public void testComputeStartSequenceId() throws Exception { List<LogSegmentMetadata> segments = Lists.newArrayList( completedLogSegment(3L, 201L, 300L).mutator() .setStartSequenceId(201L).setRecordCount(100).build(), completedLogSegment(2L, 101L, 200L).mutator() .setStartSequenceId(101L).setRecordCount(100).build() ); assertEquals(301L, DLUtils.computeStartSequenceId(segments, inprogressLogSegment(4L, 301L))); }