@ -50,9 +50,6 @@ import org.junit.Test;
public class FastSyncDownloaderTest {
public class FastSyncDownloaderTest {
private static final CompletableFuture < FastSyncState > COMPLETE =
completedFuture ( FastSyncState . EMPTY_SYNC_STATE ) ;
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
private final FastSyncActions fastSyncActions = mock ( FastSyncActions . class ) ;
private final FastSyncActions fastSyncActions = mock ( FastSyncActions . class ) ;
@ -88,7 +85,6 @@ public class FastSyncDownloaderTest {
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
@ -102,7 +98,6 @@ public class FastSyncDownloaderTest {
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
@ -119,7 +114,6 @@ public class FastSyncDownloaderTest {
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState fastSyncState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState fastSyncState = new FastSyncState ( pivotBlockHeader ) ;
final CompletableFuture < FastSyncState > complete = completedFuture ( fastSyncState ) ;
final CompletableFuture < FastSyncState > complete = completedFuture ( fastSyncState ) ;
when ( fastSyncActions . waitForSuitablePeers ( fastSyncState ) ) . thenReturn ( complete ) ;
when ( fastSyncActions . selectPivotBlock ( fastSyncState ) ) . thenReturn ( complete ) ;
when ( fastSyncActions . selectPivotBlock ( fastSyncState ) ) . thenReturn ( complete ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( fastSyncState ) ) . thenReturn ( complete ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( fastSyncState ) ) . thenReturn ( complete ) ;
when ( fastSyncActions . createChainDownloader ( fastSyncState ) ) . thenReturn ( chainDownloader ) ;
when ( fastSyncActions . createChainDownloader ( fastSyncState ) ) . thenReturn ( chainDownloader ) ;
@ -140,7 +134,6 @@ public class FastSyncDownloaderTest {
final CompletableFuture < FastSyncState > result = resumedDownloader . start ( ) ;
final CompletableFuture < FastSyncState > result = resumedDownloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( fastSyncState ) ;
verify ( fastSyncActions ) . selectPivotBlock ( fastSyncState ) ;
verify ( fastSyncActions ) . selectPivotBlock ( fastSyncState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( fastSyncState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( fastSyncState ) ;
verify ( storage ) . storeState ( fastSyncState ) ;
verify ( storage ) . storeState ( fastSyncState ) ;
@ -152,23 +145,8 @@ public class FastSyncDownloaderTest {
assertThat ( result ) . isCompletedWithValue ( fastSyncState ) ;
assertThat ( result ) . isCompletedWithValue ( fastSyncState ) ;
}
}
@Test
public void shouldAbortIfWaitForSuitablePeersFails ( ) {
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn (
CompletableFuture . failedFuture ( new FastSyncException ( FastSyncError . UNEXPECTED_ERROR ) ) ) ;
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
assertCompletedExceptionally ( result , FastSyncError . UNEXPECTED_ERROR ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verifyNoMoreInteractions ( fastSyncActions ) ;
}
@Test
@Test
public void shouldAbortIfSelectPivotBlockFails ( ) {
public void shouldAbortIfSelectPivotBlockFails ( ) {
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenThrow ( new FastSyncException ( FastSyncError . UNEXPECTED_ERROR ) ) ;
. thenThrow ( new FastSyncException ( FastSyncError . UNEXPECTED_ERROR ) ) ;
@ -176,7 +154,6 @@ public class FastSyncDownloaderTest {
assertCompletedExceptionally ( result , FastSyncError . UNEXPECTED_ERROR ) ;
assertCompletedExceptionally ( result , FastSyncError . UNEXPECTED_ERROR ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verifyNoMoreInteractions ( fastSyncActions ) ;
verifyNoMoreInteractions ( fastSyncActions ) ;
}
}
@ -188,7 +165,7 @@ public class FastSyncDownloaderTest {
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
@ -202,7 +179,6 @@ public class FastSyncDownloaderTest {
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
@ -227,7 +203,7 @@ public class FastSyncDownloaderTest {
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
@ -241,7 +217,6 @@ public class FastSyncDownloaderTest {
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . createChainDownloader ( downloadPivotBlockHeaderState ) ;
verify ( fastSyncActions ) . createChainDownloader ( downloadPivotBlockHeaderState ) ;
@ -262,7 +237,7 @@ public class FastSyncDownloaderTest {
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
doAnswer (
doAnswer (
@ -284,7 +259,6 @@ public class FastSyncDownloaderTest {
Throwable thrown = catchThrowable ( ( ) - > result . get ( ) ) ;
Throwable thrown = catchThrowable ( ( ) - > result . get ( ) ) ;
assertThat ( thrown ) . hasCauseExactlyInstanceOf ( CancellationException . class ) ;
assertThat ( thrown ) . hasCauseExactlyInstanceOf ( CancellationException . class ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
@ -299,7 +273,7 @@ public class FastSyncDownloaderTest {
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
@ -313,7 +287,6 @@ public class FastSyncDownloaderTest {
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . createChainDownloader ( downloadPivotBlockHeaderState ) ;
verify ( fastSyncActions ) . createChainDownloader ( downloadPivotBlockHeaderState ) ;
@ -335,7 +308,7 @@ public class FastSyncDownloaderTest {
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
@ -349,7 +322,6 @@ public class FastSyncDownloaderTest {
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . createChainDownloader ( downloadPivotBlockHeaderState ) ;
verify ( fastSyncActions ) . createChainDownloader ( downloadPivotBlockHeaderState ) ;
@ -379,8 +351,8 @@ public class FastSyncDownloaderTest {
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState secondDownloadPivotBlockHeaderState =
final FastSyncState secondDownloadPivotBlockHeaderState =
new FastSyncState ( secondPivotBlockHeader ) ;
new FastSyncState ( secondPivotBlockHeader ) ;
// First attempt
// First attempt
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn (
. thenReturn (
completedFuture ( selectPivotBlockState ) , completedFuture ( secondSelectPivotBlockState ) ) ;
completedFuture ( selectPivotBlockState ) , completedFuture ( secondSelectPivotBlockState ) ) ;
@ -406,7 +378,6 @@ public class FastSyncDownloaderTest {
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
@ -423,7 +394,6 @@ public class FastSyncDownloaderTest {
// A real chain downloader would cause the chainFuture to complete when cancel is called.
// A real chain downloader would cause the chainFuture to complete when cancel is called.
chainFuture . completeExceptionally ( new CancellationException ( ) ) ;
chainFuture . completeExceptionally ( new CancellationException ( ) ) ;
verify ( fastSyncActions , times ( 2 ) ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions , times ( 2 ) ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions , times ( 2 ) ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( secondSelectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( secondSelectPivotBlockState ) ;
verify ( storage ) . storeState ( secondDownloadPivotBlockHeaderState ) ;
verify ( storage ) . storeState ( secondDownloadPivotBlockHeaderState ) ;
@ -452,8 +422,8 @@ public class FastSyncDownloaderTest {
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState secondDownloadPivotBlockHeaderState =
final FastSyncState secondDownloadPivotBlockHeaderState =
new FastSyncState ( secondPivotBlockHeader ) ;
new FastSyncState ( secondPivotBlockHeader ) ;
// First attempt
// First attempt
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn (
. thenReturn (
completedFuture ( selectPivotBlockState ) , completedFuture ( secondSelectPivotBlockState ) ) ;
completedFuture ( selectPivotBlockState ) , completedFuture ( secondSelectPivotBlockState ) ) ;
@ -481,7 +451,6 @@ public class FastSyncDownloaderTest {
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
final CompletableFuture < FastSyncState > result = downloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( selectPivotBlockState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
verify ( storage ) . storeState ( downloadPivotBlockHeaderState ) ;
@ -500,7 +469,6 @@ public class FastSyncDownloaderTest {
chainFuture . completeExceptionally ( new CancellationException ( ) ) ;
chainFuture . completeExceptionally ( new CancellationException ( ) ) ;
verify ( fastSyncActions ) . scheduleFutureTask ( any ( ) , any ( ) ) ;
verify ( fastSyncActions ) . scheduleFutureTask ( any ( ) , any ( ) ) ;
verify ( fastSyncActions , times ( 2 ) ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions , times ( 2 ) ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions , times ( 2 ) ) . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( secondSelectPivotBlockState ) ;
verify ( fastSyncActions ) . downloadPivotBlockHeader ( secondSelectPivotBlockState ) ;
verify ( storage ) . storeState ( secondDownloadPivotBlockHeaderState ) ;
verify ( storage ) . storeState ( secondDownloadPivotBlockHeaderState ) ;
@ -516,12 +484,7 @@ public class FastSyncDownloaderTest {
@Test
@Test
public void shouldNotHaveTrailingPeerRequirementsBeforePivotBlockSelected ( ) {
public void shouldNotHaveTrailingPeerRequirementsBeforePivotBlockSelected ( ) {
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( new CompletableFuture < > ( ) ) ;
downloader . start ( ) ;
downloader . start ( ) ;
verify ( fastSyncActions ) . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ;
Assertions . assertThat ( downloader . calculateTrailingPeerRequirements ( ) ) . isEmpty ( ) ;
Assertions . assertThat ( downloader . calculateTrailingPeerRequirements ( ) ) . isEmpty ( ) ;
}
}
@ -530,7 +493,7 @@ public class FastSyncDownloaderTest {
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
@ -552,7 +515,7 @@ public class FastSyncDownloaderTest {
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final FastSyncState selectPivotBlockState = new FastSyncState ( 50 ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture ( ) . number ( 50 ) . buildHeader ( ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState ( pivotBlockHeader ) ;
when ( fastSyncActions . waitForSuitablePeers ( FastSyncState . EMPTY_SYNC_STATE ) ) . thenReturn ( COMPLETE ) ;
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
when ( fastSyncActions . selectPivotBlock ( FastSyncState . EMPTY_SYNC_STATE ) )
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
. thenReturn ( completedFuture ( selectPivotBlockState ) ) ;
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )
when ( fastSyncActions . downloadPivotBlockHeader ( selectPivotBlockState ) )