Simplify Database methods, move logic to DatabaseComponent.

This commit is contained in:
akwizgran
2011-10-19 15:54:56 +01:00
parent f18ddfe55f
commit 93cd31fa2d
9 changed files with 256 additions and 175 deletions

View File

@@ -148,8 +148,9 @@ public abstract class DatabaseComponentTest extends TestCase {
// unsubscribe(groupId)
oneOf(database).containsSubscription(txn, groupId);
will(returnValue(true));
oneOf(database).removeSubscription(txn, groupId);
oneOf(database).getVisibility(txn, groupId);
will(returnValue(Collections.<ContactId>emptyList()));
oneOf(database).removeSubscription(txn, groupId);
// unsubscribe(groupId) again
oneOf(database).containsSubscription(txn, groupId);
will(returnValue(false));
@@ -755,7 +756,7 @@ public abstract class DatabaseComponentTest extends TestCase {
// Get the visible subscriptions
oneOf(database).getVisibleSubscriptions(txn, contactId);
will(returnValue(Collections.singletonMap(group, 0L)));
oneOf(database).setSubscriptionTimestamp(with(txn), with(contactId),
oneOf(database).setSubscriptionsSentTimestamp(with(txn), with(contactId),
with(any(long.class)));
// Add the subscriptions to the writer
oneOf(subscriptionWriter).writeSubscriptions(
@@ -790,7 +791,7 @@ public abstract class DatabaseComponentTest extends TestCase {
// Get the local transport properties
oneOf(database).getLocalTransports(txn);
will(returnValue(transports));
oneOf(database).setTransportTimestamp(with(txn), with(contactId),
oneOf(database).setTransportsSentTimestamp(with(txn), with(contactId),
with(any(long.class)));
// Add the properties to the writer
oneOf(transportWriter).writeTransports(with(transports),
@@ -1283,8 +1284,11 @@ public abstract class DatabaseComponentTest extends TestCase {
context.checking(new Expectations() {{
oneOf(database).startTransaction();
will(returnValue(txn));
oneOf(database).getLocalProperties(txn, transportId);
will(returnValue(new TransportProperties()));
oneOf(database).setLocalProperties(txn, transportId, properties);
will(returnValue(true));
oneOf(database).setTransportsModifiedTimestamp(with(txn),
with(any(long.class)));
oneOf(database).commitTransaction(txn);
oneOf(listener).eventOccurred(with(any(
TransportsUpdatedEvent.class)));
@@ -1310,8 +1314,8 @@ public abstract class DatabaseComponentTest extends TestCase {
context.checking(new Expectations() {{
oneOf(database).startTransaction();
will(returnValue(txn));
oneOf(database).setLocalProperties(txn, transportId, properties);
will(returnValue(false));
oneOf(database).getLocalProperties(txn, transportId);
will(returnValue(properties));
oneOf(database).commitTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, cleaner);

View File

@@ -719,7 +719,7 @@ public class H2DatabaseTest extends TestCase {
@Test
public void testRetransmission() throws Exception {
BatchId[] ids = new BatchId[Database.RETRANSMIT_THRESHOLD + 5];
BatchId[] ids = new BatchId[DatabaseConstants.RETRANSMIT_THRESHOLD + 5];
for(int i = 0; i < ids.length; i++) {
ids[i] = new BatchId(TestUtils.getRandomId());
}
@@ -740,7 +740,7 @@ public class H2DatabaseTest extends TestCase {
// The contact acks the batches in reverse order. The first
// RETRANSMIT_THRESHOLD - 1 acks should not trigger any retransmissions
for(int i = 0; i < Database.RETRANSMIT_THRESHOLD - 1; i++) {
for(int i = 0; i < DatabaseConstants.RETRANSMIT_THRESHOLD - 1; i++) {
db.removeAckedBatch(txn, contactId, ids[ids.length - i - 1]);
Collection<BatchId> lost = db.getLostBatches(txn, contactId);
assertEquals(Collections.emptyList(), lost);
@@ -748,7 +748,7 @@ public class H2DatabaseTest extends TestCase {
// The next ack should trigger the retransmission of the remaining
// five outstanding batches
int index = ids.length - Database.RETRANSMIT_THRESHOLD;
int index = ids.length - DatabaseConstants.RETRANSMIT_THRESHOLD;
db.removeAckedBatch(txn, contactId, ids[index]);
Collection<BatchId> lost = db.getLostBatches(txn, contactId);
for(int i = 0; i < index; i++) {
@@ -761,7 +761,7 @@ public class H2DatabaseTest extends TestCase {
@Test
public void testNoRetransmission() throws Exception {
BatchId[] ids = new BatchId[Database.RETRANSMIT_THRESHOLD * 2];
BatchId[] ids = new BatchId[DatabaseConstants.RETRANSMIT_THRESHOLD * 2];
for(int i = 0; i < ids.length; i++) {
ids[i] = new BatchId(TestUtils.getRandomId());
}