@Override public int getUserCount() { int userCount = 0; for (UserRegistrySnapshot registry : this.remoteRegistries.values()) { userCount += registry.getUserMap().size(); } userCount += this.localRegistry.getUserCount(); return userCount; }
@Test public void getUserFromLocalRegistry() throws Exception { 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.getUserCount()); assertSame(user, this.registry.getUser("joe")); }
@Test public void handleMessageFromOwnBroadcast() throws Exception { 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.getUserCount()); Message<?> message = this.converter.toMessage(this.multiServerRegistry.getLocalRegistryDto(), null); this.multiServerRegistry.addRemoteRegistryDto(message, this.converter, 20000); assertEquals(1, this.multiServerRegistry.getUserCount()); }
@Test public void handleMessage() throws Exception { TestSimpUser simpUser1 = new TestSimpUser("joe"); TestSimpUser simpUser2 = new TestSimpUser("jane"); simpUser1.addSessions(new TestSimpSession("123")); simpUser2.addSessions(new TestSimpSession("456")); 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); Message<?> message = this.converter.toMessage(remoteRegistry.getLocalRegistryDto(), null); this.handler.handleMessage(message); assertEquals(2, remoteRegistry.getUserCount()); assertNotNull(this.multiServerRegistry.getUser("joe")); assertNotNull(this.multiServerRegistry.getUser("jane")); }
@Override public int getUserCount() { int userCount = 0; for (UserRegistrySnapshot registry : this.remoteRegistries.values()) { userCount += registry.getUserMap().size(); } userCount += this.localRegistry.getUserCount(); return userCount; }
@Override public int getUserCount() { int userCount = 0; for (UserRegistrySnapshot registry : this.remoteRegistries.values()) { userCount += registry.getUserMap().size(); } userCount += this.localRegistry.getUserCount(); return userCount; }
@Override public int getUserCount() { int userCount = 0; for (UserRegistrySnapshot registry : this.remoteRegistries.values()) { userCount += registry.getUserMap().size(); } userCount += this.localRegistry.getUserCount(); return userCount; }