forked from I2P_Developers/i2p.i2p
Fixes to JUnit tests under net.i2p.router.transport
This commit is contained in:
@@ -44,7 +44,7 @@ public class BandwidthLimitedInputStream extends FilterInputStream {
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if (_pullFromOutbound)
|
||||
_currentRequest = _context.bandwidthLimiter().requestOutbound(1, _peerSource);
|
||||
_currentRequest = _context.bandwidthLimiter().requestOutbound(1, 0, _peerSource);
|
||||
else
|
||||
_currentRequest = _context.bandwidthLimiter().requestInbound(1, _peerSource);
|
||||
|
||||
@@ -68,12 +68,11 @@ public class BandwidthLimitedInputStream extends FilterInputStream {
|
||||
if (read == -1) return -1;
|
||||
|
||||
if (_pullFromOutbound)
|
||||
_currentRequest = _context.bandwidthLimiter().requestOutbound(read, _peerSource);
|
||||
_currentRequest = _context.bandwidthLimiter().requestOutbound(read, 0, _peerSource);
|
||||
else
|
||||
_currentRequest = _context.bandwidthLimiter().requestInbound(read, _peerSource);
|
||||
|
||||
while ( (_currentRequest.getPendingInboundRequested() > 0) ||
|
||||
(_currentRequest.getPendingOutboundRequested() > 0) ) {
|
||||
while (_currentRequest.getPendingRequested() > 0) {
|
||||
// we still haven't been authorized for everything, keep on waiting
|
||||
_currentRequest.waitForNextAllocation();
|
||||
if (_currentRequest.getAborted()) {
|
||||
@@ -92,12 +91,11 @@ public class BandwidthLimitedInputStream extends FilterInputStream {
|
||||
long skip = in.skip(numBytes);
|
||||
|
||||
if (_pullFromOutbound)
|
||||
_currentRequest = _context.bandwidthLimiter().requestOutbound((int)skip, _peerSource);
|
||||
_currentRequest = _context.bandwidthLimiter().requestOutbound((int)skip, 0, _peerSource);
|
||||
else
|
||||
_currentRequest = _context.bandwidthLimiter().requestInbound((int)skip, _peerSource);
|
||||
|
||||
while ( (_currentRequest.getPendingInboundRequested() > 0) ||
|
||||
(_currentRequest.getPendingOutboundRequested() > 0) ) {
|
||||
while (_currentRequest.getPendingRequested() > 0) {
|
||||
// we still haven't been authorized for everything, keep on waiting
|
||||
_currentRequest.waitForNextAllocation();
|
||||
if (_currentRequest.getAborted()) {
|
||||
|
@@ -42,7 +42,7 @@ public class BandwidthLimitedOutputStream extends FilterOutputStream {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Writing a single byte!", new Exception("Single byte from..."));
|
||||
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
|
||||
req.waitForNextAllocation();
|
||||
long waited = _context.clock().now() - before;
|
||||
@@ -63,11 +63,11 @@ public class BandwidthLimitedOutputStream extends FilterOutputStream {
|
||||
if (len + off > src.length)
|
||||
throw new IllegalArgumentException("wtf are you thinking? len=" + len
|
||||
+ ", off=" + off + ", data=" + src.length);
|
||||
_currentRequest = _context.bandwidthLimiter().requestOutbound(len, _peerTarget);
|
||||
_currentRequest = _context.bandwidthLimiter().requestOutbound(len, 0, _peerTarget);
|
||||
|
||||
int written = 0;
|
||||
while (written < len) {
|
||||
int allocated = len - _currentRequest.getPendingOutboundRequested();
|
||||
int allocated = len - _currentRequest.getPendingRequested();
|
||||
int toWrite = allocated - written;
|
||||
if (toWrite > 0) {
|
||||
try {
|
||||
|
@@ -29,25 +29,19 @@ public class UDPEndpointTest {
|
||||
|
||||
public void runTest(int numPeers) {
|
||||
_log.debug("Run test("+numPeers+")");
|
||||
try {
|
||||
_endpoints = new UDPEndpoint[numPeers];
|
||||
int base = 2000 + _context.random().nextInt(10000);
|
||||
for (int i = 0; i < numPeers; i++) {
|
||||
_log.debug("Building " + i);
|
||||
UDPEndpoint endpoint = new UDPEndpoint(_context, null, base + i, null);
|
||||
_endpoints[i] = endpoint;
|
||||
endpoint.startup();
|
||||
I2PThread read = new I2PThread(new TestRead(endpoint), "Test read " + i);
|
||||
I2PThread write = new I2PThread(new TestWrite(endpoint), "Test write " + i);
|
||||
//read.setDaemon(true);
|
||||
read.start();
|
||||
//write.setDaemon(true);
|
||||
write.start();
|
||||
}
|
||||
} catch (SocketException se) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Error initializing", se);
|
||||
return;
|
||||
_endpoints = new UDPEndpoint[numPeers];
|
||||
int base = 2000 + _context.random().nextInt(10000);
|
||||
for (int i = 0; i < numPeers; i++) {
|
||||
_log.debug("Building " + i);
|
||||
UDPEndpoint endpoint = new UDPEndpoint(_context, null, base + i, null);
|
||||
_endpoints[i] = endpoint;
|
||||
endpoint.startup();
|
||||
I2PThread read = new I2PThread(new TestRead(endpoint), "Test read " + i);
|
||||
I2PThread write = new I2PThread(new TestWrite(endpoint), "Test write " + i);
|
||||
//read.setDaemon(true);
|
||||
read.start();
|
||||
//write.setDaemon(true);
|
||||
write.start();
|
||||
}
|
||||
_beginTest = true;
|
||||
_log.debug("Test begin");
|
||||
|
Reference in New Issue
Block a user