mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Remove raw messages from DB interface.
This commit is contained in:
@@ -99,9 +99,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
private final Group group;
|
||||
private final Author author;
|
||||
private final LocalAuthor localAuthor;
|
||||
private final Message message;
|
||||
private final Message message, message1;
|
||||
private final MessageId messageId, messageId1;
|
||||
private final byte[] raw, raw1;
|
||||
private final Metadata metadata;
|
||||
private final TransportId transportId;
|
||||
private final int maxLatency;
|
||||
@@ -117,11 +116,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
author = getAuthor();
|
||||
localAuthor = getLocalAuthor();
|
||||
message = getMessage(groupId);
|
||||
Message message1 = getMessage(groupId);
|
||||
message1 = getMessage(groupId);
|
||||
messageId = message.getId();
|
||||
messageId1 = message1.getId();
|
||||
raw = message.getRaw();
|
||||
raw1 = message1.getRaw();
|
||||
metadata = new Metadata();
|
||||
metadata.put("foo", new byte[] {'b', 'a', 'r'});
|
||||
transportId = getTransportId();
|
||||
@@ -867,7 +864,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testGenerateBatch() throws Exception {
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||
Collection<Message> messages = Arrays.asList(message, message1);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -876,12 +873,12 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
oneOf(database).getMessagesToSend(txn, contactId,
|
||||
MAX_MESSAGE_LENGTH * 2);
|
||||
will(returnValue(ids));
|
||||
oneOf(database).getRawMessage(txn, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(database).getMessage(txn, messageId);
|
||||
will(returnValue(message));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId,
|
||||
maxLatency);
|
||||
oneOf(database).getRawMessage(txn, messageId1);
|
||||
will(returnValue(raw1));
|
||||
oneOf(database).getMessage(txn, messageId1);
|
||||
will(returnValue(message1));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId1,
|
||||
maxLatency);
|
||||
oneOf(database).lowerRequestedFlag(txn, contactId, ids);
|
||||
@@ -963,7 +960,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testGenerateRequestedBatch() throws Exception {
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||
Collection<Message> messages = Arrays.asList(message, message1);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -972,12 +969,12 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
oneOf(database).getRequestedMessagesToSend(txn, contactId,
|
||||
MAX_MESSAGE_LENGTH * 2);
|
||||
will(returnValue(ids));
|
||||
oneOf(database).getRawMessage(txn, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(database).getMessage(txn, messageId);
|
||||
will(returnValue(message));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId,
|
||||
maxLatency);
|
||||
oneOf(database).getRawMessage(txn, messageId1);
|
||||
will(returnValue(raw1));
|
||||
oneOf(database).getMessage(txn, messageId1);
|
||||
will(returnValue(message1));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId1,
|
||||
maxLatency);
|
||||
oneOf(database).lowerRequestedFlag(txn, contactId, ids);
|
||||
|
||||
@@ -506,11 +506,11 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRawMessage() throws Exception {
|
||||
String name = "getRawMessage(T, MessageId)";
|
||||
public void testGetMessage() throws Exception {
|
||||
String name = "getMessage(T, MessageId)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
db.getRawMessage(txn, pickRandom(messages).getId());
|
||||
db.getMessage(txn, pickRandom(messages).getId());
|
||||
db.commitTransaction(txn);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -144,7 +144,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
assertTrue(db.containsContact(txn, contactId));
|
||||
assertTrue(db.containsGroup(txn, groupId));
|
||||
assertTrue(db.containsMessage(txn, messageId));
|
||||
assertArrayEquals(message.getRaw(), db.getRawMessage(txn, messageId));
|
||||
assertArrayEquals(message.getRaw(),
|
||||
db.getMessage(txn, messageId).getRaw());
|
||||
|
||||
// Delete the records
|
||||
db.removeMessage(txn, messageId);
|
||||
@@ -1645,9 +1646,6 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
assertEquals(message.getTimestamp(), m.getTimestamp());
|
||||
assertArrayEquals(message.getRaw(), m.getRaw());
|
||||
|
||||
// The raw message should be available
|
||||
assertArrayEquals(message.getRaw(), db.getRawMessage(txn, messageId));
|
||||
|
||||
// Delete the message
|
||||
db.deleteMessage(txn, messageId);
|
||||
|
||||
@@ -1668,14 +1666,6 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
// Expected
|
||||
}
|
||||
|
||||
// Requesting the raw message should throw an exception
|
||||
try {
|
||||
db.getRawMessage(txn, messageId);
|
||||
fail();
|
||||
} catch (MessageDeletedException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
@@ -1806,7 +1796,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
try {
|
||||
// Ask for a nonexistent message - an exception should be thrown
|
||||
db.getRawMessage(txn, messageId);
|
||||
db.getMessage(txn, messageId);
|
||||
fail();
|
||||
} catch (DbException expected) {
|
||||
// It should be possible to abort the transaction without error
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.sync.Ack;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.sync.SyncRecordWriter;
|
||||
import org.briarproject.bramble.api.transport.StreamWriter;
|
||||
@@ -13,12 +15,11 @@ import org.briarproject.bramble.test.ImmediateExecutor;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
|
||||
public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
|
||||
@@ -33,7 +34,8 @@ public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
|
||||
|
||||
private final Executor dbExecutor = new ImmediateExecutor();
|
||||
private final ContactId contactId = new ContactId(234);
|
||||
private final MessageId messageId = new MessageId(getRandomId());
|
||||
private final Message message = getMessage(new GroupId(getRandomId()));
|
||||
private final MessageId messageId = message.getId();
|
||||
|
||||
@Test
|
||||
public void testNothingToSend() throws Exception {
|
||||
@@ -72,8 +74,7 @@ public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testSomethingToSend() throws Exception {
|
||||
Ack ack = new Ack(Collections.singletonList(messageId));
|
||||
byte[] raw = getRandomBytes(1234);
|
||||
Ack ack = new Ack(singletonList(messageId));
|
||||
SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
dbExecutor, eventBus, contactId, MAX_LATENCY, streamWriter,
|
||||
recordWriter);
|
||||
@@ -98,10 +99,10 @@ public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
|
||||
will(returnValue(msgTxn));
|
||||
oneOf(db).generateBatch(with(msgTxn), with(contactId),
|
||||
with(any(int.class)), with(MAX_LATENCY));
|
||||
will(returnValue(Arrays.asList(raw)));
|
||||
will(returnValue(singletonList(message)));
|
||||
oneOf(db).commitTransaction(msgTxn);
|
||||
oneOf(db).endTransaction(msgTxn);
|
||||
oneOf(recordWriter).writeMessage(raw);
|
||||
oneOf(recordWriter).writeMessage(message.getRaw());
|
||||
// No more acks
|
||||
oneOf(db).startTransaction(false);
|
||||
will(returnValue(noAckTxn));
|
||||
|
||||
Reference in New Issue
Block a user