### Question:
ConsistentNodeRouter implements NodeRouter<N> { @Override public Optional<N> getNode(@NonNull String nodeId) { Objects.requireNonNull(nodeId); if (ring.isEmpty()) { return Optional.empty(); } Long nodeHash = ring.ceilingKey(hashFunction.hash(nodeId)); return Optional.ofNullable(ring.get(nodeHash)).map(VirtualNode::getPhysicalNode); } private  ConsistentNodeRouter(
      Collection<N> initialNodes, int replicaCount, HashFunction hashFunction); static NodeRouter<N> create(
      @Positive int replicaCount, HashFunction hashFunction); static NodeRouter<N> create(
      Collection<N> initialNodes, int replicaCount, HashFunction hashFunction); @Override Optional<N> getNode(@NonNull String nodeId); @Override void addNode(N node); @Override void removeNode(String nodeId);  }### Answer:
@Test void testEmpty() { NodeRouter<PhysicalNode> router = createConsistentRouter(); assertFalse(router.getNode("key").isPresent()); }
@Test void testConsistentAfterRemove() { NodeRouter<PhysicalNode> router = createConsistentRouter(); IntStream.range(0, 1000) .parallel() .mapToObj(index -> PhysicalNode.of("node" + index)) .forEach(router::addNode); Optional<PhysicalNode> node = router.getNode("key"); Random random = new Random(); IntStream.range(0, 250) .mapToObj(value -> "node" + random.nextInt(1000)) .filter(nodeId -> node.isPresent() && !nodeId.equals(node.get().getNodeId())) .forEach(router::removeNode); assertEquals(node, router.getNode("key")); }
@Test void testDifferentOrder() { NodeRouter<PhysicalNode> router1 = createConsistentRouter(); NodeRouter<PhysicalNode> router2 = createConsistentRouter(); IntStream.range(0, 1000) .parallel() .mapToObj(index -> PhysicalNode.of("node" + index)) .forEach(router1::addNode); StreamUtil.reverseRange(0, 1000) .parallel() .mapToObj(index -> PhysicalNode.of("node" + index)) .forEach(router2::addNode); assertEquals(router2.getNode("key"), router1.getNode("key")); }