### Question:
PeerGroup extends AbstractExecutionThreadService implements TransactionBroadcaster { public void addPeerDiscovery(PeerDiscovery peerDiscovery) { lock.lock(); try { if (getMaxConnections() == 0) setMaxConnections(DEFAULT_CONNECTIONS); peerDiscoverers.add(peerDiscovery); } finally { lock.unlock(); } } PeerGroup(NetworkParameters params);  PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain);  PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager); void setMaxConnections(int maxConnections); int getMaxConnections(); void setVersionMessage(VersionMessage ver); VersionMessage getVersionMessage(); void setUserAgent(String name, String version, @Nullable String comments); void setUserAgent(String name, String version); void addEventListener(PeerEventListener listener, Executor executor); void addEventListener(PeerEventListener listener); boolean removeEventListener(PeerEventListener listener); void clearEventListeners(); List<Peer> getConnectedPeers(); List<Peer> getPendingPeers(); void addAddress(PeerAddress peerAddress); void addAddress(InetAddress address); void addPeerDiscovery(PeerDiscovery peerDiscovery); void addWallet(Wallet wallet); void addPeerFilterProvider(PeerFilterProvider provider); void removeWallet(Wallet wallet); void recalculateFastCatchupAndFilter(FilterRecalculateMode mode); void setBloomFilterFalsePositiveRate(double bloomFilterFPRate); int numConnectedPeers(); @Nullable Peer connectTo(InetSocketAddress address); void setConnectTimeoutMillis(int connectTimeoutMillis); void startBlockChainDownload(PeerEventListener listener); void downloadBlockChain(); MemoryPool getMemoryPool(); void setFastCatchupTimeSecs(long secondsSinceEpoch); long getFastCatchupTimeSecs(); ListenableFuture<PeerGroup> waitForPeers(final int numPeers); int getMinBroadcastConnections(); void setMinBroadcastConnections(int value); ListenableFuture<Transaction> broadcastTransaction(final Transaction tx); ListenableFuture<Transaction> broadcastTransaction(final Transaction tx, final int minConnections); long getPingIntervalMsec(); void setPingIntervalMsec(long pingIntervalMsec); void setMinRequiredProtocolVersion(int minRequiredProtocolVersion); int getMinRequiredProtocolVersion(); int getMostCommonChainHeight(); static int getMostCommonChainHeight(final List<Peer> peers); Peer getDownloadPeer(); static final long DEFAULT_PING_INTERVAL_MSEC; static final double DEFAULT_BLOOM_FILTER_FP_RATE; static final double MAX_FP_RATE_INCREASE; static final int DEFAULT_CONNECT_TIMEOUT_MILLIS; }### Answer:
@Test public void peerDiscoveryPolling() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicBoolean result = new AtomicBoolean(); peerGroup.addPeerDiscovery(new PeerDiscovery() { public InetSocketAddress[] getPeers(long unused, TimeUnit unused2) throws PeerDiscoveryException { if (!result.getAndSet(true)) { throw new PeerDiscoveryException("test failure"); } else { latch.countDown(); return new InetSocketAddress[]{new InetSocketAddress("localhost", 1)}; } } public void shutdown() { } }); peerGroup.startAsync(); peerGroup.awaitRunning(); latch.await(); assertTrue(result.get()); }