// @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 peerShouldReadHave() 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(); testMessageType(testedPeer, MessageType.HAVE, new HaveMessage(42)); assertFalse(testedPeer.isSeeder()); assertTrue(testedPeer.hasPiece(42)); }