From 4d23e14d89823c0c5c504828b9067e839d18710a Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Wed, 19 Oct 2011 16:41:32 +0100 Subject: [PATCH] Unit tests for subscription and transport timestamps. --- test/net/sf/briar/db/H2DatabaseTest.java | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/net/sf/briar/db/H2DatabaseTest.java b/test/net/sf/briar/db/H2DatabaseTest.java index 64b2bce7b0..f293677ef6 100644 --- a/test/net/sf/briar/db/H2DatabaseTest.java +++ b/test/net/sf/briar/db/H2DatabaseTest.java @@ -1536,8 +1536,8 @@ public class H2DatabaseTest extends TestCase { // A message with a private parent should return null MessageId childId = new MessageId(TestUtils.getRandomId()); - Message child = new TestMessage(childId, privateMessageId, groupId, null, - timestamp, raw); + Message child = new TestMessage(childId, privateMessageId, groupId, + null, timestamp, raw); db.addGroupMessage(txn, child); db.addPrivateMessage(txn, privateMessage, contactId); assertTrue(db.containsMessage(txn, childId)); @@ -1574,6 +1574,36 @@ public class H2DatabaseTest extends TestCase { db.close(); } + @Test + public void testTimestamps() throws Exception { + Database<Connection> db = open(false); + Connection txn = db.startTransaction(); + + // Add a contact + assertEquals(contactId, db.addContact(txn, transports, secret)); + + // The subscription and transport timestamps should be initialised to 0 + assertEquals(0L, db.getSubscriptionsModified(txn, contactId)); + assertEquals(0L, db.getSubscriptionsSent(txn, contactId)); + assertEquals(0L, db.getTransportsModified(txn)); + assertEquals(0L, db.getTransportsSent(txn, contactId)); + + // Update the timestamps + db.setSubscriptionsModified(txn, Collections.singleton(contactId), 1L); + db.setSubscriptionsSent(txn, contactId, 2L); + db.setTransportsModified(txn, 3L); + db.setTransportsSent(txn, contactId, 4L); + + // Check that the updated values were stored + assertEquals(1L, db.getSubscriptionsModified(txn, contactId)); + assertEquals(2L, db.getSubscriptionsSent(txn, contactId)); + assertEquals(3L, db.getTransportsModified(txn)); + assertEquals(4L, db.getTransportsSent(txn, contactId)); + + db.commitTransaction(txn); + db.close(); + } + @Test public void testExceptionHandling() throws Exception { Database<Connection> db = open(false); -- GitLab