Moved the subscription and transport timestamps out of the contacts

table so it's not necessary to hold a write lock on the (heavily used)
contacts table to update them.
This commit is contained in:
akwizgran
2011-08-14 14:46:12 +02:00
parent 2c13e35dc4
commit 5e0aadd373
12 changed files with 122 additions and 63 deletions

View File

@@ -172,11 +172,11 @@ public class FileReadWriteTest extends TestCase {
Map<Group, Long> subs = new LinkedHashMap<Group, Long>();
subs.put(group, 0L);
subs.put(group1, 0L);
s.writeSubscriptionUpdate(subs, timestamp);
s.writeSubscriptions(subs, timestamp);
packetWriter.finishPacket();
TransportWriter t = protocolWriterFactory.createTransportWriter(out);
t.writeTransportUpdate(transports, timestamp);
t.writeTransports(transports, timestamp);
packetWriter.finishPacket();
out.flush();

View File

@@ -779,7 +779,7 @@ public abstract class DatabaseComponentTest extends TestCase {
oneOf(database).getVisibleSubscriptions(txn, contactId);
will(returnValue(Collections.singletonMap(group, 0L)));
// Add the subscriptions to the writer
oneOf(subscriptionWriter).writeSubscriptionUpdate(
oneOf(subscriptionWriter).writeSubscriptions(
with(Collections.singletonMap(group, 0L)),
with(any(long.class)));
}});
@@ -812,7 +812,7 @@ public abstract class DatabaseComponentTest extends TestCase {
oneOf(database).getTransports(txn);
will(returnValue(transports));
// Add the properties to the writer
oneOf(transportWriter).writeTransportUpdate(with(transports),
oneOf(transportWriter).writeTransports(with(transports),
with(any(long.class)));
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner);

View File

@@ -1200,15 +1200,12 @@ public class H2DatabaseTest extends TestCase {
// Add a contact and subscribe to a group
assertEquals(contactId, db.addContact(txn, transports, secret));
db.addSubscription(txn, group);
// The group should not be visible to the contact
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
// Make the group visible to the contact
db.setVisibility(txn, groupId, Collections.singleton(contactId));
assertEquals(Collections.singletonList(contactId),
db.getVisibility(txn, groupId));
// Make the group invisible again
db.setVisibility(txn, groupId, Collections.<ContactId>emptySet());
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
@@ -1225,10 +1222,8 @@ public class H2DatabaseTest extends TestCase {
// Add a contact
assertEquals(contactId, db.addContact(txn, transports, secret));
// Get the connection window for a new transport
ConnectionWindow w = db.getConnectionWindow(txn, contactId, 123);
// The connection window should exist and be in the initial state
assertNotNull(w);
assertEquals(0L, w.getCentre());
@@ -1245,19 +1240,15 @@ public class H2DatabaseTest extends TestCase {
// Add a contact
assertEquals(contactId, db.addContact(txn, transports, secret));
// Get the connection window for a new transport
ConnectionWindow w = db.getConnectionWindow(txn, contactId, 123);
// The connection window should exist and be in the initial state
assertNotNull(w);
assertEquals(0L, w.getCentre());
assertEquals(0, w.getBitmap());
// Update the connection window and store it
w.setSeen(5L);
db.setConnectionWindow(txn, contactId, 123, w);
// Check that the connection window was stored
w = db.getConnectionWindow(txn, contactId, 123);
assertNotNull(w);

View File

@@ -95,10 +95,10 @@ public class ProtocolReadWriteTest extends TestCase {
r.writeRequest(offerId, bitSet, 10);
SubscriptionWriter s = writerFactory.createSubscriptionWriter(out);
s.writeSubscriptionUpdate(subscriptions, timestamp);
s.writeSubscriptions(subscriptions, timestamp);
TransportWriter t = writerFactory.createTransportWriter(out);
t.writeTransportUpdate(transports, timestamp);
t.writeTransports(transports, timestamp);
// Read
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());