Ejemplo n.º 1
0
  /**
   * Execute {@code HelloWorld} example on the grid.
   *
   * @param args Command line arguments, none required but if provided first one should point to the
   *     Spring XML configuration file. See {@code "examples/config/"} for configuration file
   *     examples.
   * @throws GridException If example execution failed.
   */
  public static void main(String[] args) throws GridException {
    if (args.length == 0) {
      G.start();
    } else {
      G.start(args[0]);
    }

    try {
      Grid grid = G.grid();

      // Execute Hello World task.
      GridTaskFuture<Integer> fut = grid.execute(GridHelloWorldTask.class, "Hello World");

      // Wait for task completion.
      int phraseLen = fut.get();

      X.println(">>>");
      X.println(">>> Finished executing Grid \"Hello World\" example with custom task.");
      X.println(">>> Total number of characters in the phrase is '" + phraseLen + "'.");
      X.println(">>> You should see print out of 'Hello' on one node and 'World' on another node.");
      X.println(">>> Check all nodes for output (this node is also part of the grid).");
      X.println(">>>");
    } finally {
      G.stop(true);
    }
  }
  /**
   * Executes {@link GridSegmentATask} and {@link GridSegmentBTask} tasks on the grid.
   *
   * @param args Command line arguments, none required or used.
   * @throws GridException If example execution failed.
   */
  public static void main(String[] args) throws GridException {
    AbstractApplicationContext ctx =
        new ClassPathXmlApplicationContext("org/gridgain/examples/multispi/master.xml");

    // Get configuration from Spring.
    GridConfiguration cfg = ctx.getBean("grid.cfg", GridConfiguration.class);

    G.start(cfg);

    try {
      Grid grid = G.grid();

      // Execute task on segment "A".
      GridTaskFuture<Integer> futA = grid.execute(GridSegmentATask.class, null);

      // Execute task on segment "B".
      GridTaskFuture<Integer> futB = grid.execute(GridSegmentBTask.class, null);

      // Wait for task completion.
      futA.get();
      futB.get();

      X.println(">>>");
      X.println(">>> Finished executing Grid \"Multiple Topology\" example with custom tasks.");
      X.println(
          ">>> You should see print out of 'Executing job on node that is from segment A.'"
              + "on node that has attribute \"segment=A\"");
      X.println(
          ">>> and 'Executing job on node that is from segment B.' on node that has "
              + "attribute \"segment=B\"");
      X.println(">>> Check all nodes for output (this node is not a part of the grid).");
      X.println(">>>");
    } finally {
      G.stop(true);
    }
  }
Ejemplo n.º 3
0
  /**
   * Runs all tests belonging to this test suite on the grid.
   *
   * @param result Test result collector.
   */
  @Override
  public void run(TestResult result) {
    if (isDisabled) {
      copy.run(result);
    } else {
      GridTestRouter router = createRouter();

      Grid grid = startGrid();

      try {
        List<GridTaskFuture<?>> futs = new ArrayList<GridTaskFuture<?>>(testCount());

        List<GridJunit3SerializableTest> tests =
            new ArrayList<GridJunit3SerializableTest>(testCount());

        for (int i = 0; i < testCount(); i++) {
          Test junit = testAt(i);

          GridJunit3SerializableTest test;

          if (junit instanceof TestSuite) {
            test = new GridJunit3SerializableTestSuite((TestSuite) junit);
          } else {
            assert junit instanceof TestCase
                : "Test must be either TestSuite or TestCase: " + junit;

            test = new GridJunit3SerializableTestCase((TestCase) junit);
          }

          tests.add(test);

          if (clsLdr == null) {
            clsLdr = U.detectClassLoader(junit.getClass());
          }

          futs.add(
              grid.execute(
                  new GridJunit3Task(junit.getClass(), clsLdr),
                  new GridJunit3Argument(router, test, locTests.contains(test.getName())),
                  timeout));
        }

        for (int i = 0; i < testCount(); i++) {
          GridTaskFuture<?> fut = futs.get(i);

          GridJunit3SerializableTest origTest = tests.get(i);

          try {
            GridJunit3SerializableTest resTest = (GridJunit3SerializableTest) fut.get();

            origTest.setResult(resTest);

            origTest.getTest().run(result);
          } catch (GridException e) {
            handleFail(result, origTest, e);
          }
        }
      } finally {
        stopGrid();
      }
    }
  }