@Test public void testUpdateMembers() throws Exception { HazelcastClient client = mock(HazelcastClient.class); Cluster cluster = mock(Cluster.class); when(client.getCluster()).thenReturn(cluster); Set<Member> members = new HashSet<Member>(); Member member1 = mock(Member.class); Member member2 = mock(Member.class); Member member3 = mock(Member.class); InetSocketAddress inetSocketAddress1 = new InetSocketAddress("localhost", 9701); InetSocketAddress inetSocketAddress2 = new InetSocketAddress("localhost", 9702); InetSocketAddress inetSocketAddress3 = new InetSocketAddress("localhost", 9703); when(member1.getInetSocketAddress()).thenReturn(inetSocketAddress1); when(member2.getInetSocketAddress()).thenReturn(inetSocketAddress2); when(member3.getInetSocketAddress()).thenReturn(inetSocketAddress3); members.add(member1); members.add(member2); members.add(member3); when(cluster.getMembers()).thenReturn(members); InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 5701); final Connection connection = mock(Connection.class); final List<LifecycleState> lifecycleEvents = new ArrayList<LifecycleState>(); final LifecycleServiceClientImpl lifecycleService = createLifecycleServiceClientImpl(client, lifecycleEvents); ClientConfig clientConfig = new ClientConfig(); clientConfig.setCredentials(credentials).addInetSocketAddress(inetSocketAddress).setConnectionTimeout(60000); ConnectionManager connectionManager = new ConnectionManager(client, clientConfig, lifecycleService) { protected Connection getNextConnection() { return connection; } }; ClientBinder binder = mock(ClientBinder.class); connectionManager.setBinder(binder); connectionManager.updateMembers(); assertTrue(connectionManager.getClusterMembers().contains(inetSocketAddress1)); assertTrue(connectionManager.getClusterMembers().contains(inetSocketAddress2)); assertTrue(connectionManager.getClusterMembers().contains(inetSocketAddress3)); assertFalse(connectionManager.getClusterMembers().contains(inetSocketAddress)); assertEquals(3, connectionManager.getClusterMembers().size()); assertArrayEquals(new Object[0], lifecycleEvents.toArray()); }
public void updateMembers() { Set<Member> members = client.getCluster().getMembers(); clusterMembers.clear(); for (Member member : members) { InetSocketAddress address = member.getInetSocketAddress(); Collection<InetSocketAddress> addresses = AddressHelper.getPossibleSocketAddresses(address.getAddress(), address.getPort()); clusterMembers.addAll(addresses); } }
ConnectionManager implements MembershipListener { public void updateMembers() { Set<Member> members = client.getCluster().getMembers(); clusterMembers.clear(); for (Member member : members) { InetSocketAddress address = member.getInetSocketAddress(); Collection<InetSocketAddress> addresses = AddressHelper.getPossibleSocketAddresses(address.getAddress(), address.getPort()); clusterMembers.addAll(addresses); } } }
ConnectionManager implements MembershipListener { public void updateMembers() { Set<Member> members = client.getCluster().getMembers(); clusterMembers.clear(); for (Member member : members) { InetSocketAddress address = member.getInetSocketAddress(); Collection<InetSocketAddress> addresses = AddressHelper.getPossibleSocketAddresses(address.getAddress(), address.getPort()); clusterMembers.addAll(addresses); } } ConnectionManager(HazelcastClient client, ClientConfig config, LifecycleServiceClientImpl lifecycleService); }
ConnectionManager implements MembershipListener { public void updateMembers() { Set<Member> members = client.getCluster().getMembers(); clusterMembers.clear(); for (Member member : members) { InetSocketAddress address = member.getInetSocketAddress(); Collection<InetSocketAddress> addresses = AddressHelper.getPossibleSocketAddresses(address.getAddress(), address.getPort()); clusterMembers.addAll(addresses); } } ConnectionManager(HazelcastClient client, ClientConfig config, LifecycleServiceClientImpl lifecycleService); Connection getInitConnection(); Connection lookForLiveConnection(); Connection getConnection(); void destroyConnection(final Connection connection); void memberAdded(MembershipEvent membershipEvent); void memberRemoved(MembershipEvent membershipEvent); void updateMembers(); boolean shouldExecuteOnDisconnect(Connection connection); void setBinder(ClientBinder binder); void shutdown(); }
ConnectionManager implements MembershipListener { public void updateMembers() { Set<Member> members = client.getCluster().getMembers(); clusterMembers.clear(); for (Member member : members) { InetSocketAddress address = member.getInetSocketAddress(); Collection<InetSocketAddress> addresses = AddressHelper.getPossibleSocketAddresses(address.getAddress(), address.getPort()); clusterMembers.addAll(addresses); } } ConnectionManager(HazelcastClient client, ClientConfig config, LifecycleServiceClientImpl lifecycleService); Connection getInitConnection(); Connection lookForLiveConnection(); Connection getConnection(); void destroyConnection(final Connection connection); void memberAdded(MembershipEvent membershipEvent); void memberRemoved(MembershipEvent membershipEvent); void updateMembers(); boolean shouldExecuteOnDisconnect(Connection connection); void setBinder(ClientBinder binder); void shutdown();  }