@Test public void testDeletesObsoleteUpdateWhenDelivered() throws Exception { Transaction txn = new Transaction(null, false); GroupId contactGroupId = new GroupId(getRandomId()); long timestamp = 123456789; Message message = getMessage(contactGroupId, timestamp); Metadata meta = new Metadata(); BdfDictionary metaDictionary = BdfDictionary.of( new BdfEntry("transportId", "foo"), new BdfEntry("version", 3), new BdfEntry("local", false) ); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); MessageId fooVersion4 = new MessageId(getRandomId()); messageMetadata.put(fooVersion4, BdfDictionary.of( new BdfEntry("transportId", "foo"), new BdfEntry("version", 4), new BdfEntry("local", false) )); context.checking(new Expectations() {{ oneOf(metadataParser).parse(meta); will(returnValue(metaDictionary)); oneOf(clientHelper).getMessageMetadataAsDictionary(txn, contactGroupId); will(returnValue(messageMetadata)); oneOf(db).deleteMessage(txn, message.getId()); oneOf(db).deleteMessageMetadata(txn, message.getId()); }}); TransportPropertyManagerImpl t = createInstance(); assertFalse(t.incomingMessage(txn, message, meta)); }
@Override public boolean incomingMessage(Transaction txn, Message m, Metadata meta) throws DbException, InvalidMessageException { try { BdfDictionary d = metadataParser.parse(meta); TransportId t = new TransportId(d.getString("transportId")); LatestUpdate latest = findLatest(txn, m.getGroupId(), t, false); if (latest != null) { if (d.getLong("version") > latest.version) { db.deleteMessage(txn, latest.messageId); db.deleteMessageMetadata(txn, latest.messageId); } else { db.deleteMessage(txn, m.getId()); db.deleteMessageMetadata(txn, m.getId()); } } } catch (FormatException e) { throw new InvalidMessageException(e); } return false; }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public boolean incomingMessage(Transaction txn, Message m, Metadata meta) throws DbException, InvalidMessageException { try { BdfDictionary d = metadataParser.parse(meta); TransportId t = new TransportId(d.getString("transportId")); LatestUpdate latest = findLatest(txn, m.getGroupId(), t, false); if (latest != null) { if (d.getLong("version") > latest.version) { db.deleteMessage(txn, latest.messageId); db.deleteMessageMetadata(txn, latest.messageId); } else { db.deleteMessage(txn, m.getId()); db.deleteMessageMetadata(txn, m.getId()); } } } catch (FormatException e) { throw new InvalidMessageException(e); } return false; } }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public boolean incomingMessage(Transaction txn, Message m, Metadata meta) throws DbException, InvalidMessageException { try { BdfDictionary d = metadataParser.parse(meta); TransportId t = new TransportId(d.getString("transportId")); LatestUpdate latest = findLatest(txn, m.getGroupId(), t, false); if (latest != null) { if (d.getLong("version") > latest.version) { db.deleteMessage(txn, latest.messageId); db.deleteMessageMetadata(txn, latest.messageId); } else { db.deleteMessage(txn, m.getId()); db.deleteMessageMetadata(txn, m.getId()); } } } catch (FormatException e) { throw new InvalidMessageException(e); } return false; } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public boolean incomingMessage(Transaction txn, Message m, Metadata meta) throws DbException, InvalidMessageException { try { BdfDictionary d = metadataParser.parse(meta); TransportId t = new TransportId(d.getString("transportId")); LatestUpdate latest = findLatest(txn, m.getGroupId(), t, false); if (latest != null) { if (d.getLong("version") > latest.version) { db.deleteMessage(txn, latest.messageId); db.deleteMessageMetadata(txn, latest.messageId); } else { db.deleteMessage(txn, m.getId()); db.deleteMessageMetadata(txn, m.getId()); } } } catch (FormatException e) { throw new InvalidMessageException(e); } return false; } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override void onClientVisibilityChanging(Transaction txn, Contact c,
			Visibility v); @Override boolean incomingMessage(Transaction txn, Message m, Metadata meta); @Override void addRemoteProperties(Transaction txn, ContactId c,
			Map<TransportId, TransportProperties> props); @Override Map<TransportId, TransportProperties> getLocalProperties(); @Override Map<TransportId, TransportProperties> getLocalProperties(
			Transaction txn); @Override TransportProperties getLocalProperties(TransportId t); @Override Map<ContactId, TransportProperties> getRemoteProperties(
			TransportId t); @Override TransportProperties getRemoteProperties(ContactId c, TransportId t); @Override void mergeLocalProperties(TransportId t, TransportProperties p); }
TransportPropertyManagerImpl implements TransportPropertyManager,
		Client, ContactHook, ClientVersioningHook, IncomingMessageHook { @Override public boolean incomingMessage(Transaction txn, Message m, Metadata meta) throws DbException, InvalidMessageException { try { BdfDictionary d = metadataParser.parse(meta); TransportId t = new TransportId(d.getString("transportId")); LatestUpdate latest = findLatest(txn, m.getGroupId(), t, false); if (latest != null) { if (d.getLong("version") > latest.version) { db.deleteMessage(txn, latest.messageId); db.deleteMessageMetadata(txn, latest.messageId); } else { db.deleteMessage(txn, m.getId()); db.deleteMessageMetadata(txn, m.getId()); } } } catch (FormatException e) { throw new InvalidMessageException(e); } return false; } @Inject  TransportPropertyManagerImpl(DatabaseComponent db,
			ClientHelper clientHelper,
			ClientVersioningManager clientVersioningManager,
			MetadataParser metadataParser,
			ContactGroupFactory contactGroupFactory, Clock clock); @Override void createLocalState(Transaction txn); @Override void addingContact(Transaction txn, Contact c); @Override void removingContact(Transaction txn, Contact c); @Override void onClientVisibilityChanging(Transaction txn, Contact c,
			Visibility v); @Override boolean incomingMessage(Transaction txn, Message m, Metadata meta); @Override void addRemoteProperties(Transaction txn, ContactId c,
			Map<TransportId, TransportProperties> props); @Override Map<TransportId, TransportProperties> getLocalProperties(); @Override Map<TransportId, TransportProperties> getLocalProperties(
			Transaction txn); @Override TransportProperties getLocalProperties(TransportId t); @Override Map<ContactId, TransportProperties> getRemoteProperties(
			TransportId t); @Override TransportProperties getRemoteProperties(ContactId c, TransportId t); @Override void mergeLocalProperties(TransportId t, TransportProperties p);  }