mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Simplify Database methods, move logic to DatabaseComponent.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.sf.briar.plugins;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -20,14 +19,11 @@ public class PluginManagerImplTest extends TestCase {
|
||||
public void testStartAndStop() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Map<?, ?> localTransports = context.mock(Map.class);
|
||||
final ConnectionDispatcher dispatcher =
|
||||
context.mock(ConnectionDispatcher.class);
|
||||
final UiCallback uiCallback = context.mock(UiCallback.class);
|
||||
context.checking(new Expectations() {{
|
||||
allowing(db).getLocalTransports();
|
||||
will(returnValue(localTransports));
|
||||
allowing(localTransports).get(with(any(TransportId.class)));
|
||||
allowing(db).getLocalProperties(with(any(TransportId.class)));
|
||||
will(returnValue(new TransportProperties()));
|
||||
allowing(db).getRemoteProperties(with(any(TransportId.class)));
|
||||
will(returnValue(new TransportProperties()));
|
||||
|
||||
Reference in New Issue
Block a user