コード例 #1
0
  /**
   * @param it Iterator.
   * @param bound Value bound.
   * @throws Exception If failed.
   */
  private void testIteratorSerialization(Iterator<?> it, int bound) throws Exception {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();

    try (ObjectOutputStream out = new ObjectOutputStream(byteOut)) {
      out.writeObject(it);
    }

    byte[] bytes = byteOut.toByteArray();

    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));

    Iterator<?> it0 = (Iterator<?>) in.readObject();

    int cnt = 0;

    while (it0.hasNext()) {
      Object obj = it0.next();

      if (obj instanceof GridCacheEntry) checkEntry((GridCacheEntry<String, Integer>) obj, bound);
      else if (obj instanceof String) checkKey((String) obj);
      else if (obj instanceof Integer) checkValue((Integer) obj, bound);
      else assert false : "Wrong type.";

      cnt++;
    }

    assert cnt == bound;
  }
コード例 #2
0
  /** @throws Exception If failed. */
  public void testEmptyProjections() throws Exception {
    final GridClientCompute dflt = client.compute();

    Collection<? extends GridClientNode> nodes = dflt.nodes();

    assertEquals(NODES_CNT, nodes.size());

    Iterator<? extends GridClientNode> iter = nodes.iterator();

    final GridClientCompute singleNodePrj = dflt.projection(Collections.singletonList(iter.next()));

    final GridClientNode second = iter.next();

    final GridClientPredicate<GridClientNode> noneFilter =
        new GridClientPredicate<GridClientNode>() {
          @Override
          public boolean apply(GridClientNode node) {
            return false;
          }
        };

    final GridClientPredicate<GridClientNode> targetFilter =
        new GridClientPredicate<GridClientNode>() {
          @Override
          public boolean apply(GridClientNode node) {
            return node.nodeId().equals(second.nodeId());
          }
        };

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return dflt.projection(noneFilter).log(-1, -1);
          }
        },
        GridServerUnreachableException.class,
        null);

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return singleNodePrj.projection(second);
          }
        },
        GridClientException.class,
        null);

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return singleNodePrj.projection(targetFilter);
          }
        },
        GridClientException.class,
        null);
  }