/** {@inheritDoc} */
  @Override
  public Collection<ClusterNode> nodes(int p, AffinityTopologyVersion topVer) {
    Collection<ClusterNode> affNodes = cctx.affinity().nodes(p, topVer);

    lock.readLock().lock();

    try {
      assert node2part != null && node2part.valid()
          : "Invalid node-to-partitions map [topVer1="
              + topVer
              + ", topVer2="
              + this.topVer
              + ", cache="
              + cctx.name()
              + ", node2part="
              + node2part
              + ']';

      Collection<ClusterNode> nodes = null;

      Collection<UUID> nodeIds = part2node.get(p);

      if (!F.isEmpty(nodeIds)) {
        Collection<UUID> affIds = new HashSet<>(F.viewReadOnly(affNodes, F.node2id()));

        for (UUID nodeId : nodeIds) {
          if (!affIds.contains(nodeId) && hasState(p, nodeId, OWNING, MOVING, RENTING)) {
            ClusterNode n = cctx.discovery().node(nodeId);

            if (n != null
                && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) {
              if (nodes == null) {
                nodes = new ArrayList<>(affNodes.size() + 2);

                nodes.addAll(affNodes);
              }

              nodes.add(n);
            }
          }
        }
      }

      return nodes != null ? nodes : affNodes;
    } finally {
      lock.readLock().unlock();
    }
  }
  /** @throws Exception Thrown if test failed. */
  public void testA() throws Exception {
    Collection<Integer> set = new GridConcurrentWeakHashSet<>();

    Integer i = 1;

    assert set.add(i);
    assert !set.add(i);

    assert set.contains(i);

    assert set.size() == 1;

    Collection<Integer> c = F.asList(2, 3, 4, 5);

    assert set.addAll(c);
    assert !set.addAll(c);

    assert set.containsAll(c);

    assert set.size() == 1 + c.size();

    assert set.remove(i);
    assert !set.remove(i);

    assert !set.contains(i);

    assert set.size() == c.size();

    assert set.removeAll(c);
    assert !set.removeAll(c);

    assert !set.containsAll(c);

    assert set.isEmpty();

    Collection<Integer> c1 = Arrays.asList(1, 3, 5, 7, 9);

    int cnt = 0;

    for (Iterator<Integer> iter = set.iterator(); iter.hasNext(); cnt++) c1.contains(iter.next());

    assert set.size() == cnt;

    assert set.size() == set.toArray().length;

    assert set.addAll(c1);

    assert set.retainAll(c);
    assert !set.retainAll(c);

    Collection<Integer> c2 = F.retain(c1, true, c);

    assert set.containsAll(c2);
    assert !set.containsAll(c1);
    assert !set.containsAll(c);

    assert set.size() == c2.size();

    set.clear();

    assert set.isEmpty();

    try {
      set.iterator().next();

      assert false;
    } catch (NoSuchElementException ignored) {
      assert true;
    }

    try {
      set.add(null);

      assert false;
    } catch (NullPointerException ignored) {
      assert true;
    }
  }
  /** @throws Exception Thrown if test failed. */
  @SuppressWarnings({"UnusedAssignment"})
  public void testB() throws Exception {
    Collection<SampleBean> set = new GridConcurrentWeakHashSet<>();

    SampleBean bean1 = new SampleBean(1);

    assert set.add(bean1);
    assert !set.add(bean1);

    assert set.size() == 1;

    assert set.contains(bean1);

    bean1 = null;

    gc();

    assert set.isEmpty();

    Collection<SampleBean> c =
        F.asList(new SampleBean(1), new SampleBean(2), new SampleBean(3), new SampleBean(4));

    assert set.addAll(c);
    assert !set.addAll(c);

    assert set.size() == c.size();

    assert set.containsAll(c);

    c = null;

    gc();

    assert set.isEmpty();

    SampleBean b1 = new SampleBean(1);
    SampleBean b2 = new SampleBean(2);
    SampleBean b3 = new SampleBean(3);
    SampleBean b4 = new SampleBean(4);
    SampleBean b5 = new SampleBean(5);

    set.add(b1);
    set.add(b2);
    set.add(b3);
    set.add(b4);
    set.add(b5);

    Iterator iter = set.iterator();

    assert iter.hasNext();

    b2 = null;
    b3 = null;
    b4 = null;

    gc();

    int cnt = 0;

    while (iter.hasNext()) {
      info(iter.next().toString());

      cnt++;
    }

    assert set.size() == cnt;
  }