mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Broadcast event when auto delete timer is mirrored
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
package org.briarproject.briar.api.autodelete.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class AutoDeleteTimerMirroredEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
private final long newTimer;
|
||||||
|
|
||||||
|
public AutoDeleteTimerMirroredEvent(ContactId contactId, long newTimer) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
this.newTimer = newTimer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getNewTimer() {
|
||||||
|
return newTimer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupFactory;
|
import org.briarproject.bramble.api.sync.GroupFactory;
|
||||||
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
||||||
|
import org.briarproject.briar.api.autodelete.event.AutoDeleteTimerMirroredEvent;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -155,6 +156,7 @@ class AutoDeleteManagerImpl
|
|||||||
LOG.info("Mirroring auto-delete timer " + timer);
|
LOG.info("Mirroring auto-delete timer " + timer);
|
||||||
}
|
}
|
||||||
meta.put(GROUP_KEY_TIMER, timer);
|
meta.put(GROUP_KEY_TIMER, timer);
|
||||||
|
txn.attach(new AutoDeleteTimerMirroredEvent(c, timer));
|
||||||
} else if (timer != oldTimer) {
|
} else if (timer != oldTimer) {
|
||||||
// Their sent change trumps our unsent change. Mirror their
|
// Their sent change trumps our unsent change. Mirror their
|
||||||
// timer and clear the previous timer to drop our unsent change
|
// timer and clear the previous timer to drop our unsent change
|
||||||
@@ -164,6 +166,7 @@ class AutoDeleteManagerImpl
|
|||||||
}
|
}
|
||||||
meta.put(GROUP_KEY_TIMER, timer);
|
meta.put(GROUP_KEY_TIMER, timer);
|
||||||
meta.put(GROUP_KEY_PREVIOUS_TIMER, NO_PREVIOUS_TIMER);
|
meta.put(GROUP_KEY_PREVIOUS_TIMER, NO_PREVIOUS_TIMER);
|
||||||
|
txn.attach(new AutoDeleteTimerMirroredEvent(c, timer));
|
||||||
}
|
}
|
||||||
// Always update the timestamp
|
// Always update the timestamp
|
||||||
meta.put(GROUP_KEY_TIMESTAMP, timestamp);
|
meta.put(GROUP_KEY_TIMESTAMP, timestamp);
|
||||||
|
|||||||
@@ -5,11 +5,15 @@ import org.briarproject.bramble.api.client.ContactGroupFactory;
|
|||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.bramble.api.data.BdfEntry;
|
import org.briarproject.bramble.api.data.BdfEntry;
|
||||||
|
import org.briarproject.bramble.api.db.CommitAction;
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
|
import org.briarproject.bramble.api.db.EventAction;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupFactory;
|
import org.briarproject.bramble.api.sync.GroupFactory;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
|
import org.briarproject.briar.api.autodelete.event.AutoDeleteTimerMirroredEvent;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -27,6 +31,7 @@ import static org.briarproject.briar.autodelete.AutoDeleteConstants.GROUP_KEY_TI
|
|||||||
import static org.briarproject.briar.autodelete.AutoDeleteConstants.GROUP_KEY_TIMESTAMP;
|
import static org.briarproject.briar.autodelete.AutoDeleteConstants.GROUP_KEY_TIMESTAMP;
|
||||||
import static org.briarproject.briar.autodelete.AutoDeleteConstants.NO_PREVIOUS_TIMER;
|
import static org.briarproject.briar.autodelete.AutoDeleteConstants.NO_PREVIOUS_TIMER;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@SuppressWarnings("UnnecessaryLocalVariable") // Using them for readability
|
@SuppressWarnings("UnnecessaryLocalVariable") // Using them for readability
|
||||||
public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
|
public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
|
||||||
@@ -241,6 +246,9 @@ public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
autoDeleteManager.receiveAutoDeleteTimer(txn, contact.getId(),
|
autoDeleteManager.receiveAutoDeleteTimer(txn, contact.getId(),
|
||||||
remoteTimer, remoteTimestamp);
|
remoteTimer, remoteTimestamp);
|
||||||
|
|
||||||
|
// no events broadcast
|
||||||
|
assertTrue(txn.getActions().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -270,6 +278,9 @@ public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
autoDeleteManager.receiveAutoDeleteTimer(txn, contact.getId(),
|
autoDeleteManager.receiveAutoDeleteTimer(txn, contact.getId(),
|
||||||
remoteTimer, remoteTimestamp);
|
remoteTimer, remoteTimestamp);
|
||||||
|
|
||||||
|
// assert that event is broadcast with new timer
|
||||||
|
assertEvent(txn, remoteTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -299,6 +310,9 @@ public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
autoDeleteManager.receiveAutoDeleteTimer(txn, contact.getId(),
|
autoDeleteManager.receiveAutoDeleteTimer(txn, contact.getId(),
|
||||||
remoteTimer, remoteTimestamp);
|
remoteTimer, remoteTimestamp);
|
||||||
|
|
||||||
|
// no events broadcast
|
||||||
|
assertTrue(txn.getActions().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -332,6 +346,9 @@ public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
autoDeleteManager.receiveAutoDeleteTimer(txn, contact.getId(),
|
autoDeleteManager.receiveAutoDeleteTimer(txn, contact.getId(),
|
||||||
newRemoteTimer, remoteTimestamp);
|
newRemoteTimer, remoteTimestamp);
|
||||||
|
|
||||||
|
// assert that event is broadcast with new timer
|
||||||
|
assertEvent(txn, newRemoteTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectGetContact(Transaction txn) throws Exception {
|
private void expectGetContact(Transaction txn) throws Exception {
|
||||||
@@ -348,4 +365,15 @@ public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertEvent(Transaction txn, long timer) {
|
||||||
|
assertEquals(1, txn.getActions().size());
|
||||||
|
CommitAction action = txn.getActions().get(0);
|
||||||
|
assertTrue(action instanceof EventAction);
|
||||||
|
Event event = ((EventAction) action).getEvent();
|
||||||
|
assertTrue(event instanceof AutoDeleteTimerMirroredEvent);
|
||||||
|
AutoDeleteTimerMirroredEvent e = (AutoDeleteTimerMirroredEvent) event;
|
||||||
|
assertEquals(contact.getId(), e.getContactId());
|
||||||
|
assertEquals(timer, e.getNewTimer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user