Search in sources :

Example 1 with TJTracker

use of org.goldenorb.zookeeper.TJTracker in project goldenorb by jzachr.

the class TestJobManager method jobManagerTest.

/**
 * 
 */
@Test
public void jobManagerTest() throws IOException, InterruptedException, OrbZKFailure {
    zk = ZookeeperUtils.connect("localhost:21810");
    ZookeeperUtils.tryToCreateNode(zk, "/GoldenOrb");
    ZookeeperUtils.tryToCreateNode(zk, "/GoldenOrb/OrbCluster");
    //everyone join?
    CountDownLatch joinLeaderGroup = new CountDownLatch(NUM_OF_MEMBERS);
    //everyone ready to exit?
    CountDownLatch exit = new CountDownLatch(NUM_OF_MEMBERS);
    CountDownLatch jobCreated = new CountDownLatch(1);
    CountDownLatch newLeader = new CountDownLatch(1);
    OrbConfiguration orbConf = new OrbConfiguration();
    orbConf.setOrbClusterName("OrbCluster");
    orbConf.setJobHeartbeatTimeout(1000);
    orbConf.setMaximumJobTries(3);
    System.out.println(orbConf.getJobHeartbeatTimeout());
    // Create all of the test Trackers
    for (int i = 0; i < NUM_OF_MEMBERS; i++) {
        TJTracker tracker = new TJTracker(zk, joinLeaderGroup, exit, orbConf, i, "/GoldenOrb/OrbCluster");
        trackers.add(tracker);
        threads.add(new Thread(tracker));
        threads.get(i).start();
    }
    joinLeaderGroup.await();
    orbConf.setOrbZooKeeperQuorum("localhost:21810");
    orbConf.set("fs.default.name", "hdfs://localhost:" + cluster.getNameNodePort());
    orbConf.addFileToDistribute("src/test/resources/distributeTest1.txt");
    orbConf.addFileToDistribute("src/test/resources/HelloWorld.jar");
    String path1 = runJob(orbConf);
    String path2 = runJob(orbConf);
    System.out.println(path1 + " " + path2);
    new Thread(new HeartbeatUpdater(getJobInProgressPath(path1))).start();
    new Thread(new HeartbeatUpdater(getJobInProgressPath(path2))).start();
    jobCreated.await(2, TimeUnit.SECONDS);
    int leader = 0;
    for (int i = 0; i < NUM_OF_MEMBERS; i++) {
        if (trackers.get(i).isLeader()) {
            leader = i;
        }
    }
    trackers.get(leader).leave();
    newLeader.await(5, TimeUnit.SECONDS);
    //exit and shutdown
    for (int i = 0; i < NUM_OF_MEMBERS; i++) {
        trackers.get(i).leave();
    }
    exit.await();
    ZookeeperUtils.recursiveDelete(zk, "/GoldenOrb");
    ZookeeperUtils.deleteNodeIfEmpty(zk, "/GoldenOrb");
}
Also used : OrbConfiguration(org.goldenorb.conf.OrbConfiguration) TJTracker(org.goldenorb.zookeeper.TJTracker) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 OrbConfiguration (org.goldenorb.conf.OrbConfiguration)1 TJTracker (org.goldenorb.zookeeper.TJTracker)1 Test (org.junit.Test)1