RoundRobinLoadBalancer implements Router { public Target getTarget(Method method, Object[] args) { List<Member> memberList = members.get(); if (memberList.isEmpty()) { throw new NoMemberAvailableException( format("RoundRobinLoadBalancer: There are no real members in the cluster of Hazelcast instance [%s]", hazelcastInstance.getName())); } int count = counter.getAndIncrement(); if (count == Integer.MIN_VALUE) { count = 0; } else if (count < 0) { count = -count; } Member member = memberList.get(count % memberList.size()); if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, format("Next request is send to member '%s'", member)); } return new Target(member); } RoundRobinLoadBalancer(HazelcastInstance hazelcastInstance); int getMemberCount(); Target getTarget(Method method, Object[] args);  }
@Test(expected = NoMemberAvailableException.class) public void noMembersInTheCluster() throws Throwable { HazelcastInstance hazelcastInstance = TestUtils.newClientInstance(); Router lb = new RoundRobinLoadBalancer(hazelcastInstance); lb.getTarget(METHOD, ARGS); }
@Test public void singleMember() throws Throwable { HazelcastInstance instance = newNormalInstance(); Router loadBalancer = new RoundRobinLoadBalancer(instance); Member first = loadBalancer.getTarget(METHOD, ARGS).getMember(); Member second = loadBalancer.getTarget(METHOD, ARGS).getMember(); Member self = instance.getCluster().getLocalMember(); assertEquals(self, first); assertEquals(self, second); }