1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 10:49:41 +02:00

Rework incoming packet listeners and Roster

Differentiate between asynchronous and synchronous ones. Asynchronous
are the ones where the invocation order may not be the same as the order
in which the stanzas arrived.

Since it's no longer guaranteed that when a unit test calls

processPacket(stanza)

the stanza will be completely processed when the call returns, it was
necessary to extend the unit tests (mostly Roster and ChatManager) with
a packet listener that waits for his invocation. Since we now also use
LinkedHashMaps as Map for the packet listeners (SMACK-531, SMACK-424),
adding a packet listeners as last also means that it will be called as
last. We exploit this behavior change now in the unit tests.

Rename 'recvListeners' to 'syncRecvListeners' in AbstractXMPPConnection.

Rename 'rosterInitialized' to 'loaded' in Roster.

Add Roster.isLoaded().

Reset 'loaded' to false in
Roster.setOfflinePresencesAndResetLoaded() (was setOfflinePresences()).

Fixes SMACK-583, SMACK-532, SMACK-424
This commit is contained in:
Florian Schmaus 2015-01-05 21:42:35 +01:00
parent e5c6c9bdf8
commit 717090d272
39 changed files with 443 additions and 306 deletions

View file

@ -107,7 +107,7 @@ public class PacketReaderTest extends SmackTestCase {
// Keep number of current listeners
int listenersSize = getConnection(0).getPacketListeners().size();
// Add a new listener
getConnection(0).addPacketListener(listener, new MockPacketFilter(true));
getConnection(0).addAsyncPacketListener(listener, new MockPacketFilter(true));
// Check that the listener was added
assertEquals("Listener was not added", listenersSize + 1,
getConnection(0).getPacketListeners().size());
@ -117,7 +117,7 @@ public class PacketReaderTest extends SmackTestCase {
getConnection(1).sendPacket(msg);
// Remove the listener
getConnection(0).removePacketListener(listener);
getConnection(0).removeAsyncPacketListener(listener);
// Check that the number of listeners is correct (i.e. the listener was removed)
assertEquals("Listener was not removed", listenersSize,
getConnection(0).getPacketListeners().size());
@ -134,7 +134,7 @@ public class PacketReaderTest extends SmackTestCase {
packet.setBody("aloha");
// User1 will always reply to user0 when a message is received
getConnection(1).addPacketListener(new PacketListener() {
getConnection(1).addAsyncPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
System.out.println(new Date() + " " + packet);
@ -203,8 +203,8 @@ public class PacketReaderTest extends SmackTestCase {
}
};
getConnection(0).addPacketListener(listener0, pf0);
getConnection(1).addPacketListener(listener1, pf1);
getConnection(0).addAsyncPacketListener(listener0, pf0);
getConnection(1).addAsyncPacketListener(listener1, pf1);
// Check that the listener was added
@ -225,8 +225,8 @@ public class PacketReaderTest extends SmackTestCase {
}
// Remove the listener
getConnection(0).removePacketListener(listener0);
getConnection(1).removePacketListener(listener1);
getConnection(0).removeAsyncPacketListener(listener0);
getConnection(1).removeAsyncPacketListener(listener1);
try {
Thread.sleep(300);