mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Asynchronous offers and requests for BMP.
Offered and requested message IDs are stored in the database rather than being owned by DuplexConnections. This paves the way for moving to a simplex transport layer.
This commit is contained in:
@@ -3,13 +3,10 @@ package net.sf.briar.db;
|
||||
import static net.sf.briar.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.GROUP_SALT_LENGTH;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestMessage;
|
||||
@@ -22,7 +19,6 @@ import net.sf.briar.api.LocalAuthor;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.db.AckAndRequest;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.NoSuchContactException;
|
||||
import net.sf.briar.api.db.NoSuchLocalAuthorException;
|
||||
@@ -34,8 +30,10 @@ import net.sf.briar.api.db.event.DatabaseListener;
|
||||
import net.sf.briar.api.db.event.LocalAuthorAddedEvent;
|
||||
import net.sf.briar.api.db.event.LocalAuthorRemovedEvent;
|
||||
import net.sf.briar.api.db.event.LocalSubscriptionsUpdatedEvent;
|
||||
import net.sf.briar.api.db.event.LocalTransportsUpdatedEvent;
|
||||
import net.sf.briar.api.db.event.MessageAddedEvent;
|
||||
import net.sf.briar.api.db.event.MessageReceivedEvent;
|
||||
import net.sf.briar.api.db.event.MessageToAckEvent;
|
||||
import net.sf.briar.api.db.event.MessageToRequestEvent;
|
||||
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
@@ -186,6 +184,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
// removeContact()
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getInboxGroupId(txn, contactId);
|
||||
will(returnValue(null));
|
||||
oneOf(database).removeContact(txn, contactId);
|
||||
oneOf(listener).eventOccurred(with(any(ContactRemovedEvent.class)));
|
||||
// removeLocalAuthor()
|
||||
@@ -288,9 +288,13 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(true));
|
||||
oneOf(database).addMessage(txn, message, false);
|
||||
oneOf(database).setReadFlag(txn, messageId, true);
|
||||
oneOf(database).getVisibility(txn, groupId);
|
||||
will(returnValue(Arrays.asList(contactId)));
|
||||
oneOf(database).getContactIds(txn);
|
||||
will(returnValue(Arrays.asList(contactId)));
|
||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||
oneOf(database).removeOfferedMessage(txn, contactId, messageId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addStatus(txn, contactId, messageId, false, false);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
// The message was added, so the listener should be called
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
@@ -315,11 +319,11 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the contact is in the DB (which it's not)
|
||||
exactly(28).of(database).startTransaction();
|
||||
exactly(25).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(28).of(database).containsContact(txn, contactId);
|
||||
exactly(25).of(database).containsContact(txn, contactId);
|
||||
will(returnValue(false));
|
||||
exactly(28).of(database).abortTransaction(txn);
|
||||
exactly(25).of(database).abortTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
@@ -329,11 +333,6 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
try {
|
||||
db.containsSendableMessages(contactId);
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
try {
|
||||
db.generateAck(contactId, 123);
|
||||
fail();
|
||||
@@ -345,12 +344,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
try {
|
||||
db.generateBatch(contactId, 123, 456, Arrays.asList(messageId));
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
try {
|
||||
db.generateOffer(contactId, 123);
|
||||
db.generateOffer(contactId, 123, 456);
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
@@ -469,11 +463,6 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
try {
|
||||
db.setSeen(contactId, Arrays.asList(messageId));
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -657,17 +646,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Two transactions: read and write
|
||||
exactly(2).of(database).startTransaction();
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(2).of(database).commitTransaction(txn);
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
// Get the messages to ack
|
||||
oneOf(database).getMessagesToAck(txn, contactId, 123);
|
||||
will(returnValue(messagesToAck));
|
||||
// Record the messages that were acked
|
||||
oneOf(database).removeMessagesToAck(txn, contactId, messagesToAck);
|
||||
oneOf(database).lowerAckFlag(txn, contactId, messagesToAck);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
@@ -681,38 +667,30 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testGenerateBatch() throws Exception {
|
||||
final byte[] raw1 = new byte[size];
|
||||
final Collection<MessageId> sendable = Arrays.asList(messageId,
|
||||
messageId1);
|
||||
final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
final Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||
final Map<MessageId, Integer> sent = new HashMap<MessageId, Integer>();
|
||||
sent.put(messageId, 1);
|
||||
sent.put(messageId1, 2);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Two transactions: read and write
|
||||
exactly(2).of(database).startTransaction();
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(2).of(database).commitTransaction(txn);
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
// Get the sendable messages and their transmission counts
|
||||
oneOf(database).getSendableMessages(txn, contactId, size * 2);
|
||||
will(returnValue(sendable));
|
||||
oneOf(database).getMessagesToSend(txn, contactId, size * 2);
|
||||
will(returnValue(ids));
|
||||
oneOf(database).getRawMessage(txn, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(database).getTransmissionCount(txn, contactId, messageId);
|
||||
will(returnValue(1));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId,
|
||||
Long.MAX_VALUE);
|
||||
oneOf(database).getRawMessage(txn, messageId1);
|
||||
will(returnValue(raw1));
|
||||
oneOf(database).getTransmissionCount(txn, contactId, messageId1);
|
||||
will(returnValue(2));
|
||||
// Record the outstanding messages
|
||||
oneOf(database).updateExpiryTimes(txn, contactId, sent,
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId1,
|
||||
Long.MAX_VALUE);
|
||||
oneOf(database).lowerRequestedFlag(txn, contactId, ids);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
@@ -723,52 +701,10 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateBatchFromRequest() throws Exception {
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
final byte[] raw1 = new byte[size];
|
||||
final Collection<MessageId> requested = new ArrayList<MessageId>(
|
||||
Arrays.asList(messageId, messageId1, messageId2));
|
||||
final Collection<byte[]> messages = Arrays.asList(raw1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Two transactions: read and write
|
||||
exactly(2).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(2).of(database).commitTransaction(txn);
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
// Try to get the requested messages
|
||||
oneOf(database).getRawMessageIfSendable(txn, contactId, messageId);
|
||||
will(returnValue(null)); // Message is not sendable
|
||||
oneOf(database).getRawMessageIfSendable(txn, contactId, messageId1);
|
||||
will(returnValue(raw1)); // Message is sendable
|
||||
oneOf(database).getTransmissionCount(txn, contactId, messageId1);
|
||||
will(returnValue(2));
|
||||
oneOf(database).getRawMessageIfSendable(txn, contactId, messageId2);
|
||||
will(returnValue(null)); // Message is not sendable
|
||||
// Mark the message as sent
|
||||
oneOf(database).updateExpiryTimes(txn, contactId,
|
||||
Collections.singletonMap(messageId1, 2), Long.MAX_VALUE);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
assertEquals(messages, db.generateBatch(contactId, size * 3,
|
||||
Long.MAX_VALUE, requested));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateOffer() throws Exception {
|
||||
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
final Collection<MessageId> messagesToOffer = Arrays.asList(messageId,
|
||||
messageId1);
|
||||
final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
@@ -779,16 +715,85 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
// Get the sendable message IDs
|
||||
oneOf(database).getMessagesToOffer(txn, contactId, 123);
|
||||
will(returnValue(messagesToOffer));
|
||||
will(returnValue(ids));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId,
|
||||
Long.MAX_VALUE);
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId1,
|
||||
Long.MAX_VALUE);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
Offer o = db.generateOffer(contactId, 123);
|
||||
assertEquals(messagesToOffer, o.getMessageIds());
|
||||
Offer o = db.generateOffer(contactId, 123, Long.MAX_VALUE);
|
||||
assertEquals(ids, o.getMessageIds());
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateRequest() throws Exception {
|
||||
final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getMessagesToRequest(txn, contactId, 123);
|
||||
will(returnValue(ids));
|
||||
oneOf(database).removeOfferedMessages(txn, contactId, ids);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
Request r = db.generateRequest(contactId, 123);
|
||||
assertEquals(ids, r.getMessageIds());
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateRequestedBatch() throws Exception {
|
||||
final byte[] raw1 = new byte[size];
|
||||
final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
final Collection<byte[]> messages = Arrays.asList(raw, raw1);
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getRequestedMessagesToSend(txn, contactId,
|
||||
size * 2);
|
||||
will(returnValue(ids));
|
||||
oneOf(database).getRawMessage(txn, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId,
|
||||
Long.MAX_VALUE);
|
||||
oneOf(database).getRawMessage(txn, messageId1);
|
||||
will(returnValue(raw1));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId1,
|
||||
Long.MAX_VALUE);
|
||||
oneOf(database).lowerRequestedFlag(txn, contactId, ids);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
assertEquals(messages, db.generateRequestedBatch(contactId, size * 2,
|
||||
Long.MAX_VALUE));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -965,7 +970,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setStatusSeenIfVisible(txn, contactId, messageId);
|
||||
oneOf(database).containsVisibleMessage(txn, contactId, messageId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).raiseSeenFlag(txn, contactId, messageId);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
@@ -994,14 +1001,18 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).containsVisibleGroup(txn, contactId, groupId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).addMessage(txn, message, true);
|
||||
oneOf(database).addStatus(txn, contactId, messageId, true);
|
||||
oneOf(database).getVisibility(txn, groupId);
|
||||
will(returnValue(Arrays.asList(contactId)));
|
||||
oneOf(database).getContactIds(txn);
|
||||
will(returnValue(Arrays.asList(contactId)));
|
||||
oneOf(database).addMessageToAck(txn, contactId, messageId);
|
||||
oneOf(database).removeOfferedMessage(txn, contactId, messageId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addStatus(txn, contactId, messageId, false, true);
|
||||
oneOf(database).raiseAckFlag(txn, contactId, messageId);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
// The message was received and added
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
MessageReceivedEvent.class)));
|
||||
MessageToAckEvent.class)));
|
||||
oneOf(listener).eventOccurred(with(any(MessageAddedEvent.class)));
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
@@ -1031,11 +1042,11 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).containsVisibleGroup(txn, contactId, groupId);
|
||||
will(returnValue(true));
|
||||
// The message wasn't stored but it must still be acked
|
||||
oneOf(database).addMessageToAck(txn, contactId, messageId);
|
||||
oneOf(database).raiseAckFlag(txn, contactId, messageId);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
// The message was received but not added
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
MessageReceivedEvent.class)));
|
||||
MessageToAckEvent.class)));
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
@@ -1084,31 +1095,58 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final DatabaseListener listener = context.mock(DatabaseListener.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
// Get the offered messages
|
||||
oneOf(database).setStatusSeenIfVisible(txn, contactId, messageId);
|
||||
oneOf(database).containsVisibleMessage(txn, contactId, messageId);
|
||||
will(returnValue(false)); // Not visible - request message # 0
|
||||
oneOf(database).setStatusSeenIfVisible(txn, contactId, messageId1);
|
||||
oneOf(database).addOfferedMessage(txn, contactId, messageId);
|
||||
oneOf(database).containsVisibleMessage(txn, contactId, messageId1);
|
||||
will(returnValue(true)); // Visible - ack message # 1
|
||||
oneOf(database).setStatusSeenIfVisible(txn, contactId, messageId2);
|
||||
oneOf(database).raiseSeenFlag(txn, contactId, messageId1);
|
||||
oneOf(database).raiseAckFlag(txn, contactId, messageId1);
|
||||
oneOf(database).containsVisibleMessage(txn, contactId, messageId2);
|
||||
will(returnValue(false)); // Not visible - request message # 2
|
||||
oneOf(database).addOfferedMessage(txn, contactId, messageId2);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
oneOf(listener).eventOccurred(with(any(MessageToAckEvent.class)));
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
MessageToRequestEvent.class)));
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
db.addListener(listener);
|
||||
Offer o = new Offer(Arrays.asList(messageId, messageId1, messageId2));
|
||||
db.receiveOffer(contactId, o);
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveRequest() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsVisibleMessage(txn, contactId, messageId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).raiseRequestedFlag(txn, contactId, messageId);
|
||||
oneOf(database).resetExpiryTime(txn, contactId, messageId);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
Offer o = new Offer(Arrays.asList(messageId, messageId1, messageId2));
|
||||
AckAndRequest ar = db.receiveOffer(contactId, o);
|
||||
Ack a = ar.getAck();
|
||||
assertNotNull(a);
|
||||
assertEquals(Arrays.asList(messageId1), a.getMessageIds());
|
||||
Request r = ar.getRequest();
|
||||
assertNotNull(r);
|
||||
assertEquals(Arrays.asList(messageId, messageId2), r.getMessageIds());
|
||||
db.receiveRequest(contactId, new Request(Arrays.asList(messageId)));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -1248,6 +1286,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final DatabaseListener listener = context.mock(DatabaseListener.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1257,10 +1296,13 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(new TransportProperties()));
|
||||
oneOf(database).mergeLocalProperties(txn, transportId, properties);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
LocalTransportsUpdatedEvent.class)));
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
db.addListener(listener);
|
||||
db.mergeLocalProperties(transportId, properties);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
@@ -1295,29 +1337,6 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSeen() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setStatusSeenIfVisible(txn, contactId, messageId);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
db.setSeen(contactId, Arrays.asList(messageId));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChangingVisibilityCallsListeners() throws Exception {
|
||||
final ContactId contactId1 = new ContactId(123);
|
||||
|
||||
@@ -171,24 +171,23 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
// The message has no status yet, so it should not be sendable
|
||||
assertFalse(db.containsSendableMessages(txn, contactId));
|
||||
Iterator<MessageId> it =
|
||||
db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
Collection<MessageId> ids = db.getMessagesToSend(txn, contactId,
|
||||
ONE_MEGABYTE);
|
||||
assertTrue(ids.isEmpty());
|
||||
|
||||
// Adding a status with seen = false should make the message sendable
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
assertTrue(db.containsSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
db.addStatus(txn, contactId, messageId, false, false);
|
||||
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE);
|
||||
assertFalse(ids.isEmpty());
|
||||
Iterator<MessageId> it = ids.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Changing the status to seen = true should make the message unsendable
|
||||
db.setStatusSeenIfVisible(txn, contactId, messageId);
|
||||
assertFalse(db.containsSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
db.raiseSeenFlag(txn, contactId, messageId);
|
||||
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE);
|
||||
assertTrue(ids.isEmpty());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
@@ -205,27 +204,26 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
db.addStatus(txn, contactId, messageId, false, false);
|
||||
|
||||
// The contact is not subscribed, so the message should not be sendable
|
||||
assertFalse(db.containsSendableMessages(txn, contactId));
|
||||
Iterator<MessageId> it =
|
||||
db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
Collection<MessageId> ids = db.getMessagesToSend(txn, contactId,
|
||||
ONE_MEGABYTE);
|
||||
assertTrue(ids.isEmpty());
|
||||
|
||||
// The contact subscribing should make the message sendable
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
assertTrue(db.containsSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE);
|
||||
assertFalse(ids.isEmpty());
|
||||
Iterator<MessageId> it = ids.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// The contact unsubscribing should make the message unsendable
|
||||
db.setGroups(txn, contactId, Collections.<Group>emptyList(), 2);
|
||||
assertFalse(db.containsSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE);
|
||||
assertTrue(ids.isEmpty());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
@@ -243,17 +241,17 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
db.addStatus(txn, contactId, messageId, false, false);
|
||||
|
||||
// The message is sendable, but too large to send
|
||||
assertTrue(db.containsSendableMessages(txn, contactId));
|
||||
Iterator<MessageId> it =
|
||||
db.getSendableMessages(txn, contactId, size - 1).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
Collection<MessageId> ids = db.getMessagesToSend(txn, contactId,
|
||||
size - 1);
|
||||
assertTrue(ids.isEmpty());
|
||||
|
||||
// The message is just the right size to send
|
||||
assertTrue(db.containsSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, size).iterator();
|
||||
ids = db.getMessagesToSend(txn, contactId, size);
|
||||
assertFalse(ids.isEmpty());
|
||||
Iterator<MessageId> it = ids.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
@@ -273,19 +271,19 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addGroup(txn, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
db.addStatus(txn, contactId, messageId, false, false);
|
||||
|
||||
// The subscription is not visible to the contact, so the message
|
||||
// should not be sendable
|
||||
assertFalse(db.containsSendableMessages(txn, contactId));
|
||||
Iterator<MessageId> it =
|
||||
db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
Collection<MessageId> ids = db.getMessagesToSend(txn, contactId,
|
||||
ONE_MEGABYTE);
|
||||
assertTrue(ids.isEmpty());
|
||||
|
||||
// Making the subscription visible should make the message sendable
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
assertTrue(db.containsSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE);
|
||||
assertFalse(ids.isEmpty());
|
||||
Iterator<MessageId> it = ids.iterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
@@ -310,18 +308,18 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Message message1 = new TestMessage(messageId1, null, group, author,
|
||||
contentType, subject, timestamp, raw);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, true);
|
||||
db.addMessageToAck(txn, contactId, messageId);
|
||||
db.addStatus(txn, contactId, messageId, false, true);
|
||||
db.raiseAckFlag(txn, contactId, messageId);
|
||||
db.addMessage(txn, message1, false);
|
||||
db.addStatus(txn, contactId, messageId1, true);
|
||||
db.addMessageToAck(txn, contactId, messageId1);
|
||||
db.addStatus(txn, contactId, messageId1, false, true);
|
||||
db.raiseAckFlag(txn, contactId, messageId1);
|
||||
|
||||
// Both message IDs should be returned
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
assertEquals(ids, db.getMessagesToAck(txn, contactId, 1234));
|
||||
|
||||
// Remove both message IDs
|
||||
db.removeMessagesToAck(txn, contactId, ids);
|
||||
db.lowerAckFlag(txn, contactId, Arrays.asList(messageId, messageId1));
|
||||
|
||||
// Both message IDs should have been removed
|
||||
assertEquals(Collections.emptyList(), db.getMessagesToAck(txn,
|
||||
@@ -344,16 +342,16 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Receive the same message twice
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, true);
|
||||
db.addMessageToAck(txn, contactId, messageId);
|
||||
db.addMessageToAck(txn, contactId, messageId);
|
||||
db.addStatus(txn, contactId, messageId, false, true);
|
||||
db.raiseAckFlag(txn, contactId, messageId);
|
||||
db.raiseAckFlag(txn, contactId, messageId);
|
||||
|
||||
// The message ID should only be returned once
|
||||
Collection<MessageId> ids = db.getMessagesToAck(txn, contactId, 1234);
|
||||
assertEquals(Arrays.asList(messageId), ids);
|
||||
|
||||
// Remove the message ID
|
||||
db.removeMessagesToAck(txn, contactId, Arrays.asList(messageId));
|
||||
db.lowerAckFlag(txn, contactId, Arrays.asList(messageId));
|
||||
|
||||
// The message ID should have been removed
|
||||
assertEquals(Collections.emptyList(), db.getMessagesToAck(txn,
|
||||
@@ -375,26 +373,25 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
db.addStatus(txn, contactId, messageId, false, false);
|
||||
|
||||
// Retrieve the message from the database and mark it as sent
|
||||
Iterator<MessageId> it =
|
||||
db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
db.getMessagesToSend(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
db.updateExpiryTimes(txn, contactId,
|
||||
Collections.singletonMap(messageId, 0), Long.MAX_VALUE);
|
||||
db.updateExpiryTime(txn, contactId, messageId, Long.MAX_VALUE);
|
||||
|
||||
// The message should no longer be sendable
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
it = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Pretend that the message was acked
|
||||
db.setStatusSeenIfVisible(txn, contactId, messageId);
|
||||
db.raiseSeenFlag(txn, contactId, messageId);
|
||||
|
||||
// The message still should not be sendable
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
it = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
@@ -661,7 +658,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMessageIfSendableReturnsNullIfNotInDatabase()
|
||||
public void testContainsVisibleMessageRequiresMessageInDatabase()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -674,106 +671,14 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
|
||||
// The message is not in the database
|
||||
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
|
||||
assertFalse(db.containsVisibleMessage(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMessageIfSendableReturnsNullIfSeen() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
// Set the status to seen = true
|
||||
db.addStatus(txn, contactId, messageId, true);
|
||||
|
||||
// The message is not sendable because its status is seen = true
|
||||
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMessageIfSendableReturnsNullIfOld() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message -
|
||||
// the message is older than the contact's retention time
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.setRetentionTime(txn, contactId, timestamp + 1, 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
// Set the status to seen = false
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The message is not sendable because it's too old
|
||||
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMessageIfSendableReturnsMessage() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
// Set the status to seen = false
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The message is sendable so it should be returned
|
||||
byte[] b = db.getRawMessageIfSendable(txn, contactId, messageId);
|
||||
assertArrayEquals(raw, b);
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStatusSeenIfVisibleRequiresMessageInDatabase()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
|
||||
// The message is not in the database
|
||||
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStatusSeenIfVisibleRequiresLocalSubscription()
|
||||
public void testContainsVisibleMessageRequiresLocalSubscription()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -784,35 +689,14 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
|
||||
// There's no local subscription for the group
|
||||
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
assertFalse(db.containsVisibleMessage(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStatusSeenIfVisibleRequiresContactSubscription()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// There's no contact subscription for the group
|
||||
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStatusSeenIfVisibleRequiresVisibility()
|
||||
public void testContainsVisibleMessageRequiresVisibileSubscription()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -823,56 +707,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addGroup(txn, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
db.addStatus(txn, contactId, messageId, false, false);
|
||||
|
||||
// The subscription is not visible
|
||||
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStatusSeenIfVisibleReturnsTrueIfAlreadySeen()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
// The message has already been seen by the contact
|
||||
db.addStatus(txn, contactId, messageId, true);
|
||||
|
||||
assertTrue(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStatusSeenIfVisibleReturnsTrueIfNew()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
// The message has not been seen by the contact
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
assertTrue(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
assertFalse(db.containsVisibleMessage(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
@@ -946,8 +784,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParentWithParentInAnotherGroup()
|
||||
throws Exception {
|
||||
public void testGetParentWithParentInAnotherGroup() throws Exception {
|
||||
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||
Group group1 = new Group(groupId1, "Another group",
|
||||
new byte[GROUP_SALT_LENGTH]);
|
||||
@@ -976,8 +813,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParentWithParentInSameGroup()
|
||||
throws Exception {
|
||||
public void testGetParentWithParentInSameGroup() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
@@ -1060,11 +896,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
contentType, subject, timestamp1, raw);
|
||||
db.addMessage(txn, message1, false);
|
||||
// Mark one of the messages read
|
||||
assertFalse(db.setReadFlag(txn, messageId, true));
|
||||
db.setReadFlag(txn, messageId, true);
|
||||
|
||||
// Retrieve the message headers
|
||||
Collection<MessageHeader> headers =
|
||||
db.getMessageHeaders(txn, groupId);
|
||||
Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId);
|
||||
Iterator<MessageHeader> it = headers.iterator();
|
||||
boolean messageFound = false, message1Found = false;
|
||||
// First header (order is undefined)
|
||||
@@ -1126,16 +961,14 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// The message should be unread by default
|
||||
assertFalse(db.getReadFlag(txn, messageId));
|
||||
// Marking the message read should return the old value
|
||||
assertFalse(db.setReadFlag(txn, messageId, true));
|
||||
assertTrue(db.setReadFlag(txn, messageId, true));
|
||||
// Mark the message read
|
||||
db.setReadFlag(txn, messageId, true);
|
||||
// The message should be read
|
||||
assertTrue(db.getReadFlag(txn, messageId));
|
||||
// Marking the message unread should return the old value
|
||||
assertTrue(db.setReadFlag(txn, messageId, false));
|
||||
assertFalse(db.setReadFlag(txn, messageId, false));
|
||||
// Unsubscribe from the group
|
||||
db.removeGroup(txn, groupId);
|
||||
// Mark the message unread
|
||||
db.setReadFlag(txn, messageId, false);
|
||||
// The message should be unread
|
||||
assertFalse(db.getReadFlag(txn, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
@@ -1167,7 +1000,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addMessage(txn, message2, false);
|
||||
|
||||
// Mark one of the messages in the first group read
|
||||
assertFalse(db.setReadFlag(txn, messageId, true));
|
||||
db.setReadFlag(txn, messageId, true);
|
||||
|
||||
// There should be one unread message in each group
|
||||
Map<GroupId, Integer> counts = db.getUnreadMessageCounts(txn);
|
||||
@@ -1179,11 +1012,11 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertNotNull(count);
|
||||
assertEquals(1, count.intValue());
|
||||
|
||||
// Mark the read message unread (it will now be false rather than null)
|
||||
assertTrue(db.setReadFlag(txn, messageId, false));
|
||||
// Mark the read message unread
|
||||
db.setReadFlag(txn, messageId, false);
|
||||
|
||||
// Mark the message in the second group read
|
||||
assertFalse(db.setReadFlag(txn, messageId2, true));
|
||||
db.setReadFlag(txn, messageId2, true);
|
||||
|
||||
// There should be two unread messages in the first group, none in
|
||||
// the second group
|
||||
|
||||
@@ -196,7 +196,7 @@ 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.getMaxMessagesForAck(length);
|
||||
int maxMessages = writer.getMaxMessagesForRequest(length);
|
||||
Collection<MessageId> acked = new ArrayList<MessageId>();
|
||||
for(int i = 0; i < maxMessages; i++)
|
||||
acked.add(new MessageId(TestUtils.getRandomId()));
|
||||
|
||||
Reference in New Issue
Block a user