Example #1
0
    /** {@inheritDoc} */
    @Override
    public Map<? extends GridComputeJob, GridNode> map(List<GridNode> subgrid, String arg)
        throws GridException {
      assert locNodeId != null;

      if (log.isInfoEnabled()) {
        log.info("Mapping jobs [subgrid=" + subgrid + ", arg=" + arg + ']');
      }

      GridNode remoteNode = null;

      for (GridNode node : subgrid) {
        if (!node.id().equals(locNodeId)) {
          remoteNode = node;
        }
      }

      return Collections.singletonMap(
          new GridComputeJobAdapter(locNodeId) {
            /** */
            @GridLocalNodeIdResource private UUID nodeId;

            /** {@inheritDoc} */
            @SuppressWarnings("NakedNotify")
            @Override
            public Serializable execute() throws GridException {
              assert nodeId != null;

              if (!nodeId.equals(argument(0))) {
                try {
                  synchronized (mux) {
                    mux.notifyAll();
                  }

                  Thread.sleep(Integer.MAX_VALUE);
                } catch (InterruptedException e) {
                  throw new GridComputeExecutionRejectedException(
                      "Expected interruption during execution.", e);
                }
              } else {
                return "success";
              }

              throw new GridComputeExecutionRejectedException(
                  "Expected exception during execution.");
            }
          },
          remoteNode);
    }
  /** @throws Exception If failed. */
  public void testKeyMappingOnComputeNode() throws Exception {
    try {
      cache = true;

      for (int i = 0; i < 4; i++) {
        nearOnly = i == 0;

        startGrid(i);
      }

      cache = false;

      Grid compute = startGrid(4);

      for (int i = 0; i < 100; i++) {
        GridNode node = compute.mapKeyToNode(null, i);

        assertFalse("For key: " + i, node.id().equals(compute.localNode().id()));
        assertFalse("For key: " + i, node.id().equals(grid(0).localNode().id()));
      }
    } finally {
      stopAllGrids();
    }
  }