@Test
public void singleDownloadPeer2() throws Exception {

    // Check that we don't attempt multiple simultaneous block chain downloads, when adding a new peer in the
    // middle of an existing chain download.
    // Create a couple of peers.
    peerGroup.startAndWait();
    // Create a couple of peers.
    InboundMessageQueuer p1 = connectPeer(1);
    // Set up a little block chain.
    Block b1 = TestUtils.createFakeBlock(blockStore).block;
    Block b2 = TestUtils.makeSolvedTestBlock(b1);
    Block b3 = TestUtils.makeSolvedTestBlock(b2);
    // Expect a zero hash getblocks on p1. This is how the process starts.
    peerGroup.startBlockChainDownload(new AbstractPeerEventListener() {
    });
    GetBlocksMessage getblocks = (GetBlocksMessage) outbound(p1);
    assertEquals(Sha256Hash.ZERO_HASH, getblocks.getStopHash());
    // We give back an inv with some blocks in it.
    InventoryMessage inv = new InventoryMessage(params);
    inv.addBlock(b1);
    inv.addBlock(b2);
    inv.addBlock(b3);
    
    inbound(p1, inv);
    assertTrue(outbound(p1) instanceof GetDataMessage);
    // We hand back the first block.
    inbound(p1, b1);
    // Now we successfully connect to another peer. There should be no messages sent.
    InboundMessageQueuer p2 = connectPeer(2);
    Message message = (Message)outbound(p2);
    assertNull(message == null ? "" : message.toString(), message);
    peerGroup.stop();
}