Fixes to JUnit tests under net.i2p.router.transport

This commit is contained in:
str4d
2013-01-02 22:05:12 +00:00
parent dae66d7f73
commit cdc3682baa
3 changed files with 21 additions and 29 deletions

View File

@@ -44,7 +44,7 @@ public class BandwidthLimitedInputStream extends FilterInputStream {
@Override @Override
public int read() throws IOException { public int read() throws IOException {
if (_pullFromOutbound) if (_pullFromOutbound)
_currentRequest = _context.bandwidthLimiter().requestOutbound(1, _peerSource); _currentRequest = _context.bandwidthLimiter().requestOutbound(1, 0, _peerSource);
else else
_currentRequest = _context.bandwidthLimiter().requestInbound(1, _peerSource); _currentRequest = _context.bandwidthLimiter().requestInbound(1, _peerSource);
@@ -68,12 +68,11 @@ public class BandwidthLimitedInputStream extends FilterInputStream {
if (read == -1) return -1; if (read == -1) return -1;
if (_pullFromOutbound) if (_pullFromOutbound)
_currentRequest = _context.bandwidthLimiter().requestOutbound(read, _peerSource); _currentRequest = _context.bandwidthLimiter().requestOutbound(read, 0, _peerSource);
else else
_currentRequest = _context.bandwidthLimiter().requestInbound(read, _peerSource); _currentRequest = _context.bandwidthLimiter().requestInbound(read, _peerSource);
while ( (_currentRequest.getPendingInboundRequested() > 0) || while (_currentRequest.getPendingRequested() > 0) {
(_currentRequest.getPendingOutboundRequested() > 0) ) {
// we still haven't been authorized for everything, keep on waiting // we still haven't been authorized for everything, keep on waiting
_currentRequest.waitForNextAllocation(); _currentRequest.waitForNextAllocation();
if (_currentRequest.getAborted()) { if (_currentRequest.getAborted()) {
@@ -92,12 +91,11 @@ public class BandwidthLimitedInputStream extends FilterInputStream {
long skip = in.skip(numBytes); long skip = in.skip(numBytes);
if (_pullFromOutbound) if (_pullFromOutbound)
_currentRequest = _context.bandwidthLimiter().requestOutbound((int)skip, _peerSource); _currentRequest = _context.bandwidthLimiter().requestOutbound((int)skip, 0, _peerSource);
else else
_currentRequest = _context.bandwidthLimiter().requestInbound((int)skip, _peerSource); _currentRequest = _context.bandwidthLimiter().requestInbound((int)skip, _peerSource);
while ( (_currentRequest.getPendingInboundRequested() > 0) || while (_currentRequest.getPendingRequested() > 0) {
(_currentRequest.getPendingOutboundRequested() > 0) ) {
// we still haven't been authorized for everything, keep on waiting // we still haven't been authorized for everything, keep on waiting
_currentRequest.waitForNextAllocation(); _currentRequest.waitForNextAllocation();
if (_currentRequest.getAborted()) { if (_currentRequest.getAborted()) {

View File

@@ -42,7 +42,7 @@ public class BandwidthLimitedOutputStream extends FilterOutputStream {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Writing a single byte!", new Exception("Single byte from...")); _log.debug("Writing a single byte!", new Exception("Single byte from..."));
long before = _context.clock().now(); long before = _context.clock().now();
FIFOBandwidthLimiter.Request req = _context.bandwidthLimiter().requestOutbound(1, _peerTarget); FIFOBandwidthLimiter.Request req = _context.bandwidthLimiter().requestOutbound(1, 0, _peerTarget);
// only a single byte, no need to loop // only a single byte, no need to loop
req.waitForNextAllocation(); req.waitForNextAllocation();
long waited = _context.clock().now() - before; long waited = _context.clock().now() - before;
@@ -63,11 +63,11 @@ public class BandwidthLimitedOutputStream extends FilterOutputStream {
if (len + off > src.length) if (len + off > src.length)
throw new IllegalArgumentException("wtf are you thinking? len=" + len throw new IllegalArgumentException("wtf are you thinking? len=" + len
+ ", off=" + off + ", data=" + src.length); + ", off=" + off + ", data=" + src.length);
_currentRequest = _context.bandwidthLimiter().requestOutbound(len, _peerTarget); _currentRequest = _context.bandwidthLimiter().requestOutbound(len, 0, _peerTarget);
int written = 0; int written = 0;
while (written < len) { while (written < len) {
int allocated = len - _currentRequest.getPendingOutboundRequested(); int allocated = len - _currentRequest.getPendingRequested();
int toWrite = allocated - written; int toWrite = allocated - written;
if (toWrite > 0) { if (toWrite > 0) {
try { try {

View File

@@ -29,25 +29,19 @@ public class UDPEndpointTest {
public void runTest(int numPeers) { public void runTest(int numPeers) {
_log.debug("Run test("+numPeers+")"); _log.debug("Run test("+numPeers+")");
try { _endpoints = new UDPEndpoint[numPeers];
_endpoints = new UDPEndpoint[numPeers]; int base = 2000 + _context.random().nextInt(10000);
int base = 2000 + _context.random().nextInt(10000); for (int i = 0; i < numPeers; i++) {
for (int i = 0; i < numPeers; i++) { _log.debug("Building " + i);
_log.debug("Building " + i); UDPEndpoint endpoint = new UDPEndpoint(_context, null, base + i, null);
UDPEndpoint endpoint = new UDPEndpoint(_context, null, base + i, null); _endpoints[i] = endpoint;
_endpoints[i] = endpoint; endpoint.startup();
endpoint.startup(); I2PThread read = new I2PThread(new TestRead(endpoint), "Test read " + i);
I2PThread read = new I2PThread(new TestRead(endpoint), "Test read " + i); I2PThread write = new I2PThread(new TestWrite(endpoint), "Test write " + i);
I2PThread write = new I2PThread(new TestWrite(endpoint), "Test write " + i); //read.setDaemon(true);
//read.setDaemon(true); read.start();
read.start(); //write.setDaemon(true);
//write.setDaemon(true); write.start();
write.start();
}
} catch (SocketException se) {
if (_log.shouldLog(Log.ERROR))
_log.error("Error initializing", se);
return;
} }
_beginTest = true; _beginTest = true;
_log.debug("Test begin"); _log.debug("Test begin");