@Test void shouldDelaySwitchingToNewChainUntilCurrentImportCompletes() { assertThat(sync.syncToChain(targetChain)).isNotDone(); final Batch batch0 = batches.get(0); final Batch batch1 = batches.get(1); batches.receiveBlocks(batch0, chainBuilder.generateBlockAtSlot(1).getBlock()); batches.receiveBlocks( batch1, chainBuilder.generateBlockAtSlot(batch1.getFirstSlot()).getBlock()); assertBatchImported(batch0); final Batch batch4 = batches.get(4); targetChain = chainWith(dataStructureUtil.randomSlotAndBlockRoot(), syncSource); assertThat(sync.syncToChain(targetChain)).isNotDone(); batches.receiveBlocks( batch4, chainBuilder.generateBlockAtSlot(batch4.getLastSlot()).getBlock()); final Batch batch5 = batches.get(5); batches.receiveBlocks(batch5, dataStructureUtil.randomSignedBeaconBlock(batch5.getFirstSlot())); assertBatchNotActive(batch0); batches.forEach(this::assertBatchNotActive); batches.clearBatchList(); final SignedBlockAndState finalizedBlock = storageSystem.chainUpdater().finalizeEpoch(1); batches.getImportResult(batch0).complete(IMPORT_FAILED); assertThat(batches.get(0).getFirstSlot()).isEqualTo(finalizedBlock.getSlot()); }
@Override public SafeFuture<SyncResult> syncToChain(final TargetChain targetChain) { final SafeFuture<SyncResult> result = new SafeFuture<>(); eventThread.execute(() -> switchSyncTarget(targetChain, result)); return result; }
BatchSync implements Sync { @Override public SafeFuture<SyncResult> syncToChain(final TargetChain targetChain) { final SafeFuture<SyncResult> result = new SafeFuture<>(); eventThread.execute(() -> switchSyncTarget(targetChain, result)); return result; } }
BatchSync implements Sync { @Override public SafeFuture<SyncResult> syncToChain(final TargetChain targetChain) { final SafeFuture<SyncResult> result = new SafeFuture<>(); eventThread.execute(() -> switchSyncTarget(targetChain, result)); return result; } private  BatchSync(
      final EventThread eventThread,
      final RecentChainData recentChainData,
      final BatchChain activeBatches,
      final BatchImporter batchImporter,
      final BatchDataRequester batchDataRequester); }
BatchSync implements Sync { @Override public SafeFuture<SyncResult> syncToChain(final TargetChain targetChain) { final SafeFuture<SyncResult> result = new SafeFuture<>(); eventThread.execute(() -> switchSyncTarget(targetChain, result)); return result; } private  BatchSync(
      final EventThread eventThread,
      final RecentChainData recentChainData,
      final BatchChain activeBatches,
      final BatchImporter batchImporter,
      final BatchDataRequester batchDataRequester); static BatchSync create(
      final EventThread eventThread,
      final RecentChainData recentChainData,
      final BatchImporter batchImporter,
      final BatchFactory batchFactory,
      final UInt64 batchSize); @Override SafeFuture<SyncResult> syncToChain(final TargetChain targetChain); }
BatchSync implements Sync { @Override public SafeFuture<SyncResult> syncToChain(final TargetChain targetChain) { final SafeFuture<SyncResult> result = new SafeFuture<>(); eventThread.execute(() -> switchSyncTarget(targetChain, result)); return result; } private  BatchSync(
      final EventThread eventThread,
      final RecentChainData recentChainData,
      final BatchChain activeBatches,
      final BatchImporter batchImporter,
      final BatchDataRequester batchDataRequester); static BatchSync create(
      final EventThread eventThread,
      final RecentChainData recentChainData,
      final BatchImporter batchImporter,
      final BatchFactory batchFactory,
      final UInt64 batchSize); @Override SafeFuture<SyncResult> syncToChain(final TargetChain targetChain);  }