import java.net.InetAddress;
import junit.framework.TestCase;
import dijjer.io.comm.Peer;
import dijjer.io.comm.UdpSocketManager;
import dijjer.io.xfer.BlockReceiver;
import dijjer.io.xfer.BlockTransmitter;
import dijjer.io.xfer.PartiallyReceivedBlock;
/*
* Dijjer - A Peer to Peer HTTP Cache
* Copyright (C) 2004,2005 Change.Tv, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @author ian
*
* To change the template for this generated type comment go to Window - Preferences - Java - Code Generation - Code and
* Comments
*/
public class BlockTransferTest extends TestCase {
public void testTransfer() throws Exception {
UdpSocketManager usm1 = new UdpSocketManager(8000);
UdpSocketManager usm2 = new UdpSocketManager(8001);
UdpSocketManager usm3 = new UdpSocketManager(8002);
usm1.setDropProbability(8);
usm2.setDropProbability(8);
usm3.setDropProbability(8);
Peer p1 = new Peer(InetAddress.getLocalHost(), 8000);
Peer p2 = new Peer(InetAddress.getLocalHost(), 8001);
Peer p3 = new Peer(InetAddress.getLocalHost(), 8002);
byte[] block = new byte[1024 * 256];
for (int x = 0; x < block.length; x++) {
block[x] = (byte) x;
}
PartiallyReceivedBlock prb1 = new PartiallyReceivedBlock(256, 1024, block);
final BlockTransmitter bt = new BlockTransmitter(usm1, p2, 0, prb1);
(new Thread() {
public void run() {
try {
bt.send();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}).start();
PartiallyReceivedBlock prb2 = new PartiallyReceivedBlock(256, 1024);
final BlockReceiver br = new BlockReceiver(usm2, p1, 0, prb2);
final BlockTransmitter bt2 = new BlockTransmitter(usm2, p3, 0, prb2);
PartiallyReceivedBlock prb3 = new PartiallyReceivedBlock(256, 1024);
final BlockReceiver br2 = new BlockReceiver(usm3, p2, 0, prb3);
(new Thread() {
public void run() {
try {
br.receive();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}).start();
(new Thread() {
public void run() {
try {
bt2.send();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}).start();
br2.receive();
}
}