Removed shouldFlush() from plugins, added missing PacketWriter method.

This commit is contained in:
akwizgran
2014-01-15 17:10:25 +00:00
parent c146da2e7a
commit 6af3c54c28
17 changed files with 54 additions and 68 deletions

View File

@@ -39,6 +39,7 @@ import org.briarproject.api.messaging.MessageId;
import org.briarproject.api.messaging.Offer;
import org.briarproject.api.messaging.PacketWriter;
import org.briarproject.api.messaging.PacketWriterFactory;
import org.briarproject.api.messaging.Request;
import org.briarproject.api.messaging.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportUpdate;
import org.briarproject.crypto.CryptoModule;
@@ -153,6 +154,16 @@ public class ConstantsTest extends BriarTestCase {
testMessageIdsFitIntoOffer(1000);
}
@Test
public void testMessageIdsFitIntoLargeRequest() throws Exception {
testMessageIdsFitIntoRequest(MAX_PACKET_LENGTH);
}
@Test
public void testMessageIdsFitIntoSmallRequest() throws Exception {
testMessageIdsFitIntoRequest(1000);
}
@Test
public void testPropertiesFitIntoTransportUpdate() throws Exception {
// Create the maximum number of properties with the maximum length
@@ -195,24 +206,37 @@ public class ConstantsTest extends BriarTestCase {
// Create an ack with as many message IDs as possible
ByteArrayOutputStream out = new ByteArrayOutputStream(length);
PacketWriter writer = packetWriterFactory.createPacketWriter(out, true);
int maxMessages = writer.getMaxMessagesForRequest(length);
Collection<MessageId> acked = new ArrayList<MessageId>();
int maxMessages = writer.getMaxMessagesForAck(length);
Collection<MessageId> ids = new ArrayList<MessageId>();
for(int i = 0; i < maxMessages; i++)
acked.add(new MessageId(TestUtils.getRandomId()));
writer.writeAck(new Ack(acked));
ids.add(new MessageId(TestUtils.getRandomId()));
writer.writeAck(new Ack(ids));
// Check the size of the serialised ack
assertTrue(out.size() <= length);
}
private void testMessageIdsFitIntoRequest(int length) throws Exception {
// Create a request with as many message IDs as possible
ByteArrayOutputStream out = new ByteArrayOutputStream(length);
PacketWriter writer = packetWriterFactory.createPacketWriter(out, true);
int maxMessages = writer.getMaxMessagesForRequest(length);
Collection<MessageId> ids = new ArrayList<MessageId>();
for(int i = 0; i < maxMessages; i++)
ids.add(new MessageId(TestUtils.getRandomId()));
writer.writeRequest(new Request(ids));
// Check the size of the serialised request
assertTrue(out.size() <= length);
}
private void testMessageIdsFitIntoOffer(int length) throws Exception {
// Create an offer with as many message IDs as possible
ByteArrayOutputStream out = new ByteArrayOutputStream(length);
PacketWriter writer = packetWriterFactory.createPacketWriter(out, true);
int maxMessages = writer.getMaxMessagesForOffer(length);
Collection<MessageId> offered = new ArrayList<MessageId>();
Collection<MessageId> ids = new ArrayList<MessageId>();
for(int i = 0; i < maxMessages; i++)
offered.add(new MessageId(TestUtils.getRandomId()));
writer.writeOffer(new Offer(offered));
ids.add(new MessageId(TestUtils.getRandomId()));
writer.writeOffer(new Offer(ids));
// Check the size of the serialised offer
assertTrue(out.size() <= length);
}

View File

@@ -85,7 +85,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
public void testConnectionTooShort() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, MAX_PACKET_LENGTH, Long.MAX_VALUE, true);
out, MAX_PACKET_LENGTH, Long.MAX_VALUE);
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
secret, 0, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
@@ -103,7 +103,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
public void testNothingToSend() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE, true);
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE);
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
secret, 0, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
@@ -152,7 +152,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
public void testSomethingToSend() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE, true);
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE);
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
secret, 0, true);
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,

View File

@@ -146,7 +146,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
PacketWriterFactory packetWriterFactory =
alice.getInstance(PacketWriterFactory.class);
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
out, Long.MAX_VALUE, Long.MAX_VALUE, false);
out, Long.MAX_VALUE, Long.MAX_VALUE);
ConnectionContext ctx = km.getConnectionContext(contactId, transportId);
assertNotNull(ctx);
OutgoingSimplexConnection simplex = new OutgoingSimplexConnection(db,

View File

@@ -11,16 +11,14 @@ class TestSimplexTransportWriter implements SimplexTransportWriter {
private final ByteArrayOutputStream out;
private final long capacity, maxLatency;
private final boolean flush;
private boolean disposed = false, exception = false;
TestSimplexTransportWriter(ByteArrayOutputStream out, long capacity,
long maxLatency, boolean flush) {
long maxLatency) {
this.out = out;
this.capacity = capacity;
this.maxLatency = maxLatency;
this.flush = flush;
}
public long getCapacity() {
@@ -39,10 +37,6 @@ class TestSimplexTransportWriter implements SimplexTransportWriter {
return out;
}
public boolean shouldFlush() {
return flush;
}
public void dispose(boolean exception) {
assert !disposed;
disposed = true;