merge of '2246f1b81c19ddc2c058e68870f1445b9cca1598'

and '956cf5bff87f174141628efbad07e028e30fc4c9'
This commit is contained in:
kytv
2013-01-06 02:24:09 +00:00
4 changed files with 115 additions and 38 deletions

View File

@ -14,7 +14,11 @@ import java.io.OutputStream;
import java.util.Properties;
import java.util.Random;
import junit.framework.TestCase;
import org.junit.BeforeClass;
import org.junit.Test;
import static junit.framework.TestCase.*;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
/**
@ -28,15 +32,14 @@ import net.i2p.router.RouterContext;
* 10 concurrent threads is, well, slow.
*
*/
public class BandwidthLimiterTest extends TestCase{
private RouterContext _context;
public class BandwidthLimiterTest {
private static RouterContext _context;
private final static int NUM_KB = 256;
public void setUp() {
_context = new RouterContext(null);
}
public void tearDown(){
@BeforeClass
public static void setUp() {
_context = new RouterContext(new Router());
_context.initAll();
}
private void prepareLimiter(int inKBps, int outKBps, int inBurst, int outBurst) {
@ -102,6 +105,7 @@ public class BandwidthLimiterTest extends TestCase{
* with various limits) and log the times.
*
*/
@Test
public void testOutbound() {
double error;
double predict;
@ -137,6 +141,7 @@ public class BandwidthLimiterTest extends TestCase{
* with various limits) and log the times.
*
*/
@Test
public void testInbound() {
double predict;
double error;
@ -168,6 +173,7 @@ public class BandwidthLimiterTest extends TestCase{
}
@Test
public void testOutboundContention() {
double predict;
double error;

View File

@ -10,7 +10,10 @@ package net.i2p.router.tunnel;
import java.util.ArrayList;
import net.i2p.I2PAppContext;
import static junit.framework.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import net.i2p.router.RouterContext;
/**
@ -20,8 +23,8 @@ import net.i2p.router.RouterContext;
*/
public class BatchedFragmentTest extends FragmentTest {
@Before
public void setUp() {
super.setUp();
BatchedPreprocessor.DEFAULT_DELAY = 200;
}
@ -35,6 +38,7 @@ public class BatchedFragmentTest extends FragmentTest {
* after a brief delay.
*
*/
@Test
public void testBatched() {
PendingGatewayMessage pending1 = createPending(10, false, false);
ArrayList messages = new ArrayList();
@ -66,6 +70,58 @@ public class BatchedFragmentTest extends FragmentTest {
assertTrue(handleReceiver.receivedOk());
}
/**
* Send a message that fits inside a single fragment through
*
*/
@Test
public void testSingle() {
PendingGatewayMessage pending = createPending(949, false, false);
ArrayList messages = new ArrayList();
messages.add(pending);
TunnelGateway.QueuePreprocessor pre = createPreprocessor(_context);
SenderImpl sender = new SenderImpl();
DefragmentedReceiverImpl handleReceiver = new DefragmentedReceiverImpl(pending.getData());
FragmentHandler handler = new FragmentHandler(_context, handleReceiver);
ReceiverImpl receiver = new ReceiverImpl(handler, 0);
byte msg[] = pending.getData();
boolean keepGoing = true;
while (keepGoing) {
keepGoing = pre.preprocessQueue(messages, new SenderImpl(), receiver);
if (keepGoing)
try { Thread.sleep(100); } catch (InterruptedException ie) {}
}
assertTrue(handleReceiver.receivedOk());
}
/**
* Send a message with two fragments through with no delay
*
*/
@Test
public void testMultiple() throws Exception {
PendingGatewayMessage pending = createPending(2048, false, false);
ArrayList messages = new ArrayList();
messages.add(pending);
TunnelGateway.QueuePreprocessor pre = createPreprocessor(_context);
SenderImpl sender = new SenderImpl();
DefragmentedReceiverImpl handleReceiver = new DefragmentedReceiverImpl(pending.getData());
FragmentHandler handler = new FragmentHandler(_context, handleReceiver);
ReceiverImpl receiver = new ReceiverImpl(handler, 0);
byte msg[] = pending.getData();
boolean keepGoing = true;
while (keepGoing) {
keepGoing = pre.preprocessQueue(messages, new SenderImpl(), receiver);
if (keepGoing)
try { Thread.sleep(100); } catch (InterruptedException ie) {}
}
assertTrue(handleReceiver.receivedOk());
}
/**
* Send a small message, wait a second, then send a large message, pushing

View File

@ -23,8 +23,16 @@ import net.i2p.util.Log;
* Simple test to create an encrypted TunnelBuildMessage, decrypt its layers (as it would be
* during transmission), inject replies, then handle the TunnelBuildReplyMessage (unwrapping
* the reply encryption and reading the replies).
*
* ===
* Update 1/5/2013 :
* This test is renamed so it does not match the JUnit wildcard.
* There is something wrong with the decryption check; it doesn't look like the test takes
* into consideration the re-encryption of the records in the TunnelBuildMessage.
* Most probably the test will have to be re-written from scratch.
* --zab
*/
public class BuildMessageTest extends TestCase {
public class BuildMessageTestStandalone extends TestCase {
private Hash _peers[];
private PrivateKey _privKeys[];
private PublicKey _pubKeys[];
@ -35,7 +43,7 @@ public class BuildMessageTest extends TestCase {
I2PAppContext ctx = I2PAppContext.getGlobalContext();
Log log = ctx.logManager().getLog(getClass());
List order = pickOrder(ctx);
List<Integer> order = pickOrder();
TunnelCreatorConfig cfg = createConfig(ctx);
_replyRouter = new Hash();
@ -122,9 +130,9 @@ public class BuildMessageTest extends TestCase {
"\n================================================================");
}
private static final List pickOrder(I2PAppContext ctx) {
private static final List<Integer> pickOrder() {
// pseudorandom, yet consistent (so we can be repeatable)
List rv = new ArrayList(8);
List<Integer> rv = new ArrayList<Integer>(8);
rv.add(new Integer(2));
rv.add(new Integer(4));
rv.add(new Integer(6));

View File

@ -10,7 +10,12 @@ package net.i2p.router.tunnel;
import java.util.ArrayList;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static junit.framework.TestCase.*;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
import net.i2p.data.TunnelId;
@ -23,11 +28,17 @@ import net.i2p.router.RouterContext;
* FragmentHandler, and FragmentedMessage operation.
*
*/
public class FragmentTest extends TestCase{
protected RouterContext _context;
public class FragmentTest {
public void setUp() {
protected static RouterContext _context;
@BeforeClass
public static void globalSetUp() {
_context = new RouterContext(null);
}
@Before
public void set() {
_context.random().nextBoolean();
FragmentHandler.MAX_DEFRAGMENT_TIME = 10*1000;
}
@ -40,6 +51,7 @@ public class FragmentTest extends TestCase{
* Send a message that fits inside a single fragment through
*
*/
@Test
public void testSingle() {
PendingGatewayMessage pending = createPending(949, false, false);
ArrayList messages = new ArrayList();
@ -52,20 +64,18 @@ public class FragmentTest extends TestCase{
ReceiverImpl receiver = new ReceiverImpl(handler, 0);
byte msg[] = pending.getData();
boolean keepGoing = true;
while (keepGoing) {
keepGoing = pre.preprocessQueue(messages, new SenderImpl(), receiver);
if (keepGoing)
try { Thread.sleep(100); } catch (InterruptedException ie) {}
}
assertTrue(handleReceiver.receivedOk());
try {
pre.preprocessQueue(messages, new SenderImpl(), receiver);
fail("should have thrown IAE");
} catch (IllegalArgumentException expected){}
}
/**
* Send a message with two fragments through with no delay
*
*/
public void testMultiple() {
@Test
public void testMultiple() throws Exception {
PendingGatewayMessage pending = createPending(2048, false, false);
ArrayList messages = new ArrayList();
messages.add(pending);
@ -77,13 +87,10 @@ public class FragmentTest extends TestCase{
ReceiverImpl receiver = new ReceiverImpl(handler, 0);
byte msg[] = pending.getData();
boolean keepGoing = true;
while (keepGoing) {
keepGoing = pre.preprocessQueue(messages, new SenderImpl(), receiver);
if (keepGoing)
try { Thread.sleep(100); } catch (InterruptedException ie) {}
}
assertTrue(handleReceiver.receivedOk());
try {
pre.preprocessQueue(messages, new SenderImpl(), receiver);
fail("should have thrown IAE");
} catch (IllegalArgumentException expected){}
}
/**
@ -183,10 +190,10 @@ public class FragmentTest extends TestCase{
}
protected class DefragmentedReceiverImpl implements FragmentHandler.DefragmentedReceiver {
private byte _expected[];
private byte _expected2[];
private byte _expected3[];
private int _received;
private volatile byte _expected[];
private volatile byte _expected2[];
private volatile byte _expected3[];
private volatile int _received;
public DefragmentedReceiverImpl(byte expected[]) {
this(expected, null);
}