forked from I2P_Developers/i2p.i2p
Update FragmentTest to expect an IAE.
Update {Batched}FragmentTest to JUnit 4 Use a single instance of I2PAppContext
This commit is contained in:
@ -10,7 +10,10 @@ package net.i2p.router.tunnel;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
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;
|
import net.i2p.router.RouterContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,8 +23,8 @@ import net.i2p.router.RouterContext;
|
|||||||
*/
|
*/
|
||||||
public class BatchedFragmentTest extends FragmentTest {
|
public class BatchedFragmentTest extends FragmentTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
super.setUp();
|
|
||||||
BatchedPreprocessor.DEFAULT_DELAY = 200;
|
BatchedPreprocessor.DEFAULT_DELAY = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +38,7 @@ public class BatchedFragmentTest extends FragmentTest {
|
|||||||
* after a brief delay.
|
* after a brief delay.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testBatched() {
|
public void testBatched() {
|
||||||
PendingGatewayMessage pending1 = createPending(10, false, false);
|
PendingGatewayMessage pending1 = createPending(10, false, false);
|
||||||
ArrayList messages = new ArrayList();
|
ArrayList messages = new ArrayList();
|
||||||
@ -66,6 +70,58 @@ public class BatchedFragmentTest extends FragmentTest {
|
|||||||
assertTrue(handleReceiver.receivedOk());
|
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
|
* Send a small message, wait a second, then send a large message, pushing
|
||||||
|
@ -10,7 +10,12 @@ package net.i2p.router.tunnel;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
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.DataHelper;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.data.TunnelId;
|
import net.i2p.data.TunnelId;
|
||||||
@ -23,11 +28,17 @@ import net.i2p.router.RouterContext;
|
|||||||
* FragmentHandler, and FragmentedMessage operation.
|
* FragmentHandler, and FragmentedMessage operation.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FragmentTest extends TestCase{
|
public class FragmentTest {
|
||||||
protected RouterContext _context;
|
|
||||||
|
|
||||||
public void setUp() {
|
protected static RouterContext _context;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void globalSetUp() {
|
||||||
_context = new RouterContext(null);
|
_context = new RouterContext(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void set() {
|
||||||
_context.random().nextBoolean();
|
_context.random().nextBoolean();
|
||||||
FragmentHandler.MAX_DEFRAGMENT_TIME = 10*1000;
|
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
|
* Send a message that fits inside a single fragment through
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSingle() {
|
public void testSingle() {
|
||||||
PendingGatewayMessage pending = createPending(949, false, false);
|
PendingGatewayMessage pending = createPending(949, false, false);
|
||||||
ArrayList messages = new ArrayList();
|
ArrayList messages = new ArrayList();
|
||||||
@ -51,21 +63,19 @@ public class FragmentTest extends TestCase{
|
|||||||
FragmentHandler handler = new FragmentHandler(_context, handleReceiver);
|
FragmentHandler handler = new FragmentHandler(_context, handleReceiver);
|
||||||
ReceiverImpl receiver = new ReceiverImpl(handler, 0);
|
ReceiverImpl receiver = new ReceiverImpl(handler, 0);
|
||||||
byte msg[] = pending.getData();
|
byte msg[] = pending.getData();
|
||||||
|
|
||||||
boolean keepGoing = true;
|
try {
|
||||||
while (keepGoing) {
|
pre.preprocessQueue(messages, new SenderImpl(), receiver);
|
||||||
keepGoing = pre.preprocessQueue(messages, new SenderImpl(), receiver);
|
fail("should have thrown IAE");
|
||||||
if (keepGoing)
|
} catch (IllegalArgumentException expected){}
|
||||||
try { Thread.sleep(100); } catch (InterruptedException ie) {}
|
|
||||||
}
|
|
||||||
assertTrue(handleReceiver.receivedOk());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message with two fragments through with no delay
|
* 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);
|
PendingGatewayMessage pending = createPending(2048, false, false);
|
||||||
ArrayList messages = new ArrayList();
|
ArrayList messages = new ArrayList();
|
||||||
messages.add(pending);
|
messages.add(pending);
|
||||||
@ -77,13 +87,10 @@ public class FragmentTest extends TestCase{
|
|||||||
ReceiverImpl receiver = new ReceiverImpl(handler, 0);
|
ReceiverImpl receiver = new ReceiverImpl(handler, 0);
|
||||||
byte msg[] = pending.getData();
|
byte msg[] = pending.getData();
|
||||||
|
|
||||||
boolean keepGoing = true;
|
try {
|
||||||
while (keepGoing) {
|
pre.preprocessQueue(messages, new SenderImpl(), receiver);
|
||||||
keepGoing = pre.preprocessQueue(messages, new SenderImpl(), receiver);
|
fail("should have thrown IAE");
|
||||||
if (keepGoing)
|
} catch (IllegalArgumentException expected){}
|
||||||
try { Thread.sleep(100); } catch (InterruptedException ie) {}
|
|
||||||
}
|
|
||||||
assertTrue(handleReceiver.receivedOk());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,10 +190,10 @@ public class FragmentTest extends TestCase{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected class DefragmentedReceiverImpl implements FragmentHandler.DefragmentedReceiver {
|
protected class DefragmentedReceiverImpl implements FragmentHandler.DefragmentedReceiver {
|
||||||
private byte _expected[];
|
private volatile byte _expected[];
|
||||||
private byte _expected2[];
|
private volatile byte _expected2[];
|
||||||
private byte _expected3[];
|
private volatile byte _expected3[];
|
||||||
private int _received;
|
private volatile int _received;
|
||||||
public DefragmentedReceiverImpl(byte expected[]) {
|
public DefragmentedReceiverImpl(byte expected[]) {
|
||||||
this(expected, null);
|
this(expected, null);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user