mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Replaced PacketWriter methods with a constant.
This commit is contained in:
@@ -21,13 +21,8 @@ import org.briarproject.api.identity.AuthorFactory;
|
||||
import org.briarproject.api.messaging.MessagingConstants;
|
||||
import org.briarproject.api.messaging.PrivateMessage;
|
||||
import org.briarproject.api.messaging.PrivateMessageFactory;
|
||||
import org.briarproject.api.sync.Ack;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.sync.Offer;
|
||||
import org.briarproject.api.sync.PacketWriter;
|
||||
import org.briarproject.api.sync.PacketWriterFactory;
|
||||
import org.briarproject.api.sync.Request;
|
||||
import org.briarproject.contact.ContactModule;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.data.DataModule;
|
||||
@@ -38,9 +33,6 @@ import org.briarproject.identity.IdentityModule;
|
||||
import org.briarproject.messaging.MessagingModule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.briarproject.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
|
||||
@@ -59,7 +51,6 @@ public class ConstantsTest extends BriarTestCase {
|
||||
private final AuthorFactory authorFactory;
|
||||
private final PrivateMessageFactory privateMessageFactory;
|
||||
private final ForumPostFactory forumPostFactory;
|
||||
private final PacketWriterFactory packetWriterFactory;
|
||||
|
||||
public ConstantsTest() throws Exception {
|
||||
Injector i = Guice.createInjector(new TestDatabaseModule(),
|
||||
@@ -71,7 +62,6 @@ public class ConstantsTest extends BriarTestCase {
|
||||
authorFactory = i.getInstance(AuthorFactory.class);
|
||||
privateMessageFactory = i.getInstance(PrivateMessageFactory.class);
|
||||
forumPostFactory = i.getInstance(ForumPostFactory.class);
|
||||
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,16 +95,6 @@ public class ConstantsTest extends BriarTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageIdsFitIntoLargeAck() throws Exception {
|
||||
testMessageIdsFitIntoAck(MAX_PACKET_PAYLOAD_LENGTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageIdsFitIntoSmallAck() throws Exception {
|
||||
testMessageIdsFitIntoAck(1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrivateMessageFitsIntoPacket() throws Exception {
|
||||
// Create a maximum-length private message
|
||||
@@ -159,63 +139,4 @@ public class ConstantsTest extends BriarTestCase {
|
||||
+ MAX_FORUM_POST_BODY_LENGTH);
|
||||
assertTrue(length <= MAX_PACKET_PAYLOAD_LENGTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageIdsFitIntoLargeOffer() throws Exception {
|
||||
testMessageIdsFitIntoOffer(MAX_PACKET_PAYLOAD_LENGTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageIdsFitIntoSmallOffer() throws Exception {
|
||||
testMessageIdsFitIntoOffer(1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageIdsFitIntoLargeRequest() throws Exception {
|
||||
testMessageIdsFitIntoRequest(MAX_PACKET_PAYLOAD_LENGTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageIdsFitIntoSmallRequest() throws Exception {
|
||||
testMessageIdsFitIntoRequest(1000);
|
||||
}
|
||||
|
||||
private void testMessageIdsFitIntoAck(int length) throws Exception {
|
||||
// Create an ack with as many message IDs as possible
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(length);
|
||||
PacketWriter writer = packetWriterFactory.createPacketWriter(out);
|
||||
int maxMessages = writer.getMaxMessagesForAck(length);
|
||||
Collection<MessageId> ids = new ArrayList<MessageId>();
|
||||
for (int i = 0; i < maxMessages; i++)
|
||||
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);
|
||||
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);
|
||||
int maxMessages = writer.getMaxMessagesForOffer(length);
|
||||
Collection<MessageId> ids = new ArrayList<MessageId>();
|
||||
for (int i = 0; i < maxMessages; i++)
|
||||
ids.add(new MessageId(TestUtils.getRandomId()));
|
||||
writer.writeOffer(new Offer(ids));
|
||||
// Check the size of the serialised offer
|
||||
assertTrue(out.size() <= length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_IDS;
|
||||
|
||||
private static final int MAX_MESSAGES_PER_ACK = 10;
|
||||
public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
|
||||
private final Mockery context;
|
||||
private final DatabaseComponent db;
|
||||
@@ -53,9 +53,7 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
// Add listener
|
||||
oneOf(eventBus).addListener(session);
|
||||
// No acks to send
|
||||
oneOf(packetWriter).getMaxMessagesForAck(with(any(long.class)));
|
||||
will(returnValue(MAX_MESSAGES_PER_ACK));
|
||||
oneOf(db).generateAck(contactId, MAX_MESSAGES_PER_ACK);
|
||||
oneOf(db).generateAck(contactId, MAX_MESSAGE_IDS);
|
||||
will(returnValue(null));
|
||||
// No messages to send
|
||||
oneOf(db).generateBatch(with(contactId), with(any(int.class)),
|
||||
@@ -81,15 +79,11 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
// Add listener
|
||||
oneOf(eventBus).addListener(session);
|
||||
// One ack to send
|
||||
oneOf(packetWriter).getMaxMessagesForAck(with(any(long.class)));
|
||||
will(returnValue(MAX_MESSAGES_PER_ACK));
|
||||
oneOf(db).generateAck(contactId, MAX_MESSAGES_PER_ACK);
|
||||
oneOf(db).generateAck(contactId, MAX_MESSAGE_IDS);
|
||||
will(returnValue(ack));
|
||||
oneOf(packetWriter).writeAck(ack);
|
||||
// No more acks
|
||||
oneOf(packetWriter).getMaxMessagesForAck(with(any(long.class)));
|
||||
will(returnValue(MAX_MESSAGES_PER_ACK));
|
||||
oneOf(db).generateAck(contactId, MAX_MESSAGES_PER_ACK);
|
||||
oneOf(db).generateAck(contactId, MAX_MESSAGE_IDS);
|
||||
will(returnValue(null));
|
||||
// One message to send
|
||||
oneOf(db).generateBatch(with(contactId), with(any(int.class)),
|
||||
|
||||
Reference in New Issue
Block a user