Implement allocation-friendly method to get user count in SimpUserRegistry
SPR-14930
(cherry picked from commit a929e9c)
This commit is contained in:
committed by
Juergen Hoeller
parent
ac30bcb0eb
commit
8de100b116
@@ -61,9 +61,10 @@ public class MultiServerUserRegistryTests {
|
||||
SimpUser user = Mockito.mock(SimpUser.class);
|
||||
Set<SimpUser> users = Collections.singleton(user);
|
||||
when(this.localRegistry.getUsers()).thenReturn(users);
|
||||
when(this.localRegistry.getUserCount()).thenReturn(1);
|
||||
when(this.localRegistry.getUser("joe")).thenReturn(user);
|
||||
|
||||
assertEquals(1, this.registry.getUsers().size());
|
||||
assertEquals(1, this.registry.getUserCount());
|
||||
assertSame(user, this.registry.getUser("joe"));
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ public class MultiServerUserRegistryTests {
|
||||
this.registry.addRemoteRegistryDto(message, this.converter, 20000);
|
||||
|
||||
|
||||
assertEquals(1, this.registry.getUsers().size());
|
||||
assertEquals(1, this.registry.getUserCount());
|
||||
SimpUser user = this.registry.getUser("joe");
|
||||
assertNotNull(user);
|
||||
assertTrue(user.hasSessions());
|
||||
@@ -125,7 +126,7 @@ public class MultiServerUserRegistryTests {
|
||||
this.registry.addRemoteRegistryDto(message, this.converter, 20000);
|
||||
|
||||
|
||||
assertEquals(3, this.registry.getUsers().size());
|
||||
assertEquals(3, this.registry.getUserCount());
|
||||
Set<SimpSubscription> matches = this.registry.findSubscriptions(s -> s.getDestination().equals("/match"));
|
||||
assertEquals(2, matches.size());
|
||||
Iterator<SimpSubscription> iterator = matches.iterator();
|
||||
@@ -157,7 +158,7 @@ public class MultiServerUserRegistryTests {
|
||||
this.registry.addRemoteRegistryDto(message, this.converter, 20000);
|
||||
|
||||
|
||||
assertEquals(1, this.registry.getUsers().size());
|
||||
assertEquals(1, this.registry.getUserCount());
|
||||
SimpUser user = this.registry.getUsers().iterator().next();
|
||||
assertTrue(user.hasSessions());
|
||||
assertEquals(2, user.getSessions().size());
|
||||
@@ -187,9 +188,9 @@ public class MultiServerUserRegistryTests {
|
||||
this.registry.addRemoteRegistryDto(message, this.converter, -1);
|
||||
|
||||
|
||||
assertEquals(1, this.registry.getUsers().size());
|
||||
assertEquals(1, this.registry.getUserCount());
|
||||
this.registry.purgeExpiredRegistries();
|
||||
assertEquals(0, this.registry.getUsers().size());
|
||||
assertEquals(0, this.registry.getUserCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class UserRegistryMessageHandlerTests {
|
||||
|
||||
MultiServerUserRegistry remoteRegistry = new MultiServerUserRegistry(mock(SimpUserRegistry.class));
|
||||
remoteRegistry.addRemoteRegistryDto(message, this.converter, 20000);
|
||||
assertEquals(2, remoteRegistry.getUsers().size());
|
||||
assertEquals(2, remoteRegistry.getUserCount());
|
||||
assertNotNull(remoteRegistry.getUser("joe"));
|
||||
assertNotNull(remoteRegistry.getUser("jane"));
|
||||
}
|
||||
@@ -142,6 +142,7 @@ public class UserRegistryMessageHandlerTests {
|
||||
|
||||
HashSet<SimpUser> simpUsers = new HashSet<>(Arrays.asList(simpUser1, simpUser2));
|
||||
SimpUserRegistry remoteUserRegistry = mock(SimpUserRegistry.class);
|
||||
when(remoteUserRegistry.getUserCount()).thenReturn(2);
|
||||
when(remoteUserRegistry.getUsers()).thenReturn(simpUsers);
|
||||
|
||||
MultiServerUserRegistry remoteRegistry = new MultiServerUserRegistry(remoteUserRegistry);
|
||||
@@ -149,7 +150,7 @@ public class UserRegistryMessageHandlerTests {
|
||||
|
||||
this.handler.handleMessage(message);
|
||||
|
||||
assertEquals(2, remoteRegistry.getUsers().size());
|
||||
assertEquals(2, remoteRegistry.getUserCount());
|
||||
assertNotNull(this.multiServerRegistry.getUser("joe"));
|
||||
assertNotNull(this.multiServerRegistry.getUser("jane"));
|
||||
}
|
||||
@@ -159,13 +160,14 @@ public class UserRegistryMessageHandlerTests {
|
||||
|
||||
TestSimpUser simpUser = new TestSimpUser("joe");
|
||||
simpUser.addSessions(new TestSimpSession("123"));
|
||||
when(this.localRegistry.getUserCount()).thenReturn(1);
|
||||
when(this.localRegistry.getUsers()).thenReturn(Collections.singleton(simpUser));
|
||||
|
||||
assertEquals(1, this.multiServerRegistry.getUsers().size());
|
||||
assertEquals(1, this.multiServerRegistry.getUserCount());
|
||||
|
||||
Message<?> message = this.converter.toMessage(this.multiServerRegistry.getLocalRegistryDto(), null);
|
||||
this.multiServerRegistry.addRemoteRegistryDto(message, this.converter, 20000);
|
||||
assertEquals(1, this.multiServerRegistry.getUsers().size());
|
||||
assertEquals(1, this.multiServerRegistry.getUserCount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user