mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Throw checked exception if concurrent attempts are made to remove a
contact.
This commit is contained in:
@@ -1229,6 +1229,7 @@ DatabaseCleaner.Callback {
|
|||||||
if(LOG.isLoggable(Level.FINE)) LOG.fine("Removing contact " + c);
|
if(LOG.isLoggable(Level.FINE)) LOG.fine("Removing contact " + c);
|
||||||
contactLock.writeLock().lock();
|
contactLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
|
if(!containsContact(c)) throw new NoSuchContactException();
|
||||||
messageLock.writeLock().lock();
|
messageLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
messageFlagLock.writeLock().lock();
|
messageFlagLock.writeLock().lock();
|
||||||
|
|||||||
@@ -183,6 +183,8 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
oneOf(database).setConnectionWindow(txn, contactId, remoteIndex,
|
oneOf(database).setConnectionWindow(txn, contactId, remoteIndex,
|
||||||
connectionWindow);
|
connectionWindow);
|
||||||
// removeContact(contactId)
|
// removeContact(contactId)
|
||||||
|
oneOf(database).containsContact(txn, contactId);
|
||||||
|
will(returnValue(true));
|
||||||
oneOf(database).removeContact(txn, contactId);
|
oneOf(database).removeContact(txn, contactId);
|
||||||
oneOf(listener).eventOccurred(with(any(ContactRemovedEvent.class)));
|
oneOf(listener).eventOccurred(with(any(ContactRemovedEvent.class)));
|
||||||
// close()
|
// close()
|
||||||
@@ -502,11 +504,11 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
context.mock(TransportUpdate.class);
|
context.mock(TransportUpdate.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Check whether the contact is still in the DB (which it's not)
|
// Check whether the contact is still in the DB (which it's not)
|
||||||
exactly(17).of(database).startTransaction();
|
exactly(20).of(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
exactly(17).of(database).containsContact(txn, contactId);
|
exactly(20).of(database).containsContact(txn, contactId);
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
exactly(17).of(database).commitTransaction(txn);
|
exactly(20).of(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||||
|
|
||||||
@@ -546,11 +548,21 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.getConnectionNumber(contactId, remoteIndex);
|
||||||
|
fail();
|
||||||
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.getConnectionWindow(contactId, remoteIndex);
|
db.getConnectionWindow(contactId, remoteIndex);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.getRemoteIndex(contactId, transportId);
|
||||||
|
fail();
|
||||||
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.getSharedSecret(contactId);
|
db.getSharedSecret(contactId);
|
||||||
fail();
|
fail();
|
||||||
@@ -586,6 +598,11 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
db.removeContact(contactId);
|
||||||
|
fail();
|
||||||
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.setConnectionWindow(contactId, remoteIndex, null);
|
db.setConnectionWindow(contactId, remoteIndex, null);
|
||||||
fail();
|
fail();
|
||||||
|
|||||||
Reference in New Issue
Block a user