mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Replaced the Status enum with a seen flag and an expiry time.
This commit is contained in:
@@ -2,8 +2,6 @@ package net.sf.briar.db;
|
||||
|
||||
import static net.sf.briar.api.Rating.GOOD;
|
||||
import static net.sf.briar.api.Rating.UNRATED;
|
||||
import static net.sf.briar.db.Status.NEW;
|
||||
import static net.sf.briar.db.Status.SEEN;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -364,7 +362,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(true));
|
||||
oneOf(database).getContacts(txn);
|
||||
will(returnValue(Collections.singletonList(contactId)));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, NEW);
|
||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||
// The author is unrated and there are no sendable children
|
||||
oneOf(database).getRating(txn, authorId);
|
||||
will(returnValue(UNRATED));
|
||||
@@ -399,7 +397,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(true));
|
||||
oneOf(database).getContacts(txn);
|
||||
will(returnValue(Collections.singletonList(contactId)));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, NEW);
|
||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||
// The author is rated GOOD and there are two sendable children
|
||||
oneOf(database).getRating(txn, authorId);
|
||||
will(returnValue(GOOD));
|
||||
@@ -460,7 +458,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
// addLocalPrivateMessage(privateMessage, contactId)
|
||||
oneOf(database).addPrivateMessage(txn, privateMessage, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, NEW);
|
||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
@@ -698,7 +696,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).getRawMessage(txn, messageId1);
|
||||
will(returnValue(raw1));
|
||||
// Record the outstanding messages
|
||||
oneOf(database).addOutstandingMessages(txn, contactId, sendable);
|
||||
// FIXME: Calculate the expiry time
|
||||
oneOf(database).addOutstandingMessages(txn, contactId, sendable,
|
||||
Long.MAX_VALUE);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
@@ -734,8 +734,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).getRawMessageIfSendable(txn, contactId, messageId2);
|
||||
will(returnValue(null)); // Message is not sendable
|
||||
// Record the outstanding messages
|
||||
// FIXME: Calculate the expiry time
|
||||
oneOf(database).addOutstandingMessages(txn, contactId,
|
||||
Collections.singletonList(messageId1));
|
||||
Collections.singletonList(messageId1), Long.MAX_VALUE);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
@@ -922,7 +923,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
// The message is stored
|
||||
oneOf(database).addPrivateMessage(txn, privateMessage, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, SEEN);
|
||||
oneOf(database).addStatus(txn, contactId, messageId, true);
|
||||
// The message must be acked
|
||||
oneOf(database).addMessageToAck(txn, contactId, messageId);
|
||||
}});
|
||||
@@ -1011,7 +1012,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
// The message is stored, but it's a duplicate
|
||||
oneOf(database).addGroupMessage(txn, message);
|
||||
will(returnValue(false));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, SEEN);
|
||||
oneOf(database).addStatus(txn, contactId, messageId, true);
|
||||
// The message must be acked
|
||||
oneOf(database).addMessageToAck(txn, contactId, messageId);
|
||||
}});
|
||||
@@ -1043,8 +1044,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
// The message is stored, and it's not a duplicate
|
||||
oneOf(database).addGroupMessage(txn, message);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, SEEN);
|
||||
// Set the status to NEW for all other contacts (there are none)
|
||||
oneOf(database).addStatus(txn, contactId, messageId, true);
|
||||
// Set the status to seen = true for all other contacts (none)
|
||||
oneOf(database).getContacts(txn);
|
||||
will(returnValue(Collections.singletonList(contactId)));
|
||||
// Calculate the sendability - zero, so ancestors aren't updated
|
||||
@@ -1085,8 +1086,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
// The message is stored, and it's not a duplicate
|
||||
oneOf(database).addGroupMessage(txn, message);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, SEEN);
|
||||
// Set the status to NEW for all other contacts (there are none)
|
||||
oneOf(database).addStatus(txn, contactId, messageId, true);
|
||||
// Set the status to seen = true for all other contacts (none)
|
||||
oneOf(database).getContacts(txn);
|
||||
will(returnValue(Collections.singletonList(contactId)));
|
||||
// Calculate the sendability - ancestors are updated
|
||||
@@ -1214,7 +1215,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(true));
|
||||
oneOf(database).getContacts(txn);
|
||||
will(returnValue(Collections.singletonList(contactId)));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, NEW);
|
||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||
oneOf(database).getRating(txn, authorId);
|
||||
will(returnValue(UNRATED));
|
||||
oneOf(database).getNumberOfSendableChildren(txn, messageId);
|
||||
@@ -1250,7 +1251,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
// addLocalPrivateMessage(privateMessage, contactId)
|
||||
oneOf(database).addPrivateMessage(txn, privateMessage, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setStatus(txn, contactId, messageId, NEW);
|
||||
oneOf(database).addStatus(txn, contactId, messageId, false);
|
||||
// The message was added, so the listener should be called
|
||||
oneOf(listener).eventOccurred(with(any(MessageAddedEvent.class)));
|
||||
}});
|
||||
|
||||
@@ -3,9 +3,6 @@ package net.sf.briar.db;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static net.sf.briar.api.Rating.GOOD;
|
||||
import static net.sf.briar.api.Rating.UNRATED;
|
||||
import static net.sf.briar.db.Status.NEW;
|
||||
import static net.sf.briar.db.Status.SEEN;
|
||||
import static net.sf.briar.db.Status.SENT;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.File;
|
||||
@@ -29,6 +26,7 @@ import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.clock.SystemClock;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.api.db.MessageHeader;
|
||||
import net.sf.briar.api.messaging.AuthorId;
|
||||
@@ -224,7 +222,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendablePrivateMessagesMustHaveStatusNew()
|
||||
public void testSendablePrivateMessagesMustHaveSeenFlagFalse()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -239,25 +237,14 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Changing the status to NEW should make the message sendable
|
||||
db.setStatus(txn, contactId, messageId1, NEW);
|
||||
// Adding a status with seen = false should make the message sendable
|
||||
db.addStatus(txn, contactId, messageId1, false);
|
||||
assertTrue(db.hasSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId1, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Changing the status to SENT should make the message unsendable
|
||||
db.setStatus(txn, contactId, messageId1, SENT);
|
||||
assertFalse(db.hasSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Changing the status to SEEN should also make the message unsendable
|
||||
db.setStatus(txn, contactId, messageId1, SEEN);
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
@@ -271,7 +258,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
// Add a contact and store a private message
|
||||
assertEquals(contactId, db.addContact(txn));
|
||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||
db.setStatus(txn, contactId, messageId1, NEW);
|
||||
db.addStatus(txn, contactId, messageId1, false);
|
||||
|
||||
// The message is sendable, but too large to send
|
||||
assertTrue(db.hasSendableMessages(txn, contactId));
|
||||
@@ -302,7 +289,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The message should not be sendable
|
||||
assertFalse(db.hasSendableMessages(txn, contactId));
|
||||
@@ -329,7 +316,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendableGroupMessagesMustHaveStatusNew()
|
||||
public void testSendableGroupMessagesMustHaveSeenFlagFalse()
|
||||
throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -348,25 +335,20 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Changing the status to NEW should make the message sendable
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
// Adding a status with seen = false should make the message sendable
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
assertTrue(db.hasSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Changing the status to SENT should make the message unsendable
|
||||
db.setStatus(txn, contactId, messageId, SENT);
|
||||
// Changing the status to seen = true should make the message unsendable
|
||||
db.setStatusSeenIfVisible(txn, contactId, messageId);
|
||||
assertFalse(db.hasSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Changing the status to SEEN should also make the message unsendable
|
||||
db.setStatus(txn, contactId, messageId, SEEN);
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
@@ -382,7 +364,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setSendability(txn, messageId, 1);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The contact is not subscribed, so the message should not be sendable
|
||||
assertFalse(db.hasSendableMessages(txn, contactId));
|
||||
@@ -420,7 +402,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setSendability(txn, messageId, 1);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The message is sendable, but too large to send
|
||||
assertTrue(db.hasSendableMessages(txn, contactId));
|
||||
@@ -450,7 +432,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setSendability(txn, messageId, 1);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The subscription is not visible to the contact, so the message
|
||||
// should not be sendable
|
||||
@@ -534,7 +516,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setSendability(txn, messageId, 1);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// Retrieve the message from the database and mark it as sent
|
||||
Iterator<MessageId> it =
|
||||
@@ -542,9 +524,9 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
db.setStatus(txn, contactId, messageId, SENT);
|
||||
// FIXME: Calculate the expiry time
|
||||
db.addOutstandingMessages(txn, contactId,
|
||||
Collections.singletonList(messageId));
|
||||
Collections.singletonList(messageId), Long.MAX_VALUE);
|
||||
|
||||
// The message should no longer be sendable
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
@@ -913,11 +895,11 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
|
||||
// Set the sendability to > 0 and the status to SEEN
|
||||
// Set the sendability to > 0 and the status to seen = true
|
||||
db.setSendability(txn, messageId, 1);
|
||||
db.setStatus(txn, contactId, messageId, SEEN);
|
||||
db.addStatus(txn, contactId, messageId, true);
|
||||
|
||||
// The message is not sendable because its status is SEEN
|
||||
// The message is not sendable because its status is seen = true
|
||||
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
@@ -936,9 +918,9 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
|
||||
// Set the sendability to 0 and the status to NEW
|
||||
// Set the sendability to 0 and the status to seen = false
|
||||
db.setSendability(txn, messageId, 0);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The message is not sendable because its sendability is 0
|
||||
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
|
||||
@@ -961,9 +943,9 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setRetentionTime(txn, contactId, timestamp + 1, 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
|
||||
// Set the sendability to > 0 and the status to NEW
|
||||
// Set the sendability to > 0 and the status to seen = false
|
||||
db.setSendability(txn, messageId, 1);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The message is not sendable because it's too old
|
||||
assertNull(db.getRawMessageIfSendable(txn, contactId, messageId));
|
||||
@@ -984,9 +966,9 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
|
||||
// Set the sendability to > 0 and the status to NEW
|
||||
// Set the sendability to > 0 and the status to seen = false
|
||||
db.setSendability(txn, messageId, 1);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The message is sendable so it should be returned
|
||||
byte[] b = db.getRawMessageIfSendable(txn, contactId, messageId);
|
||||
@@ -1042,7 +1024,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(contactId, db.addContact(txn));
|
||||
db.addSubscription(txn, group);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// There's no contact subscription for the group
|
||||
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
@@ -1062,7 +1044,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addSubscription(txn, group);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
// The subscription is not visible
|
||||
assertFalse(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
@@ -1085,7 +1067,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addGroupMessage(txn, message);
|
||||
|
||||
// The message has already been seen by the contact
|
||||
db.setStatus(txn, contactId, messageId, SEEN);
|
||||
db.addStatus(txn, contactId, messageId, true);
|
||||
|
||||
assertTrue(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
|
||||
@@ -1107,7 +1089,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addGroupMessage(txn, message);
|
||||
|
||||
// The message has not been seen by the contact
|
||||
db.setStatus(txn, contactId, messageId, NEW);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
assertTrue(db.setStatusSeenIfVisible(txn, contactId, messageId));
|
||||
|
||||
@@ -1828,7 +1810,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
private Database<Connection> open(boolean resume) throws Exception {
|
||||
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
|
||||
MAX_SIZE));
|
||||
MAX_SIZE), new SystemClock());
|
||||
db.open(resume);
|
||||
return db;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user