@Override protected void setUp() throws Exception { super.setUp(); channel1 = new GroupChannel(); channel1.addInterceptor(new MessageDispatch15Interceptor()); channel2 = new GroupChannel(); channel2.addInterceptor(new MessageDispatch15Interceptor()); ThroughputInterceptor tint = new ThroughputInterceptor(); tint.setInterval(500); ThroughputInterceptor tint2 = new ThroughputInterceptor(); tint2.setInterval(500); // channel1.addInterceptor(tint); channel2.addInterceptor(tint2); listener1 = new Listener(); ReceiverBase rb1 = (ReceiverBase) channel1.getChannelReceiver(); ReceiverBase rb2 = (ReceiverBase) channel2.getChannelReceiver(); rb1.setUdpPort(50000); rb2.setUdpPort(50000); channel2.addChannelListener(listener1); channel1.start(Channel.DEFAULT); channel2.start(Channel.DEFAULT); }
public void testDataSendNO_ACK() throws Exception { final AtomicInteger counter = new AtomicInteger(0); ReceiverBase rb1 = (ReceiverBase) channel1.getChannelReceiver(); ReceiverBase rb2 = (ReceiverBase) channel2.getChannelReceiver(); rb1.setUdpRxBufSize(1024 * 1024 * 10); rb2.setUdpRxBufSize(1024 * 1024 * 10); rb1.setUdpTxBufSize(1024 * 1024 * 10); rb2.setUdpTxBufSize(1024 * 1024 * 10); System.err.println("Starting NO_ACK"); Thread[] threads = new Thread[threadCount]; for (int x = 0; x < threads.length; x++) { threads[x] = new Thread() { @Override public void run() { try { long start = System.currentTimeMillis(); for (int i = 0; i < msgCount; i++) { int cnt = counter.getAndAdd(1); channel1.send( new Member[] {channel2.getLocalMember(false)}, Data.createRandomData(1024, cnt), Channel.SEND_OPTIONS_UDP); // Thread.currentThread().sleep(10); } System.out.println( "Thread[" + this.getName() + "] sent " + msgCount + " messages in " + (System.currentTimeMillis() - start) + " ms."); } catch (Exception x) { x.printStackTrace(); return; } finally { threadCounter++; } } }; } for (int x = 0; x < threads.length; x++) { threads[x].start(); } for (int x = 0; x < threads.length; x++) { threads[x].join(); } // sleep for 50 sec, let the other messages in long start = System.currentTimeMillis(); while ((System.currentTimeMillis() - start) < 25000 && msgCount * threadCount != listener1.count.get()) Thread.sleep(500); System.err.println("Finished NO_ACK [" + listener1.count + "]"); System.out.println( "Sent " + counter.get() + " messages. Received " + listener1.count + " Highest msg received:" + listener1.maxIdx); System.out.print("Missing messages:"); printMissingMsgs(listener1.nrs, counter.get()); assertEquals("Checking success messages.", msgCount * threadCount, listener1.count.get()); }