@Test public void queueFetchTaskWhenConcurrencyLimitReached() { final int taskCount = maxConcurrentRequests + 1; for (int i = 0; i < taskCount; i++) { final Bytes32 root = dataStructureUtil.randomBytes32(); recentBlockFetcher.requestRecentBlock(root); } assertTaskCounts(taskCount, taskCount - 1, 1); final SafeFuture<FetchBlockResult> future = taskFutures.get(0); final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(1); future.complete(FetchBlockResult.createSuccessful(block)); assertTaskCounts(taskCount - 1, taskCount - 1, 0); }
public void requestRecentBlock(final Bytes32 blockRoot) { if (pendingBlocksPool.contains(blockRoot)) { return; } final FetchBlockTask task = fetchBlockTaskFactory.create(eth2Network, blockRoot); if (allTasks.putIfAbsent(blockRoot, task) != null) { task.cancel(); return; } LOG.trace("Queue block to be fetched: {}", blockRoot); queueTask(task); }
FetchRecentBlocksService extends Service { public void requestRecentBlock(final Bytes32 blockRoot) { if (pendingBlocksPool.contains(blockRoot)) { return; } final FetchBlockTask task = fetchBlockTaskFactory.create(eth2Network, blockRoot); if (allTasks.putIfAbsent(blockRoot, task) != null) { task.cancel(); return; } LOG.trace("Queue block to be fetched: {}", blockRoot); queueTask(task); } }
FetchRecentBlocksService extends Service { public void requestRecentBlock(final Bytes32 blockRoot) { if (pendingBlocksPool.contains(blockRoot)) { return; } final FetchBlockTask task = fetchBlockTaskFactory.create(eth2Network, blockRoot); if (allTasks.putIfAbsent(blockRoot, task) != null) { task.cancel(); return; } LOG.trace("Queue block to be fetched: {}", blockRoot); queueTask(task); } FetchRecentBlocksService(
      final AsyncRunner asyncRunner,
      final P2PNetwork<Eth2Peer> eth2Network,
      final PendingPool<SignedBeaconBlock> pendingBlocksPool,
      final FetchBlockTaskFactory fetchBlockTaskFactory,
      final int maxConcurrentRequests); }
FetchRecentBlocksService extends Service { public void requestRecentBlock(final Bytes32 blockRoot) { if (pendingBlocksPool.contains(blockRoot)) { return; } final FetchBlockTask task = fetchBlockTaskFactory.create(eth2Network, blockRoot); if (allTasks.putIfAbsent(blockRoot, task) != null) { task.cancel(); return; } LOG.trace("Queue block to be fetched: {}", blockRoot); queueTask(task); } FetchRecentBlocksService(
      final AsyncRunner asyncRunner,
      final P2PNetwork<Eth2Peer> eth2Network,
      final PendingPool<SignedBeaconBlock> pendingBlocksPool,
      final FetchBlockTaskFactory fetchBlockTaskFactory,
      final int maxConcurrentRequests); static FetchRecentBlocksService create(
      final AsyncRunner asyncRunner,
      final P2PNetwork<Eth2Peer> eth2Network,
      final PendingPool<SignedBeaconBlock> pendingBlocksPool); long subscribeBlockFetched(final BlockSubscriber subscriber); void unsubscribeBlockFetched(final int subscriberId); void requestRecentBlock(final Bytes32 blockRoot); void cancelRecentBlockRequest(final Bytes32 blockRoot); }
FetchRecentBlocksService extends Service { public void requestRecentBlock(final Bytes32 blockRoot) { if (pendingBlocksPool.contains(blockRoot)) { return; } final FetchBlockTask task = fetchBlockTaskFactory.create(eth2Network, blockRoot); if (allTasks.putIfAbsent(blockRoot, task) != null) { task.cancel(); return; } LOG.trace("Queue block to be fetched: {}", blockRoot); queueTask(task); } FetchRecentBlocksService(
      final AsyncRunner asyncRunner,
      final P2PNetwork<Eth2Peer> eth2Network,
      final PendingPool<SignedBeaconBlock> pendingBlocksPool,
      final FetchBlockTaskFactory fetchBlockTaskFactory,
      final int maxConcurrentRequests); static FetchRecentBlocksService create(
      final AsyncRunner asyncRunner,
      final P2PNetwork<Eth2Peer> eth2Network,
      final PendingPool<SignedBeaconBlock> pendingBlocksPool); long subscribeBlockFetched(final BlockSubscriber subscriber); void unsubscribeBlockFetched(final int subscriberId); void requestRecentBlock(final Bytes32 blockRoot); void cancelRecentBlockRequest(final Bytes32 blockRoot);  }