mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Refactored transport component and renamed WritersModule.
The goal of the refactoring was to clean up the dependencies of IncomingBatchConnection and OutgoingBatchConnection.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package net.sf.briar.transport;
|
||||
|
||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.transport.ConnectionWriter;
|
||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||
import net.sf.briar.api.transport.TransportConstants;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -30,20 +31,20 @@ public class ConnectionWriterTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testOverhead() throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(
|
||||
TransportConstants.MIN_CONNECTION_LENGTH);
|
||||
ByteArrayOutputStream out =
|
||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||
true, transportId, connection, secret);
|
||||
MIN_CONNECTION_LENGTH, true, transportId, connection, secret);
|
||||
// Check that the connection writer thinks there's room for a packet
|
||||
long capacity = w.getCapacity(TransportConstants.MIN_CONNECTION_LENGTH);
|
||||
assertTrue(capacity >= ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
assertTrue(capacity <= TransportConstants.MIN_CONNECTION_LENGTH);
|
||||
long capacity = w.getCapacity();
|
||||
assertTrue(capacity >= MAX_PACKET_LENGTH);
|
||||
assertTrue(capacity <= MIN_CONNECTION_LENGTH);
|
||||
// Check that there really is room for a packet
|
||||
byte[] payload = new byte[ProtocolConstants.MAX_PACKET_LENGTH];
|
||||
byte[] payload = new byte[MAX_PACKET_LENGTH];
|
||||
w.getOutputStream().write(payload);
|
||||
w.getOutputStream().flush();
|
||||
long used = out.size();
|
||||
assertTrue(used >= ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
assertTrue(used <= TransportConstants.MIN_CONNECTION_LENGTH);
|
||||
assertTrue(used >= MAX_PACKET_LENGTH);
|
||||
assertTrue(used <= MIN_CONNECTION_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user