@Test public void shouldReturnLogPositionToRecoverFromIfNeeded() { // given LogPosition checkPointLogPosition = new LogPosition( 1L, 4242 ); when( tailScanner.getTailInformation() ) .thenReturn( new LogTailInformation( new CheckPoint( checkPointLogPosition ), true, 10L, logVersion, currentLogVersion, LogEntryVersion.CURRENT ) ); // when RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider( tailScanner, monitor ).get(); // then verify( monitor ).commitsAfterLastCheckPoint( checkPointLogPosition, 10L ); assertEquals( checkPointLogPosition, recoveryStartInformation.getRecoveryPosition() ); assertEquals( 10L, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint() ); assertTrue( recoveryStartInformation.isRecoveryRequired() ); }
@Test public void shouldRecoverFromStartOfLogZeroIfThereAreNoCheckPointAndOldestLogIsVersionZero() { // given when( tailScanner.getTailInformation() ).thenReturn( new LogTailInformation( true, 10L, INITIAL_LOG_VERSION, currentLogVersion, LogEntryVersion.CURRENT ) ); // when RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider( tailScanner, monitor ).get(); // then verify( monitor ).noCheckPointFound(); assertEquals( LogPosition.start( INITIAL_LOG_VERSION ), recoveryStartInformation.getRecoveryPosition() ); assertEquals( 10L, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint() ); assertTrue( recoveryStartInformation.isRecoveryRequired() ); }
@Test public void shouldReturnUnspecifiedIfThereIsNoNeedForRecovery() { // given when( tailScanner.getTailInformation() ).thenReturn( new LogTailScanner.LogTailInformation( false, NO_TRANSACTION_ID, logVersion, currentLogVersion, LogEntryVersion.CURRENT ) ); // when RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider( tailScanner, monitor ).get(); // then verify( monitor ).noCommitsAfterLastCheckPoint( null ); assertEquals( LogPosition.UNSPECIFIED, recoveryStartInformation.getRecoveryPosition() ); assertEquals( NO_TRANSACTION_ID, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint() ); assertFalse( recoveryStartInformation.isRecoveryRequired() ); }
if ( !logTailInformation.commitsAfterLastCheckpoint() ) monitor.noCommitsAfterLastCheckPoint( lastCheckPoint != null ? lastCheckPoint.getLogPosition() : null ); return createRecoveryInformation( LogPosition.UNSPECIFIED, txIdAfterLastCheckPoint ); monitor.commitsAfterLastCheckPoint( lastCheckPoint.getLogPosition(), txIdAfterLastCheckPoint ); return createRecoveryInformation( lastCheckPoint.getLogPosition(), txIdAfterLastCheckPoint ); logTailInformation.currentLogVersion ); monitor.noCheckPointFound(); return createRecoveryInformation( LogPosition.start( 0 ), txIdAfterLastCheckPoint );
if ( !logTailInformation.commitsAfterLastCheckpoint() ) monitor.noCommitsAfterLastCheckPoint( lastCheckPoint != null ? lastCheckPoint.getLogPosition() : null ); return createRecoveryInformation( LogPosition.UNSPECIFIED, txIdAfterLastCheckPoint ); monitor.commitsAfterLastCheckPoint( lastCheckPoint.getLogPosition(), txIdAfterLastCheckPoint ); return createRecoveryInformation( lastCheckPoint.getLogPosition(), txIdAfterLastCheckPoint ); logTailInformation.currentLogVersion ); monitor.noCheckPointFound(); return createRecoveryInformation( LogPosition.start( 0 ), txIdAfterLastCheckPoint );