// @Test(expected = IllegalStateException.class) public void peerShouldReadBitField() throws InterruptedException, THPRequestException, HashException, CannotUnserializeException, CannotReadTokenException, CannotReadBencodedException, CannotReadMessageException { lock = new CountDownLatch(2); initGuice(); initEventBus(); initTorrentStream(); initClient(); client.loadMetaInfo(torrentStream); client.refreshPeerList(); System.out.println("Refreshing peer list"); lock.await(30, TimeUnit.SECONDS); assertNotNull(peers); assertFalse(peers.isEmpty()); Peer testedPeer = peers.iterator().next(); byte[] payload = new byte[metaInfo.getInformation().getPieceCount()]; Arrays.fill(payload, (byte) 0xFF); testMessageType(testedPeer, MessageType.BITFIELD, new BitFieldMessage(payload)); assertTrue(testedPeer.isSeeder()); Arrays.fill(payload, (byte) 0); testMessageType(testedPeer, MessageType.BITFIELD, new BitFieldMessage(payload)); }
// @Test public void peerShouldHaveConsistentPieceCount() throws InterruptedException, THPRequestException, HashException, CannotUnserializeException, CannotReadTokenException, CannotReadBencodedException { lock = new CountDownLatch(2); initGuice(); initEventBus(); initTorrentStream(); initClient(); client.loadMetaInfo(torrentStream); client.refreshPeerList(); System.out.println("Refreshing peer list"); lock.await(30, TimeUnit.SECONDS); assertNotNull(peers); assertFalse(peers.isEmpty()); Peer testedPeer = peers.iterator().next(); expectedMessageReceived = false; expectedMessageType = MessageType.HANDSHAKE; lock = new CountDownLatch(2); testedPeer.connect(); lock.await(30, TimeUnit.SECONDS); assertTrue(testedPeer.getPeerId() != null); assertEquals(metaInfo.getInformation().getPieceCount(), testedPeer.getExpectedPieceCount()); }