Clear presence only if the connection’s displacement listener is still present
This commit is contained in:
parent
407070c9fc
commit
8c7975d89a
|
@ -235,11 +235,12 @@ public class ClientPresenceManager extends RedisClusterPubSubAdapter<String, Str
|
||||||
|
|
||||||
public boolean clearPresence(final UUID accountUuid, final long deviceId, final DisplacedPresenceListener listener) {
|
public boolean clearPresence(final UUID accountUuid, final long deviceId, final DisplacedPresenceListener listener) {
|
||||||
final String presenceKey = getPresenceKey(accountUuid, deviceId);
|
final String presenceKey = getPresenceKey(accountUuid, deviceId);
|
||||||
if (!displacementListenersByPresenceKey.remove(presenceKey, listener)) {
|
if (displacementListenersByPresenceKey.remove(presenceKey, listener)) {
|
||||||
|
return clearPresence(presenceKey);
|
||||||
|
} else {
|
||||||
displacementListenerAlreadyRemovedCounter.increment();
|
displacementListenerAlreadyRemovedCounter.increment();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return clearPresence(presenceKey);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean clearPresence(final String presenceKey) {
|
private boolean clearPresence(final String presenceKey) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
|
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
|
||||||
|
@ -161,6 +162,8 @@ class ClientPresenceManagerTest {
|
||||||
assertFalse(clientPresenceManager.isPresent(accountUuid, deviceId));
|
assertFalse(clientPresenceManager.isPresent(accountUuid, deviceId));
|
||||||
|
|
||||||
clientPresenceManager.setPresent(accountUuid, deviceId, NO_OP);
|
clientPresenceManager.setPresent(accountUuid, deviceId, NO_OP);
|
||||||
|
assertFalse(clientPresenceManager.clearPresence(accountUuid, deviceId,
|
||||||
|
ignored -> fail("this listener should never be called")));
|
||||||
assertTrue(clientPresenceManager.clearPresence(accountUuid, deviceId, NO_OP));
|
assertTrue(clientPresenceManager.clearPresence(accountUuid, deviceId, NO_OP));
|
||||||
|
|
||||||
clientPresenceManager.setPresent(accountUuid, deviceId, NO_OP);
|
clientPresenceManager.setPresent(accountUuid, deviceId, NO_OP);
|
||||||
|
|
Loading…
Reference in New Issue