@Test public void getMostFreeServer() { ServerGroup bw = group("bw"); repository.addServer(bw, "bw-1"); repository.addServer(bw, "bw-2"); repository.addServer(bw, "bw-3"); repository.addServer(bw, "bw-4"); repository.addServer(bw, "bw-12"); incrementOnline(bw, "bw-1", 5); incrementOnline(bw, "bw-2", 3); incrementOnline(bw, "bw-3", 9); incrementOnline(bw, "bw-4", 2); incrementOnline(bw, "bw-12", 22); assertEquals("bw-4", repository.getMostFreeServer(bw)); List<String> mostFreeServers = repository.getMostFreeServers(bw, new FreeServersQueryOptions(6, 10)); assertEquals(new HashSet<>(Arrays.asList("bw-4", "bw-2", "bw-1")), new HashSet<>(mostFreeServers)); }
@Override public String getMostFreeServer(ServerGroup group) { return redisTransactions.runTransaction(jedis -> { return jedis.zrangeByScoreWithScores(this.redisSetName(group), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0, 1) .stream() .findFirst() .map(Tuple::getElement) .orElseThrow(NoFreeServersException::new); }); }
RedisOnlineIndexingRepository implements OnlineIndexingRepository { @Override public String getMostFreeServer(ServerGroup group) { return redisTransactions.runTransaction(jedis -> { return jedis.zrangeByScoreWithScores(this.redisSetName(group), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0, 1) .stream() .findFirst() .map(Tuple::getElement) .orElseThrow(NoFreeServersException::new); }); } }
RedisOnlineIndexingRepository implements OnlineIndexingRepository { @Override public String getMostFreeServer(ServerGroup group) { return redisTransactions.runTransaction(jedis -> { return jedis.zrangeByScoreWithScores(this.redisSetName(group), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0, 1) .stream() .findFirst() .map(Tuple::getElement) .orElseThrow(NoFreeServersException::new); }); }  }
RedisOnlineIndexingRepository implements OnlineIndexingRepository { @Override public String getMostFreeServer(ServerGroup group) { return redisTransactions.runTransaction(jedis -> { return jedis.zrangeByScoreWithScores(this.redisSetName(group), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0, 1) .stream() .findFirst() .map(Tuple::getElement) .orElseThrow(NoFreeServersException::new); }); }  @Override String getMostFreeServer(ServerGroup group); @Override List<String> getMostFreeServers(ServerGroup group, FreeServersQueryOptions options); @Override void removeServerData(ServerGroup serverGroup, String serverName); @Override void incrementOnline(ServerGroup serverGroup, String serverName); @Override void decrementOnline(ServerGroup serverGroup, String serverName); @Override void addServer(ServerGroup serverGroup, String serverName); }
RedisOnlineIndexingRepository implements OnlineIndexingRepository { @Override public String getMostFreeServer(ServerGroup group) { return redisTransactions.runTransaction(jedis -> { return jedis.zrangeByScoreWithScores(this.redisSetName(group), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0, 1) .stream() .findFirst() .map(Tuple::getElement) .orElseThrow(NoFreeServersException::new); }); }  @Override String getMostFreeServer(ServerGroup group); @Override List<String> getMostFreeServers(ServerGroup group, FreeServersQueryOptions options); @Override void removeServerData(ServerGroup serverGroup, String serverName); @Override void incrementOnline(ServerGroup serverGroup, String serverName); @Override void decrementOnline(ServerGroup serverGroup, String serverName); @Override void addServer(ServerGroup serverGroup, String serverName);  }