Skip to content

Instantly share code, notes, and snippets.

@sandro-k
Created February 24, 2014 12:37
Show Gist options
  • Save sandro-k/9187634 to your computer and use it in GitHub Desktop.
Save sandro-k/9187634 to your computer and use it in GitHub Desktop.
public class TomP2PMessageTest {
@Test
public void testMessaging() throws IOException, InterruptedException {
Peer peer = new PeerMaker( Number160.ONE ).setPorts( 4000 ).makeAndListen();
int numberOfItems = 10000;
final CountDownLatch latch = new CountDownLatch( numberOfItems );
peer.setObjectDataReply( new ObjectDataReply() {
@Override
public Object reply( PeerAddress sender, Object request ) throws Exception {
latch.countDown();
return "OK";
}
} );
final int minimumResults = 1;
final int maxFailure = 0;
final int parallelDiff = 0;
SenderCacheStrategy senderCacheStrategy = new SenderCacheStrategy( 250, 10000 );
final RequestP2PConfiguration requestP2PConfiguration =
new RequestP2PConfiguration( minimumResults, maxFailure, parallelDiff, false, false,
senderCacheStrategy );
final Deque<FutureDHT> futures = newLinkedList();
for ( int i = 0; i < numberOfItems; i++ ) {
FutureDHT test = peer.send( Number160.ONE )
.setRequestP2PConfiguration( requestP2PConfiguration )
.setRefreshSeconds( 0 )
.setDirectReplication( false )
.setObject( "test" )
.start();
futures.add( test );
}
for ( FutureDHT futureDHT : futures ) {
futureDHT.awaitUninterruptibly();
}
Assert.assertEquals( "The latch should count down to zero if all messages were received", 0, latch.getCount() );
peer.shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment