package water.testframework.multinode;

import org.testng.annotations.BeforeSuite;
import water.H2O;

/**
 * Run cookbook examples.
 *
 * Runs all the cookbook examples.
 * Does not require any arguments.
 */
public class MultiNodeSetup {
  /**
   * Number of total H2O nodes to start.
   *
   * Note that all nodes are started within one process by this harness.
   * This approach is good for unit testing.  You would not want to deploy to production like this.
   *
   * Each H2O node is wrapped in it's own classloader.  The H2O nodes communicate with each other
   * using sockets even though they all live in the same process.  This gives very realistic test
   * behavior.
   */
  int _numNodes;

  public MultiNodeSetup(int numNodes) {
    _numNodes = numNodes;
  }

  /**
   * Main program.
   *
   * No args required.  Exit code 0 means all tests passed, nonzero otherwise.
   * Each H2O node needs two ports, n and n+1.
   */
  @BeforeSuite(groups={"multi-node"})
  public void setupCloud() {
    System.out.println("MultiNodeSetup creating " + _numNodes + " secondary nodes...");

    // Leader node, where the tests execute from.
    H2O.main(new String[]{});

    // Secondary nodes.
    for( int i = 0; i < _numNodes-1; i++ ) {
      String[] arr = new String[0];
      NodeContainer n = new NodeContainer(arr);
      n.start();
    }

    H2O.waitForCloudSize(_numNodes, 10000);

    System.out.println("Created");
  }
}

@@ -99,115 +99,8 @@
 O;%0A%0A
-/**%0A * Run cookbook examples.%0A *%0A * Runs all the cookbook examples.%0A * Does not require any arguments.%0A */%0A
 publ
@@ -294,17 +294,21 @@
 testing.
- 
+%0A   *
  You wou
@@ -413,17 +413,21 @@
 sloader.
- 
+%0A   *
  The H2O
@@ -460,21 +460,16 @@
 ch other
-%0A   *
  using s
@@ -486,16 +486,21 @@
 n though
+%0A   *
  they al
@@ -530,55 +530,8 @@
 ess.
-  This gives very realistic test%0A   * behavior.
 %0A   
@@ -637,151 +637,169 @@
   * 
-Main program.%0A   *%0A   * No args required.  Exit code 0 means all tests passed, nonzero otherwise.%0A   * Each H2O node needs two ports, n and n+1
+Start 1 leader node.%0A   * Start n-1 secondary nodes.%0A   *%0A   * The primary node blocks for cloud initialization and runs the test%0A   * program flow inside TestNG
 .%0A  

Update comments.