Don't broadcast MessageAddedEvent if message wasn't added.

Fixed a bug in SimplexMessagingIntegrationTest that should've caught
this.
This commit is contained in:
akwizgran
2014-07-04 12:07:18 +01:00
parent 96a9178b0b
commit 458c0ca285
3 changed files with 16 additions and 11 deletions

View File

@@ -1133,9 +1133,11 @@ DatabaseCleaner.Callback {
} finally { } finally {
lock.writeLock().unlock(); lock.writeLock().unlock();
} }
// FIXME: MessageAddedEvent should only be broadcast if msg is visible if(visible) {
if(visible) callListeners(new MessageToAckEvent(c)); if(!duplicate)
if(!duplicate) callListeners(new MessageAddedEvent(m.getGroup(), c)); callListeners(new MessageAddedEvent(m.getGroup(), c));
callListeners(new MessageToAckEvent(c));
}
} }
public void receiveOffer(ContactId c, Offer o) throws DbException { public void receiveOffer(ContactId c, Offer o) throws DbException {

View File

@@ -1077,8 +1077,8 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
} }
public boolean containsVisibleGroup(Connection txn, ContactId c, public boolean containsVisibleGroup(Connection txn, ContactId c, GroupId g)
GroupId g) throws DbException { throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {

View File

@@ -25,7 +25,7 @@ import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent; import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.messaging.Group; import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.api.messaging.Message; import org.briarproject.api.messaging.Message;
import org.briarproject.api.messaging.MessageFactory; import org.briarproject.api.messaging.MessageFactory;
import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.messaging.MessageVerifier;
@@ -59,7 +59,6 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
private final File testDir = TestUtils.getTestDirectory(); private final File testDir = TestUtils.getTestDirectory();
private final File aliceDir = new File(testDir, "alice"); private final File aliceDir = new File(testDir, "alice");
private final File bobDir = new File(testDir, "bob"); private final File bobDir = new File(testDir, "bob");
private final Group group;
private final TransportId transportId; private final TransportId transportId;
private final byte[] initialSecret; private final byte[] initialSecret;
private final long epoch; private final long epoch;
@@ -67,8 +66,6 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
private Injector alice, bob; private Injector alice, bob;
public SimplexMessagingIntegrationTest() throws Exception { public SimplexMessagingIntegrationTest() throws Exception {
GroupId groupId = new GroupId(TestUtils.getRandomId());
group = new Group(groupId, "Group", new byte[GROUP_SALT_LENGTH]);
transportId = new TransportId("id"); transportId = new TransportId("id");
// Create matching secrets for Alice and Bob // Create matching secrets for Alice and Bob
initialSecret = new byte[32]; initialSecret = new byte[32];
@@ -77,6 +74,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
epoch = System.currentTimeMillis() - 2 * rotationPeriod; epoch = System.currentTimeMillis() - 2 * rotationPeriod;
} }
@Override
@Before @Before
public void setUp() { public void setUp() {
testDir.mkdirs(); testDir.mkdirs();
@@ -88,7 +86,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
return Guice.createInjector(new TestDatabaseModule(dir), return Guice.createInjector(new TestDatabaseModule(dir),
new TestLifecycleModule(), new TestSystemModule(), new TestLifecycleModule(), new TestSystemModule(),
new CryptoModule(), new DatabaseModule(), new MessagingModule(), new CryptoModule(), new DatabaseModule(), new MessagingModule(),
new DuplexMessagingModule(), new SimplexMessagingModule(), new DuplexMessagingModule(), new SimplexMessagingModule(),
new SerialModule(), new TransportModule()); new SerialModule(), new TransportModule());
} }
@@ -122,6 +120,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
new byte[MAX_PUBLIC_KEY_LENGTH]); new byte[MAX_PUBLIC_KEY_LENGTH]);
ContactId contactId = db.addContact(bobAuthor, aliceId); ContactId contactId = db.addContact(bobAuthor, aliceId);
// Add the inbox group // Add the inbox group
GroupFactory gf = alice.getInstance(GroupFactory.class);
Group group = gf.createGroup("Group", new byte[GROUP_SALT_LENGTH]);
db.addGroup(group); db.addGroup(group);
db.setInboxGroup(contactId, group); db.setInboxGroup(contactId, group);
// Add the transport and the endpoint // Add the transport and the endpoint
@@ -181,6 +181,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
new byte[MAX_PUBLIC_KEY_LENGTH]); new byte[MAX_PUBLIC_KEY_LENGTH]);
ContactId contactId = db.addContact(aliceAuthor, bobId); ContactId contactId = db.addContact(aliceAuthor, bobId);
// Add the inbox group // Add the inbox group
GroupFactory gf = bob.getInstance(GroupFactory.class);
Group group = gf.createGroup("Group", new byte[GROUP_SALT_LENGTH]);
db.addGroup(group); db.addGroup(group);
db.setInboxGroup(contactId, group); db.setInboxGroup(contactId, group);
// Add the transport and the endpoint // Add the transport and the endpoint
@@ -228,6 +230,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
db.close(); db.close();
} }
@Override
@After @After
public void tearDown() { public void tearDown() {
TestUtils.deleteTestDirectory(testDir); TestUtils.deleteTestDirectory(testDir);
@@ -235,7 +238,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
private static class MessageListener implements EventListener { private static class MessageListener implements EventListener {
private boolean messageAdded = false; private volatile boolean messageAdded = false;
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if(e instanceof MessageAddedEvent) messageAdded = true; if(e instanceof MessageAddedEvent) messageAdded = true;