incubator-giraph-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ach...@apache.org
Subject svn commit: r1245205 [18/18] - in /incubator/giraph/trunk: ./ src/main/java/org/apache/giraph/ src/main/java/org/apache/giraph/benchmark/ src/main/java/org/apache/giraph/bsp/ src/main/java/org/apache/giraph/comm/ src/main/java/org/apache/giraph/example...
Date Thu, 16 Feb 2012 22:12:36 GMT
Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java?rev=1245205&r1=1245204&r2=1245205&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java Thu Feb 16 22:12:31 2012
@@ -63,340 +63,340 @@ import java.util.List;
  * Unit test for many simple BSP applications.
  */
 public class TestBspBasic extends BspCase {
-    /**
-     * Create the test case
-     *
-     * @param testName name of the test case
-     */
-    public TestBspBasic(String testName) {
-        super(testName);
-    }
-
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite() {
-        return new TestSuite(TestBspBasic.class);
-    }
-
-    /**
-     * Just instantiate the vertex (all functions are implemented) and the
-     * VertexInputFormat using reflection.
-     *
-     * @throws IllegalAccessException
-     * @throws InstantiationException
-     * @throws InterruptedException
-     * @throws IOException
-     * @throws InvocationTargetException
-     * @throws IllegalArgumentException
-     * @throws NoSuchMethodException
-     * @throws SecurityException
-     */
-    public void testInstantiateVertex()
-            throws InstantiationException, IllegalAccessException,
-            IOException, InterruptedException, IllegalArgumentException,
-        InvocationTargetException, SecurityException, NoSuchMethodException {
-        System.out.println("testInstantiateVertex: java.class.path=" +
-                           System.getProperty("java.class.path"));
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        job.setVertexClass(SimpleSuperstepVertex.class);
-        job.setVertexInputFormatClass(
-            SimpleSuperstepVertex.SimpleSuperstepVertexInputFormat.class);
-        GraphState<LongWritable, IntWritable, FloatWritable, IntWritable> gs =
-            new GraphState<LongWritable, IntWritable,
-                           FloatWritable, IntWritable>();
-        BasicVertex<LongWritable, IntWritable, FloatWritable, IntWritable> vertex =
-            BspUtils.createVertex(job.getConfiguration());
-        vertex.initialize(null, null, null, null);
-        System.out.println("testInstantiateVertex: Got vertex " + vertex +
-                           ", graphState" + gs);
-        VertexInputFormat<LongWritable, IntWritable, FloatWritable, IntWritable>
-            inputFormat = BspUtils.createVertexInputFormat(job.getConfiguration());
-        List<InputSplit> splitArray =
-            inputFormat.getSplits(
-                new JobContext(new Configuration(), new JobID()), 1);
-        ByteArrayOutputStream byteArrayOutputStream =
-            new ByteArrayOutputStream();
-        DataOutputStream outputStream =
-            new DataOutputStream(byteArrayOutputStream);
-        ((Writable) splitArray.get(0)).write(outputStream);
-        System.out.println("testInstantiateVertex: Example output split = " +
-                           byteArrayOutputStream.toString());
-    }
-
-    /**
-     * Do some checks for local job runner.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testLocalJobRunnerConfig()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        if (getJobTracker() != null) {
-            System.out.println("testLocalJobRunnerConfig: Skipping for " +
-                               "non-local");
-            return;
-        }
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setWorkerConfiguration(5, 5, 100.0f);
-        job.getConfiguration().setBoolean(GiraphJob.SPLIT_MASTER_WORKER, true);
-        job.setVertexClass(SimpleSuperstepVertex.class);
-        job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
+  /**
+   * Create the test case
+   *
+   * @param testName name of the test case
+   */
+  public TestBspBasic(String testName) {
+    super(testName);
+  }
+
+  /**
+   * @return the suite of tests being tested
+   */
+  public static Test suite() {
+    return new TestSuite(TestBspBasic.class);
+  }
+
+  /**
+   * Just instantiate the vertex (all functions are implemented) and the
+   * VertexInputFormat using reflection.
+   *
+   * @throws IllegalAccessException
+   * @throws InstantiationException
+   * @throws InterruptedException
+   * @throws IOException
+   * @throws InvocationTargetException
+   * @throws IllegalArgumentException
+   * @throws NoSuchMethodException
+   * @throws SecurityException
+   */
+  public void testInstantiateVertex()
+      throws InstantiationException, IllegalAccessException,
+      IOException, InterruptedException, IllegalArgumentException,
+      InvocationTargetException, SecurityException, NoSuchMethodException {
+    System.out.println("testInstantiateVertex: java.class.path=" +
+        System.getProperty("java.class.path"));
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    job.setVertexClass(SimpleSuperstepVertex.class);
+    job.setVertexInputFormatClass(
+        SimpleSuperstepVertex.SimpleSuperstepVertexInputFormat.class);
+    GraphState<LongWritable, IntWritable, FloatWritable, IntWritable> gs =
+        new GraphState<LongWritable, IntWritable,
+        FloatWritable, IntWritable>();
+    BasicVertex<LongWritable, IntWritable, FloatWritable, IntWritable> vertex =
+        BspUtils.createVertex(job.getConfiguration());
+    vertex.initialize(null, null, null, null);
+    System.out.println("testInstantiateVertex: Got vertex " + vertex +
+        ", graphState" + gs);
+    VertexInputFormat<LongWritable, IntWritable, FloatWritable, IntWritable>
+    inputFormat = BspUtils.createVertexInputFormat(job.getConfiguration());
+    List<InputSplit> splitArray =
+        inputFormat.getSplits(
+            new JobContext(new Configuration(), new JobID()), 1);
+    ByteArrayOutputStream byteArrayOutputStream =
+        new ByteArrayOutputStream();
+    DataOutputStream outputStream =
+        new DataOutputStream(byteArrayOutputStream);
+    ((Writable) splitArray.get(0)).write(outputStream);
+    System.out.println("testInstantiateVertex: Example output split = " +
+        byteArrayOutputStream.toString());
+  }
+
+  /**
+   * Do some checks for local job runner.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testLocalJobRunnerConfig()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    if (getJobTracker() != null) {
+      System.out.println("testLocalJobRunnerConfig: Skipping for " +
+          "non-local");
+      return;
+    }
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setWorkerConfiguration(5, 5, 100.0f);
+    job.getConfiguration().setBoolean(GiraphJob.SPLIT_MASTER_WORKER, true);
+    job.setVertexClass(SimpleSuperstepVertex.class);
+    job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
+    try {
+      job.run(true);
+      assertTrue(false);
+    } catch (IllegalArgumentException e) {
+    }
+
+    job.getConfiguration().setBoolean(GiraphJob.SPLIT_MASTER_WORKER, false);
+    try {
+      job.run(true);
+      assertTrue(false);
+    } catch (IllegalArgumentException e) {
+    }
+    job.setWorkerConfiguration(1, 1, 100.0f);
+    job.run(true);
+  }
+
+  /**
+   * Run a sample BSP job in JobTracker, kill a task, and make sure
+   * the job fails (not enough attempts to restart)
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testBspFail()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    // Allow this test only to be run on a real Hadoop setup
+    if (getJobTracker() == null) {
+      System.out.println("testBspFail: not executed for local setup.");
+      return;
+    }
+
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.getConfiguration().setInt("mapred.map.max.attempts", 1);
+    job.setVertexClass(SimpleFailVertex.class);
+    job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
+    Path outputPath = new Path("/tmp/" + getCallingMethodName());
+    removeAndSetOutput(job, outputPath);
+    assertTrue(!job.run(true));
+  }
+
+  /**
+   * Run a sample BSP job locally and test supersteps.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testBspSuperStep()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.getConfiguration().setFloat(GiraphJob.TOTAL_INPUT_SPLIT_MULTIPLIER,
+        2.0f);
+    // GeneratedInputSplit will generate 10 vertices
+    job.getConfiguration().setLong(GeneratedVertexReader.READER_VERTICES,
+        10);
+    job.setVertexClass(SimpleSuperstepVertex.class);
+    job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
+    job.setVertexOutputFormatClass(SimpleSuperstepVertexOutputFormat.class);
+    Path outputPath = new Path("/tmp/" + getCallingMethodName());
+    removeAndSetOutput(job, outputPath);
+    assertTrue(job.run(true));
+    if (getJobTracker() == null) {
+      FileStatus fileStatus = getSinglePartFileStatus(job, outputPath);
+      assertTrue(fileStatus.getLen() == 49);
+    }
+  }
+
+  /**
+   * Run a sample BSP job locally and test messages.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testBspMsg()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(SimpleMsgVertex.class);
+    job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
+    assertTrue(job.run(true));
+  }
+
+
+  /**
+   * Run a sample BSP job locally with no vertices and make sure
+   * it completes.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testEmptyVertexInputFormat()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.getConfiguration().setLong(GeneratedVertexReader.READER_VERTICES,
+        0);
+    job.setVertexClass(SimpleMsgVertex.class);
+    job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
+    assertTrue(job.run(true));
+  }
+
+  /**
+   * Run a sample BSP job locally with combiner and checkout output value.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testBspCombiner()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(SimpleCombinerVertex.class);
+    job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
+    job.setVertexCombinerClass(SimpleSumCombiner.class);
+    assertTrue(job.run(true));
+  }
+
+  /**
+   * Run a sample BSP job locally and test PageRank.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testBspPageRank()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(SimplePageRankVertex.class);
+    job.setWorkerContextClass(
+        SimplePageRankVertex.SimplePageRankVertexWorkerContext.class);
+    job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
+    assertTrue(job.run(true));
+    if (getJobTracker() == null) {
+      double maxPageRank =
+          SimplePageRankVertex.SimplePageRankVertexWorkerContext.getFinalMax();
+      double minPageRank =
+          SimplePageRankVertex.SimplePageRankVertexWorkerContext.getFinalMin();
+      long numVertices =
+          SimplePageRankVertex.SimplePageRankVertexWorkerContext.getFinalSum();
+      System.out.println("testBspPageRank: maxPageRank=" + maxPageRank +
+          " minPageRank=" + minPageRank +
+          " numVertices=" + numVertices);
+      assertTrue("34.030 !< " + maxPageRank + " !< " + " 34.0301",
+          maxPageRank > 34.030 && maxPageRank < 34.0301);
+      assertTrue("0.03 !< " + minPageRank + " !< " + "0.03001",
+          minPageRank > 0.03 && minPageRank < 0.03001);
+      assertTrue("numVertices = " + numVertices + " != 5", numVertices == 5);
+    }
+  }
+
+  /**
+   * Run a sample BSP job locally and test shortest paths.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testBspShortestPaths()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(SimpleShortestPathsVertex.class);
+    job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
+    job.setVertexOutputFormatClass(
+        SimpleShortestPathsVertexOutputFormat.class);
+    job.getConfiguration().setLong(SimpleShortestPathsVertex.SOURCE_ID, 0);
+    Path outputPath = new Path("/tmp/" + getCallingMethodName());
+    removeAndSetOutput(job, outputPath);
+    assertTrue(job.run(true));
+
+    job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(SimpleShortestPathsVertex.class);
+    job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
+    job.setVertexOutputFormatClass(
+        SimpleShortestPathsVertexOutputFormat.class);
+    job.getConfiguration().setLong(SimpleShortestPathsVertex.SOURCE_ID, 0);
+    Path outputPath2 = new Path("/tmp/" + getCallingMethodName() + "2");
+    removeAndSetOutput(job, outputPath2);
+    assertTrue(job.run(true));
+    if (getJobTracker() == null) {
+      FileStatus fileStatus = getSinglePartFileStatus(job, outputPath);
+      FileStatus fileStatus2 = getSinglePartFileStatus(job, outputPath2);
+      assertTrue(fileStatus.getLen() == fileStatus2.getLen());
+    }
+  }
+
+  /**
+   * Run a sample BSP job locally and test PageRank with AggregatorWriter.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testBspPageRankWithAggregatorWriter()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(SimplePageRankVertex.class);
+    job.setWorkerContextClass(
+        SimplePageRankVertex.SimplePageRankVertexWorkerContext.class);
+    job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
+    job.setAggregatorWriterClass(SimpleAggregatorWriter.class);
+    Path outputPath = new Path("/tmp/" + getCallingMethodName());
+    removeAndSetOutput(job, outputPath);
+    assertTrue(job.run(true));
+    if (getJobTracker() == null) {
+      double maxPageRank =
+          SimplePageRankVertex.SimplePageRankVertexWorkerContext.getFinalMax();
+      double minPageRank =
+          SimplePageRankVertex.SimplePageRankVertexWorkerContext.getFinalMin();
+      long numVertices =
+          SimplePageRankVertex.SimplePageRankVertexWorkerContext.getFinalSum();
+      System.out.println("testBspPageRank: maxPageRank=" + maxPageRank +
+          " minPageRank=" + minPageRank +
+          " numVertices=" + numVertices);
+      FileSystem fs = FileSystem.get(new Configuration());
+      FSDataInputStream input =
+          fs.open(new Path(SimpleAggregatorWriter.getFilename()));
+      int i, all;
+      for (i = 0; ; i++) {
+        all = 0;
         try {
-            job.run(true);
-            assertTrue(false);
-        } catch (IllegalArgumentException e) {
-        }
-
-        job.getConfiguration().setBoolean(GiraphJob.SPLIT_MASTER_WORKER, false);
-        try {
-            job.run(true);
-            assertTrue(false);
-        } catch (IllegalArgumentException e) {
-        }
-        job.setWorkerConfiguration(1, 1, 100.0f);
-        job.run(true);
-    }
-
-    /**
-     * Run a sample BSP job in JobTracker, kill a task, and make sure
-     * the job fails (not enough attempts to restart)
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testBspFail()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        // Allow this test only to be run on a real Hadoop setup
-        if (getJobTracker() == null) {
-            System.out.println("testBspFail: not executed for local setup.");
-            return;
-        }
-
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.getConfiguration().setInt("mapred.map.max.attempts", 1);
-        job.setVertexClass(SimpleFailVertex.class);
-        job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
-        Path outputPath = new Path("/tmp/" + getCallingMethodName());
-        removeAndSetOutput(job, outputPath);
-        assertTrue(!job.run(true));
-    }
-
-    /**
-     * Run a sample BSP job locally and test supersteps.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testBspSuperStep()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.getConfiguration().setFloat(GiraphJob.TOTAL_INPUT_SPLIT_MULTIPLIER,
-                                        2.0f);
-        // GeneratedInputSplit will generate 10 vertices
-        job.getConfiguration().setLong(GeneratedVertexReader.READER_VERTICES,
-                                       10);
-        job.setVertexClass(SimpleSuperstepVertex.class);
-        job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
-        job.setVertexOutputFormatClass(SimpleSuperstepVertexOutputFormat.class);
-        Path outputPath = new Path("/tmp/" + getCallingMethodName());
-        removeAndSetOutput(job, outputPath);
-        assertTrue(job.run(true));
-        if (getJobTracker() == null) {
-            FileStatus fileStatus = getSinglePartFileStatus(job, outputPath);
-            assertTrue(fileStatus.getLen() == 49);
-        }
-    }
-
-    /**
-     * Run a sample BSP job locally and test messages.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testBspMsg()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(SimpleMsgVertex.class);
-        job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
-        assertTrue(job.run(true));
-    }
-
-
-    /**
-     * Run a sample BSP job locally with no vertices and make sure
-     * it completes.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testEmptyVertexInputFormat()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.getConfiguration().setLong(GeneratedVertexReader.READER_VERTICES,
-                                       0);
-        job.setVertexClass(SimpleMsgVertex.class);
-        job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
-        assertTrue(job.run(true));
-    }
-
-    /**
-     * Run a sample BSP job locally with combiner and checkout output value.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testBspCombiner()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(SimpleCombinerVertex.class);
-        job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
-        job.setVertexCombinerClass(SimpleSumCombiner.class);
-        assertTrue(job.run(true));
-    }
-
-    /**
-     * Run a sample BSP job locally and test PageRank.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testBspPageRank()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(SimplePageRankVertex.class);
-        job.setWorkerContextClass(
-        	SimplePageRankVertex.SimplePageRankVertexWorkerContext.class);
-        job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
-        assertTrue(job.run(true));
-        if (getJobTracker() == null) {
-            double maxPageRank =
-            	SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalMax;
-            double minPageRank =
-            	SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalMin;
-            long numVertices =
-            	SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalSum;
-            System.out.println("testBspPageRank: maxPageRank=" + maxPageRank +
-                               " minPageRank=" + minPageRank +
-                               " numVertices=" + numVertices);
-            assertTrue("34.030 !< " + maxPageRank + " !< " + " 34.0301",
-                maxPageRank > 34.030 && maxPageRank < 34.0301);
-            assertTrue("0.03 !< " + minPageRank + " !< " + "0.03001",
-                minPageRank > 0.03 && minPageRank < 0.03001);
-            assertTrue("numVertices = " + numVertices + " != 5", numVertices == 5);
-        }
-    }
-
-    /**
-     * Run a sample BSP job locally and test shortest paths.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testBspShortestPaths()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(SimpleShortestPathsVertex.class);
-        job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
-        job.setVertexOutputFormatClass(
-            SimpleShortestPathsVertexOutputFormat.class);
-        job.getConfiguration().setLong(SimpleShortestPathsVertex.SOURCE_ID, 0);
-        Path outputPath = new Path("/tmp/" + getCallingMethodName());
-        removeAndSetOutput(job, outputPath);
-        assertTrue(job.run(true));
-
-        job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(SimpleShortestPathsVertex.class);
-        job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
-        job.setVertexOutputFormatClass(
-            SimpleShortestPathsVertexOutputFormat.class);
-        job.getConfiguration().setLong(SimpleShortestPathsVertex.SOURCE_ID, 0);
-        Path outputPath2 = new Path("/tmp/" + getCallingMethodName() + "2");
-        removeAndSetOutput(job, outputPath2);
-        assertTrue(job.run(true));
-        if (getJobTracker() == null) {
-            FileStatus fileStatus = getSinglePartFileStatus(job, outputPath);
-            FileStatus fileStatus2 = getSinglePartFileStatus(job, outputPath2);
-            assertTrue(fileStatus.getLen() == fileStatus2.getLen());
-        }
-    }
-
-    /**
-     * Run a sample BSP job locally and test PageRank with AggregatorWriter.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testBspPageRankWithAggregatorWriter()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(SimplePageRankVertex.class);
-        job.setWorkerContextClass(
-            SimplePageRankVertex.SimplePageRankVertexWorkerContext.class);
-        job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
-        job.setAggregatorWriterClass(SimpleAggregatorWriter.class);
-        Path outputPath = new Path("/tmp/" + getCallingMethodName());
-        removeAndSetOutput(job, outputPath);
-        assertTrue(job.run(true));
-        if (getJobTracker() == null) {
-            double maxPageRank =
-                SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalMax;
-            double minPageRank =
-                SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalMin;
-            long numVertices =
-                SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalSum;
-            System.out.println("testBspPageRank: maxPageRank=" + maxPageRank +
-                               " minPageRank=" + minPageRank +
-                               " numVertices=" + numVertices);
-            FileSystem fs = FileSystem.get(new Configuration());
-            FSDataInputStream input =
-                fs.open(new Path(SimpleAggregatorWriter.filename));
-            int i, all;
-            for (i = 0; ; i++) {
-                all = 0;
-                try {
-                    DoubleWritable max = new DoubleWritable();
-                    max.readFields(input);
-                    all++;
-                    DoubleWritable min = new DoubleWritable();
-                    min.readFields(input);
-                    all++;
-                    LongWritable sum = new LongWritable();
-                    sum.readFields(input);
-                    all++;
-                    if (i > 0) {
-                        assertTrue(max.get() == maxPageRank);
-                        assertTrue(min.get() == minPageRank);
-                        assertTrue(sum.get() == numVertices);
-                    }
-                } catch (IOException e) {
-                    break;
-                }
-            }
-            input.close();
-            // contained all supersteps
-            assertTrue(i == SimplePageRankVertex.MAX_SUPERSTEPS+1 && all == 0);
-            remove(new Configuration(),
-                   new Path(SimpleAggregatorWriter.filename));
+          DoubleWritable max = new DoubleWritable();
+          max.readFields(input);
+          all++;
+          DoubleWritable min = new DoubleWritable();
+          min.readFields(input);
+          all++;
+          LongWritable sum = new LongWritable();
+          sum.readFields(input);
+          all++;
+          if (i > 0) {
+            assertTrue(max.get() == maxPageRank);
+            assertTrue(min.get() == minPageRank);
+            assertTrue(sum.get() == numVertices);
+          }
+        } catch (IOException e) {
+          break;
         }
+      }
+      input.close();
+      // contained all supersteps
+      assertTrue(i == SimplePageRankVertex.MAX_SUPERSTEPS+1 && all == 0);
+      remove(new Configuration(),
+          new Path(SimpleAggregatorWriter.getFilename()));
     }
+  }
 }

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java?rev=1245205&r1=1245204&r2=1245205&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java Thu Feb 16 22:12:31 2012
@@ -21,6 +21,7 @@ package org.apache.giraph;
 import java.io.IOException;
 
 import org.apache.giraph.benchmark.PageRankBenchmark;
+import org.apache.giraph.benchmark.PageRankComputation;
 import org.apache.giraph.benchmark.PseudoRandomVertexInputFormat;
 import org.apache.giraph.graph.GiraphJob;
 import org.apache.giraph.lib.JsonBase64VertexInputFormat;
@@ -36,80 +37,80 @@ import junit.framework.TestSuite;
  * Test out the JsonBase64 format.
  */
 public class TestJsonBase64Format extends BspCase {
-    /**
-     * Create the test case
-     *
-     * @param testName name of the test case
-     */
-    public TestJsonBase64Format(String testName) {
-        super(testName);
+  /**
+   * Create the test case
+   *
+   * @param testName name of the test case
+   */
+  public TestJsonBase64Format(String testName) {
+    super(testName);
+  }
+
+  /**
+   * @return the suite of tests being tested
+   */
+  public static Test suite() {
+    return new TestSuite(TestJsonBase64Format.class);
+  }
+
+  /**
+   * Start a job and finish after i supersteps, then begin a new job and
+   * continue on more j supersteps.  Check the results against a single job
+   * with i + j supersteps.
+   *
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testContinue()
+    throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(PageRankBenchmark.class);
+    job.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
+    job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
+    job.getConfiguration().setLong(
+        PseudoRandomVertexInputFormat.AGGREGATE_VERTICES, 101);
+    job.getConfiguration().setLong(
+        PseudoRandomVertexInputFormat.EDGES_PER_VERTEX, 2);
+    job.getConfiguration().setInt(PageRankComputation.SUPERSTEP_COUNT, 2);
+    Path outputPath = new Path("/tmp/" + getCallingMethodName());
+    removeAndSetOutput(job, outputPath);
+    assertTrue(job.run(true));
+
+    job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(PageRankBenchmark.class);
+    job.setVertexInputFormatClass(JsonBase64VertexInputFormat.class);
+    job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
+    job.getConfiguration().setInt(PageRankComputation.SUPERSTEP_COUNT, 3);
+    FileInputFormat.setInputPaths(job, outputPath);
+    Path outputPath2 = new Path("/tmp/" + getCallingMethodName() + "2");
+    removeAndSetOutput(job, outputPath2);
+    assertTrue(job.run(true));
+
+    FileStatus twoJobsFile = null;
+    if (getJobTracker() == null) {
+      twoJobsFile = getSinglePartFileStatus(job, outputPath);
     }
 
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite() {
-        return new TestSuite(TestJsonBase64Format.class);
-    }
-
-    /**
-     * Start a job and finish after i supersteps, then begin a new job and
-     * continue on more j supersteps.  Check the results against a single job
-     * with i + j supersteps.
-     *
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testContinue()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(PageRankBenchmark.class);
-        job.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
-        job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
-        job.getConfiguration().setLong(
-            PseudoRandomVertexInputFormat.AGGREGATE_VERTICES, 101);
-        job.getConfiguration().setLong(
-            PseudoRandomVertexInputFormat.EDGES_PER_VERTEX, 2);
-        job.getConfiguration().setInt(PageRankBenchmark.SUPERSTEP_COUNT, 2);
-        Path outputPath = new Path("/tmp/" + getCallingMethodName());
-        removeAndSetOutput(job, outputPath);
-        assertTrue(job.run(true));
-
-        job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(PageRankBenchmark.class);
-        job.setVertexInputFormatClass(JsonBase64VertexInputFormat.class);
-        job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
-        job.getConfiguration().setInt(PageRankBenchmark.SUPERSTEP_COUNT, 3);
-        FileInputFormat.setInputPaths(job, outputPath);
-        Path outputPath2 = new Path("/tmp/" + getCallingMethodName() + "2");
-        removeAndSetOutput(job, outputPath2);
-        assertTrue(job.run(true));
-
-        FileStatus twoJobsFile = null;
-        if (getJobTracker() == null) {
-            twoJobsFile = getSinglePartFileStatus(job, outputPath);
-        }
-
-        job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.setVertexClass(PageRankBenchmark.class);
-        job.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
-        job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
-        job.getConfiguration().setLong(
-            PseudoRandomVertexInputFormat.AGGREGATE_VERTICES, 101);
-        job.getConfiguration().setLong(
-            PseudoRandomVertexInputFormat.EDGES_PER_VERTEX, 2);
-        job.getConfiguration().setInt(PageRankBenchmark.SUPERSTEP_COUNT, 5);
-        Path outputPath3 = new Path("/tmp/" + getCallingMethodName() + "3");
-        removeAndSetOutput(job, outputPath3);
-        assertTrue(job.run(true));
-
-        if (getJobTracker() == null) {
-            FileStatus oneJobFile = getSinglePartFileStatus(job, outputPath3);
-            assertTrue(twoJobsFile.getLen() == oneJobFile.getLen());
-        }
+    job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.setVertexClass(PageRankBenchmark.class);
+    job.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
+    job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
+    job.getConfiguration().setLong(
+        PseudoRandomVertexInputFormat.AGGREGATE_VERTICES, 101);
+    job.getConfiguration().setLong(
+        PseudoRandomVertexInputFormat.EDGES_PER_VERTEX, 2);
+    job.getConfiguration().setInt(PageRankComputation.SUPERSTEP_COUNT, 5);
+    Path outputPath3 = new Path("/tmp/" + getCallingMethodName() + "3");
+    removeAndSetOutput(job, outputPath3);
+    assertTrue(job.run(true));
+
+    if (getJobTracker() == null) {
+      FileStatus oneJobFile = getSinglePartFileStatus(job, outputPath3);
+      assertTrue(twoJobsFile.getLen() == oneJobFile.getLen());
     }
+  }
 }

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/TestManualCheckpoint.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/TestManualCheckpoint.java?rev=1245205&r1=1245204&r2=1245205&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/TestManualCheckpoint.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/TestManualCheckpoint.java Thu Feb 16 22:12:31 2012
@@ -33,88 +33,88 @@ import junit.framework.TestSuite;
  * Unit test for manual checkpoint restarting
  */
 public class TestManualCheckpoint extends BspCase {
-    /** Where the checkpoints will be stored and restarted */
-    private final String HDFS_CHECKPOINT_DIR =
-        "/tmp/testBspCheckpoints";
+  /** Where the checkpoints will be stored and restarted */
+  private final String HDFS_CHECKPOINT_DIR =
+      "/tmp/testBspCheckpoints";
 
-    /**
-     * Create the test case
-     *
-     * @param testName name of the test case
-     */
-    public TestManualCheckpoint(String testName) {
-        super(testName);
-    }
+  /**
+   * Create the test case
+   *
+   * @param testName name of the test case
+   */
+  public TestManualCheckpoint(String testName) {
+    super(testName);
+  }
 
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite() {
-        return new TestSuite(TestManualCheckpoint.class);
-    }
+  /**
+   * @return the suite of tests being tested
+   */
+  public static Test suite() {
+    return new TestSuite(TestManualCheckpoint.class);
+  }
 
-    /**
-     * Run a sample BSP job locally and test checkpointing.
-     * @throws IOException
-     * @throws ClassNotFoundException
-     * @throws InterruptedException
-     */
-    public void testBspCheckpoint()
-            throws IOException, InterruptedException, ClassNotFoundException {
-        GiraphJob job = new GiraphJob(getCallingMethodName());
-        setupConfiguration(job);
-        job.getConfiguration().set(GiraphJob.CHECKPOINT_DIRECTORY,
-                                   HDFS_CHECKPOINT_DIR);
-        job.getConfiguration().setBoolean(
-            GiraphJob.CLEANUP_CHECKPOINTS_AFTER_SUCCESS, false);
-        job.setVertexClass(SimpleCheckpointVertex.class);
-        job.setWorkerContextClass(
-            SimpleCheckpointVertex.SimpleCheckpointVertexWorkerContext.class);
-        job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
-        job.setVertexOutputFormatClass(SimpleSuperstepVertexOutputFormat.class);
-        Path outputPath = new Path("/tmp/" + getCallingMethodName());
-        removeAndSetOutput(job, outputPath);
-        assertTrue(job.run(true));
-        long fileLen = 0;
-        long idSum = 0;
-        if (getJobTracker() == null) {
-            FileStatus fileStatus = getSinglePartFileStatus(job, outputPath);
-            fileLen = fileStatus.getLen();
-            idSum =
-            	SimpleCheckpointVertex.SimpleCheckpointVertexWorkerContext.finalSum;
-            System.out.println("testBspCheckpoint: idSum = " + idSum +
-                               " fileLen = " + fileLen);
-        }
+  /**
+   * Run a sample BSP job locally and test checkpointing.
+   * @throws IOException
+   * @throws ClassNotFoundException
+   * @throws InterruptedException
+   */
+  public void testBspCheckpoint()
+      throws IOException, InterruptedException, ClassNotFoundException {
+    GiraphJob job = new GiraphJob(getCallingMethodName());
+    setupConfiguration(job);
+    job.getConfiguration().set(GiraphJob.CHECKPOINT_DIRECTORY,
+        HDFS_CHECKPOINT_DIR);
+    job.getConfiguration().setBoolean(
+        GiraphJob.CLEANUP_CHECKPOINTS_AFTER_SUCCESS, false);
+    job.setVertexClass(SimpleCheckpointVertex.class);
+    job.setWorkerContextClass(
+        SimpleCheckpointVertex.SimpleCheckpointVertexWorkerContext.class);
+    job.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
+    job.setVertexOutputFormatClass(SimpleSuperstepVertexOutputFormat.class);
+    Path outputPath = new Path("/tmp/" + getCallingMethodName());
+    removeAndSetOutput(job, outputPath);
+    assertTrue(job.run(true));
+    long fileLen = 0;
+    long idSum = 0;
+    if (getJobTracker() == null) {
+      FileStatus fileStatus = getSinglePartFileStatus(job, outputPath);
+      fileLen = fileStatus.getLen();
+      idSum =
+          SimpleCheckpointVertex.SimpleCheckpointVertexWorkerContext.getFinalSum();
+      System.out.println("testBspCheckpoint: idSum = " + idSum +
+          " fileLen = " + fileLen);
+    }
 
-        // Restart the test from superstep 2
-        System.out.println(
-            "testBspCheckpoint: Restarting from superstep 2" +
+    // Restart the test from superstep 2
+    System.out.println(
+        "testBspCheckpoint: Restarting from superstep 2" +
             " with checkpoint path = " + HDFS_CHECKPOINT_DIR);
-        GiraphJob restartedJob = new GiraphJob(getCallingMethodName() +
-                                               "Restarted");
-        setupConfiguration(restartedJob);
-        restartedJob.getConfiguration().set(GiraphJob.CHECKPOINT_DIRECTORY,
-                                            HDFS_CHECKPOINT_DIR);
-        restartedJob.getConfiguration().setLong(GiraphJob.RESTART_SUPERSTEP, 2);
-        restartedJob.setVertexClass(SimpleCheckpointVertex.class);
-        restartedJob.setWorkerContextClass(
-        	SimpleCheckpointVertex.SimpleCheckpointVertexWorkerContext.class);
-        restartedJob.setVertexInputFormatClass(
-            SimpleSuperstepVertexInputFormat.class);
-        restartedJob.setVertexOutputFormatClass(
-            SimpleSuperstepVertexOutputFormat.class);
-        outputPath = new Path("/tmp/" + getCallingMethodName() + "Restarted");
-        removeAndSetOutput(restartedJob, outputPath);
-        assertTrue(restartedJob.run(true));
-        if (getJobTracker() == null) {
-            FileStatus fileStatus = getSinglePartFileStatus(job, outputPath);
-            fileLen = fileStatus.getLen();
-            assertTrue(fileStatus.getLen() == fileLen);
-            long idSumRestarted =
-            	SimpleCheckpointVertex.SimpleCheckpointVertexWorkerContext.finalSum;
-            System.out.println("testBspCheckpoint: idSumRestarted = " +
-                               idSumRestarted);
-            assertTrue(idSum == idSumRestarted);
-        }
+    GiraphJob restartedJob = new GiraphJob(getCallingMethodName() +
+        "Restarted");
+    setupConfiguration(restartedJob);
+    restartedJob.getConfiguration().set(GiraphJob.CHECKPOINT_DIRECTORY,
+        HDFS_CHECKPOINT_DIR);
+    restartedJob.getConfiguration().setLong(GiraphJob.RESTART_SUPERSTEP, 2);
+    restartedJob.setVertexClass(SimpleCheckpointVertex.class);
+    restartedJob.setWorkerContextClass(
+        SimpleCheckpointVertex.SimpleCheckpointVertexWorkerContext.class);
+    restartedJob.setVertexInputFormatClass(
+        SimpleSuperstepVertexInputFormat.class);
+    restartedJob.setVertexOutputFormatClass(
+        SimpleSuperstepVertexOutputFormat.class);
+    outputPath = new Path("/tmp/" + getCallingMethodName() + "Restarted");
+    removeAndSetOutput(restartedJob, outputPath);
+    assertTrue(restartedJob.run(true));
+    if (getJobTracker() == null) {
+      FileStatus fileStatus = getSinglePartFileStatus(job, outputPath);
+      fileLen = fileStatus.getLen();
+      assertTrue(fileStatus.getLen() == fileLen);
+      long idSumRestarted =
+          SimpleCheckpointVertex.SimpleCheckpointVertexWorkerContext.getFinalSum();
+      System.out.println("testBspCheckpoint: idSumRestarted = " +
+          idSumRestarted);
+      assertTrue(idSum == idSumRestarted);
     }
+  }
 }

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java?rev=1245205&r1=1245204&r2=1245205&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java Thu Feb 16 22:12:31 2012
@@ -38,110 +38,111 @@ import java.util.Map;
  */
 public class SimpleShortestPathVertexTest extends TestCase {
 
-    /**
-     * Test the behavior when a shorter path to a vertex has been found
-     */
-    public void testOnShorterPathFound() throws Exception {
-
-        SimpleShortestPathsVertex vertex = new SimpleShortestPathsVertex();
-        vertex.initialize(null, null, null, null);
-        vertex.addEdge(new LongWritable(10L), new FloatWritable(2.5f));
-        vertex.addEdge(new LongWritable(20L), new FloatWritable(0.5f));
-
-        MockUtils.MockedEnvironment<LongWritable, DoubleWritable, FloatWritable,
-                DoubleWritable> env = MockUtils.prepareVertex(vertex, 1L,
-                new LongWritable(7L), new DoubleWritable(Double.MAX_VALUE),
-                false);
-
-        Mockito.when(env.getConfiguration().getLong(
-                SimpleShortestPathsVertex.SOURCE_ID,
-                SimpleShortestPathsVertex.SOURCE_ID_DEFAULT)).thenReturn(2L);
-
-        vertex.compute(Lists.newArrayList(new DoubleWritable(2),
-                new DoubleWritable(1.5)).iterator());
-
-        assertTrue(vertex.isHalted());
-        assertEquals(1.5, vertex.getVertexValue().get());
-
-        env.verifyMessageSent(new LongWritable(10L), new DoubleWritable(4));
-        env.verifyMessageSent(new LongWritable(20L), new DoubleWritable(2));
-    }
-
-    /**
-     * Test the behavior when a new, but not shorter path to a vertex has been found
-     */
-    public void testOnNoShorterPathFound() throws Exception {
-
-        SimpleShortestPathsVertex vertex = new SimpleShortestPathsVertex();
-        vertex.initialize(null, null, null, null);
-        vertex.addEdge(new LongWritable(10L), new FloatWritable(2.5f));
-        vertex.addEdge(new LongWritable(20L), new FloatWritable(0.5f));
-
-        MockUtils.MockedEnvironment<LongWritable, DoubleWritable, FloatWritable,
-                DoubleWritable> env = MockUtils.prepareVertex(vertex, 1L,
-                new LongWritable(7L), new DoubleWritable(0.5), false);
-
-        Mockito.when(env.getConfiguration().getLong(
-                SimpleShortestPathsVertex.SOURCE_ID,
-                SimpleShortestPathsVertex.SOURCE_ID_DEFAULT)).thenReturn(2L);
-
-        vertex.compute(Lists.newArrayList(new DoubleWritable(2),
-                new DoubleWritable(1.5)).iterator());
-
-        assertTrue(vertex.isHalted());
-        assertEquals(0.5, vertex.getVertexValue().get());
-
-        env.verifyNoMessageSent();
-    }
-
-    /**
-     * A local integration test on toy data
-     */
-    public void testToyData() throws Exception {
-
-        // a small four vertex graph
-        String[] graph = new String[] {
-                "[1,0,[[2,1],[3,3]]]",
-                "[2,0,[[3,1],[4,10]]]",
-                "[3,0,[[4,2]]]",
-                "[4,0,[]]" };
-
-        // start from vertex 1
-        Map<String, String> params = Maps.newHashMap();
-        params.put(SimpleShortestPathsVertex.SOURCE_ID, "1");
-
-        // run internally
-        Iterable<String> results = InternalVertexRunner.run(
-                SimpleShortestPathsVertex.class,
-                SimpleShortestPathsVertex.
-                        SimpleShortestPathsVertexInputFormat.class,
-                SimpleShortestPathsVertex.
-                        SimpleShortestPathsVertexOutputFormat.class,
-                params, graph);
-
-        Map<Long, Double> distances = parseDistances(results);
-
-        // verify results
-        assertNotNull(distances);
-        assertEquals(4, distances.size());
-        assertEquals(0.0, distances.get(1L));
-        assertEquals(1.0, distances.get(2L));
-        assertEquals(2.0, distances.get(3L));
-        assertEquals(4.0, distances.get(4L));
-    }
-
-    private Map<Long, Double> parseDistances(Iterable<String> results) {
-        Map<Long, Double> distances =
-                Maps.newHashMapWithExpectedSize(Iterables.size(results));
-        for (String line : results) {
-            try {
-                JSONArray jsonVertex = new JSONArray(line);
-                distances.put(jsonVertex.getLong(0), jsonVertex.getDouble(1));
-            } catch (JSONException e) {
-                throw new IllegalArgumentException(
-                    "Couldn't get vertex from line " + line, e);
-            }
-        }
-        return distances;
+  /**
+   * Test the behavior when a shorter path to a vertex has been found
+   */
+  public void testOnShorterPathFound() throws Exception {
+
+    SimpleShortestPathsVertex vertex = new SimpleShortestPathsVertex();
+    vertex.initialize(null, null, null, null);
+    vertex.addEdge(new LongWritable(10L), new FloatWritable(2.5f));
+    vertex.addEdge(new LongWritable(20L), new FloatWritable(0.5f));
+
+    MockUtils.MockedEnvironment<LongWritable, DoubleWritable, FloatWritable,
+    DoubleWritable> env = MockUtils.prepareVertex(vertex, 1L,
+        new LongWritable(7L), new DoubleWritable(Double.MAX_VALUE),
+        false);
+
+    Mockito.when(env.getConfiguration().getLong(
+        SimpleShortestPathsVertex.SOURCE_ID,
+        SimpleShortestPathsVertex.SOURCE_ID_DEFAULT)).thenReturn(2L);
+
+    vertex.compute(Lists.newArrayList(new DoubleWritable(2),
+        new DoubleWritable(1.5)).iterator());
+
+    assertTrue(vertex.isHalted());
+    assertEquals(1.5, vertex.getVertexValue().get());
+
+    env.verifyMessageSent(new LongWritable(10L), new DoubleWritable(4));
+    env.verifyMessageSent(new LongWritable(20L), new DoubleWritable(2));
+  }
+
+  /**
+   * Test the behavior when a new, but not shorter path to a vertex has been
+   * found.
+   */
+  public void testOnNoShorterPathFound() throws Exception {
+
+    SimpleShortestPathsVertex vertex = new SimpleShortestPathsVertex();
+    vertex.initialize(null, null, null, null);
+    vertex.addEdge(new LongWritable(10L), new FloatWritable(2.5f));
+    vertex.addEdge(new LongWritable(20L), new FloatWritable(0.5f));
+
+    MockUtils.MockedEnvironment<LongWritable, DoubleWritable, FloatWritable,
+    DoubleWritable> env = MockUtils.prepareVertex(vertex, 1L,
+        new LongWritable(7L), new DoubleWritable(0.5), false);
+
+    Mockito.when(env.getConfiguration().getLong(
+        SimpleShortestPathsVertex.SOURCE_ID,
+        SimpleShortestPathsVertex.SOURCE_ID_DEFAULT)).thenReturn(2L);
+
+    vertex.compute(Lists.newArrayList(new DoubleWritable(2),
+        new DoubleWritable(1.5)).iterator());
+
+    assertTrue(vertex.isHalted());
+    assertEquals(0.5, vertex.getVertexValue().get());
+
+    env.verifyNoMessageSent();
+  }
+
+  /**
+   * A local integration test on toy data
+   */
+  public void testToyData() throws Exception {
+
+    // a small four vertex graph
+    String[] graph = new String[] {
+        "[1,0,[[2,1],[3,3]]]",
+        "[2,0,[[3,1],[4,10]]]",
+        "[3,0,[[4,2]]]",
+    "[4,0,[]]" };
+
+    // start from vertex 1
+    Map<String, String> params = Maps.newHashMap();
+    params.put(SimpleShortestPathsVertex.SOURCE_ID, "1");
+
+    // run internally
+    Iterable<String> results = InternalVertexRunner.run(
+        SimpleShortestPathsVertex.class,
+        SimpleShortestPathsVertex.
+        SimpleShortestPathsVertexInputFormat.class,
+        SimpleShortestPathsVertex.
+        SimpleShortestPathsVertexOutputFormat.class,
+        params, graph);
+
+    Map<Long, Double> distances = parseDistances(results);
+
+    // verify results
+    assertNotNull(distances);
+    assertEquals(4, distances.size());
+    assertEquals(0.0, distances.get(1L));
+    assertEquals(1.0, distances.get(2L));
+    assertEquals(2.0, distances.get(3L));
+    assertEquals(4.0, distances.get(4L));
+  }
+
+  private Map<Long, Double> parseDistances(Iterable<String> results) {
+    Map<Long, Double> distances =
+        Maps.newHashMapWithExpectedSize(Iterables.size(results));
+    for (String line : results) {
+      try {
+        JSONArray jsonVertex = new JSONArray(line);
+        distances.put(jsonVertex.getLong(0), jsonVertex.getDouble(1));
+      } catch (JSONException e) {
+        throw new IllegalArgumentException(
+            "Couldn't get vertex from line " + line, e);
+      }
     }
+    return distances;
+  }
 }

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java?rev=1245205&r1=1245204&r2=1245205&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java Thu Feb 16 22:12:31 2012
@@ -41,136 +41,134 @@ import java.util.Map;
  * Tests {@link EdgeListVertex}.
  */
 public class TestEdgeListVertex extends TestCase {
-    /** Instantiated vertex filled in from setup() */
-    private IFDLEdgeListVertex vertex;
-    /** Job filled in by setup() */
-    private GiraphJob job;
-
-    /**
-     * Simple instantiable class that extends {@link EdgeArrayVertex}.
-     */
-    private static class IFDLEdgeListVertex extends
-            EdgeListVertex<IntWritable, FloatWritable, DoubleWritable,
-            LongWritable> {
-
-        @Override
-        public void compute(Iterator<LongWritable> msgIterator)
-                throws IOException {
-        }
-    }
-
+  /** Instantiated vertex filled in from setup() */
+  private IFDLEdgeListVertex vertex;
+  /** Job filled in by setup() */
+  private GiraphJob job;
+
+  /**
+   * Simple instantiable class that extends {@link EdgeArrayVertex}.
+   */
+  private static class IFDLEdgeListVertex extends
+      EdgeListVertex<IntWritable, FloatWritable, DoubleWritable,
+      LongWritable> {
     @Override
-    public void setUp() {
-        try {
-            job = new GiraphJob("TestEdgeArrayVertex");
-        } catch (IOException e) {
-            throw new RuntimeException("setUp: Failed", e);
-        }
-        job.setVertexClass(IFDLEdgeListVertex.class);
-        job.getConfiguration().setClass(GiraphJob.VERTEX_INDEX_CLASS,
-            IntWritable.class, WritableComparable.class);
-        job.getConfiguration().setClass(GiraphJob.VERTEX_VALUE_CLASS,
-            FloatWritable.class, Writable.class);
-        job.getConfiguration().setClass(GiraphJob.EDGE_VALUE_CLASS,
-            DoubleWritable.class, Writable.class);
-        job.getConfiguration().setClass(GiraphJob.MESSAGE_VALUE_CLASS,
-            LongWritable.class, Writable.class);
-        vertex = (IFDLEdgeListVertex)
-            BspUtils.<IntWritable, FloatWritable, DoubleWritable, LongWritable>
-            createVertex(job.getConfiguration());
-    }
-
-    public void testInstantiate() throws IOException {
-        assertNotNull(vertex);
-    }
-
-    public void testEdges() {
-        Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
-        for (int i = 1000; i > 0; --i) {
-            edgeMap.put(new IntWritable(i), new DoubleWritable(i * 2.0));
-        }
-        vertex.initialize(null, null, edgeMap, null);
-        assertEquals(vertex.getNumOutEdges(), 1000);
-        int expectedIndex = 1;
-        for (IntWritable index : vertex) {
-            assertEquals(index.get(), expectedIndex);
-            assertEquals(vertex.getEdgeValue(index).get(),
-                         expectedIndex * 2.0d);
-            ++expectedIndex;
-        }
-        assertEquals(vertex.removeEdge(new IntWritable(500)),
-                     new DoubleWritable(1000));
-        assertEquals(vertex.getNumOutEdges(), 999);
-    }
-
-    public void testGetEdges() {
-        Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
-        for (int i = 1000; i > 0; --i) {
-            edgeMap.put(new IntWritable(i), new DoubleWritable(i * 3.0));
-        }
-        vertex.initialize(null, null, edgeMap, null);
-        assertEquals(vertex.getNumOutEdges(), 1000);
-        assertEquals(vertex.getEdgeValue(new IntWritable(600)),
-                     new DoubleWritable(600 * 3.0));
-        assertEquals(vertex.removeEdge(new IntWritable(600)),
-                     new DoubleWritable(600 * 3.0));
-        assertEquals(vertex.getNumOutEdges(), 999);
-        assertEquals(vertex.getEdgeValue(new IntWritable(500)),
-                     new DoubleWritable(500 * 3.0));
-        assertEquals(vertex.getEdgeValue(new IntWritable(700)),
-                     new DoubleWritable(700 * 3.0));
-    }
-
-    public void testAddRemoveEdges() {
-        Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
-        vertex.initialize(null, null, edgeMap, null);
-        assertEquals(vertex.getNumOutEdges(), 0);
-        assertTrue(vertex.addEdge(new IntWritable(2),
-                                  new DoubleWritable(2.0)));
-        assertEquals(vertex.getNumOutEdges(), 1);
-        assertEquals(vertex.getEdgeValue(new IntWritable(2)),
-                                         new DoubleWritable(2.0));
-        assertTrue(vertex.addEdge(new IntWritable(4),
-                                 new DoubleWritable(4.0)));
-        assertTrue(vertex.addEdge(new IntWritable(3),
-                                  new DoubleWritable(3.0)));
-        assertTrue(vertex.addEdge(new IntWritable(1),
-                                  new DoubleWritable(1.0)));
-        assertEquals(vertex.getNumOutEdges(), 4);
-        assertNull(vertex.getEdgeValue(new IntWritable(5)));
-        assertNull(vertex.getEdgeValue(new IntWritable(0)));
-        int i = 1;
-        for (IntWritable edgeDestId : vertex) {
-            assertEquals(i, edgeDestId.get());
-            assertEquals(i * 1.0d, vertex.getEdgeValue(edgeDestId).get());
-            ++i;
-        }
-        assertNotNull(vertex.removeEdge(new IntWritable(1)));
-        assertEquals(vertex.getNumOutEdges(), 3);
-        assertNotNull(vertex.removeEdge(new IntWritable(3)));
-        assertEquals(vertex.getNumOutEdges(), 2);
-        assertNotNull(vertex.removeEdge(new IntWritable(2)));
-        assertEquals(vertex.getNumOutEdges(), 1);
-        assertNotNull(vertex.removeEdge(new IntWritable(4)));
-        assertEquals(vertex.getNumOutEdges(), 0);
-    }
-
-
-    public void testSerialize() {
-        Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
-        for (int i = 1000; i > 0; --i) {
-            edgeMap.put(new IntWritable(i), new DoubleWritable(i * 2.0));
-        }
-        List<LongWritable> messageList = Lists.newArrayList();
-        messageList.add(new LongWritable(4));
-        messageList.add(new LongWritable(5));
-        vertex.initialize(
-            new IntWritable(2), new FloatWritable(3.0f), edgeMap, messageList);
-        byte[] byteArray = WritableUtils.writeToByteArray(vertex);
-        IFDLEdgeListVertex readVertex = (IFDLEdgeListVertex)
-            BspUtils.<IntWritable, FloatWritable, DoubleWritable, LongWritable>
-            createVertex(job.getConfiguration());
-        WritableUtils.readFieldsFromByteArray(byteArray, readVertex);
-        assertEquals(vertex, readVertex);
+    public void compute(Iterator<LongWritable> msgIterator)
+      throws IOException {
     }
+  }
+
+  @Override
+  public void setUp() {
+    try {
+      job = new GiraphJob("TestEdgeArrayVertex");
+    } catch (IOException e) {
+      throw new RuntimeException("setUp: Failed", e);
+    }
+    job.setVertexClass(IFDLEdgeListVertex.class);
+    job.getConfiguration().setClass(GiraphJob.VERTEX_INDEX_CLASS,
+        IntWritable.class, WritableComparable.class);
+    job.getConfiguration().setClass(GiraphJob.VERTEX_VALUE_CLASS,
+        FloatWritable.class, Writable.class);
+    job.getConfiguration().setClass(GiraphJob.EDGE_VALUE_CLASS,
+        DoubleWritable.class, Writable.class);
+    job.getConfiguration().setClass(GiraphJob.MESSAGE_VALUE_CLASS,
+        LongWritable.class, Writable.class);
+    vertex = (IFDLEdgeListVertex)
+      BspUtils.<IntWritable, FloatWritable, DoubleWritable, LongWritable>
+      createVertex(job.getConfiguration());
+  }
+
+  public void testInstantiate() throws IOException {
+    assertNotNull(vertex);
+  }
+
+  public void testEdges() {
+    Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
+    for (int i = 1000; i > 0; --i) {
+      edgeMap.put(new IntWritable(i), new DoubleWritable(i * 2.0));
+    }
+    vertex.initialize(null, null, edgeMap, null);
+    assertEquals(vertex.getNumOutEdges(), 1000);
+    int expectedIndex = 1;
+    for (IntWritable index : vertex) {
+      assertEquals(index.get(), expectedIndex);
+      assertEquals(vertex.getEdgeValue(index).get(),
+          expectedIndex * 2.0d);
+      ++expectedIndex;
+    }
+    assertEquals(vertex.removeEdge(new IntWritable(500)),
+        new DoubleWritable(1000));
+    assertEquals(vertex.getNumOutEdges(), 999);
+  }
+
+  public void testGetEdges() {
+    Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
+    for (int i = 1000; i > 0; --i) {
+      edgeMap.put(new IntWritable(i), new DoubleWritable(i * 3.0));
+    }
+    vertex.initialize(null, null, edgeMap, null);
+    assertEquals(vertex.getNumOutEdges(), 1000);
+    assertEquals(vertex.getEdgeValue(new IntWritable(600)),
+        new DoubleWritable(600 * 3.0));
+    assertEquals(vertex.removeEdge(new IntWritable(600)),
+        new DoubleWritable(600 * 3.0));
+    assertEquals(vertex.getNumOutEdges(), 999);
+    assertEquals(vertex.getEdgeValue(new IntWritable(500)),
+        new DoubleWritable(500 * 3.0));
+    assertEquals(vertex.getEdgeValue(new IntWritable(700)),
+        new DoubleWritable(700 * 3.0));
+  }
+
+  public void testAddRemoveEdges() {
+    Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
+    vertex.initialize(null, null, edgeMap, null);
+    assertEquals(vertex.getNumOutEdges(), 0);
+    assertTrue(vertex.addEdge(new IntWritable(2),
+        new DoubleWritable(2.0)));
+    assertEquals(vertex.getNumOutEdges(), 1);
+    assertEquals(vertex.getEdgeValue(new IntWritable(2)),
+        new DoubleWritable(2.0));
+    assertTrue(vertex.addEdge(new IntWritable(4),
+        new DoubleWritable(4.0)));
+    assertTrue(vertex.addEdge(new IntWritable(3),
+        new DoubleWritable(3.0)));
+    assertTrue(vertex.addEdge(new IntWritable(1),
+        new DoubleWritable(1.0)));
+    assertEquals(vertex.getNumOutEdges(), 4);
+    assertNull(vertex.getEdgeValue(new IntWritable(5)));
+    assertNull(vertex.getEdgeValue(new IntWritable(0)));
+    int i = 1;
+    for (IntWritable edgeDestId : vertex) {
+      assertEquals(i, edgeDestId.get());
+      assertEquals(i * 1.0d, vertex.getEdgeValue(edgeDestId).get());
+      ++i;
+    }
+    assertNotNull(vertex.removeEdge(new IntWritable(1)));
+    assertEquals(vertex.getNumOutEdges(), 3);
+    assertNotNull(vertex.removeEdge(new IntWritable(3)));
+    assertEquals(vertex.getNumOutEdges(), 2);
+    assertNotNull(vertex.removeEdge(new IntWritable(2)));
+    assertEquals(vertex.getNumOutEdges(), 1);
+    assertNotNull(vertex.removeEdge(new IntWritable(4)));
+    assertEquals(vertex.getNumOutEdges(), 0);
+  }
+
+  public void testSerialize() {
+    Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
+    for (int i = 1000; i > 0; --i) {
+      edgeMap.put(new IntWritable(i), new DoubleWritable(i * 2.0));
+    }
+    List<LongWritable> messageList = Lists.newArrayList();
+    messageList.add(new LongWritable(4));
+    messageList.add(new LongWritable(5));
+    vertex.initialize(
+        new IntWritable(2), new FloatWritable(3.0f), edgeMap, messageList);
+    byte[] byteArray = WritableUtils.writeToByteArray(vertex);
+    IFDLEdgeListVertex readVertex = (IFDLEdgeListVertex)
+      BspUtils.<IntWritable, FloatWritable, DoubleWritable, LongWritable>
+      createVertex(job.getConfiguration());
+    WritableUtils.readFieldsFromByteArray(byteArray, readVertex);
+    assertEquals(vertex, readVertex);
+  }
 }

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java?rev=1245205&r1=1245204&r2=1245205&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java Thu Feb 16 22:12:31 2012
@@ -44,7 +44,7 @@ public class MockUtils {
     public static class MockedEnvironment<I extends WritableComparable,
             V extends Writable, E extends Writable, M extends Writable> {
 
-        private final GraphState graphState;
+        private final GraphState<I, V, E, M> graphState;
         private final Mapper.Context context;
         private final Configuration conf;
         private final WorkerCommunications communications;

Modified: incubator/giraph/trunk/src/test/java/zk/TestZooKeeperManager.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/zk/TestZooKeeperManager.java?rev=1245205&r1=1245204&r2=1245205&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/zk/TestZooKeeperManager.java (original)
+++ incubator/giraph/trunk/src/test/java/zk/TestZooKeeperManager.java Thu Feb 16 22:12:31 2012
@@ -31,7 +31,8 @@ public class TestZooKeeperManager extend
         "", ZooKeeperManager.getBasePath(conf));
 
     conf.set(GiraphJob.BASE_ZNODE_KEY, "/howdy");
-    assertEquals("Base path should reflect value of " + GiraphJob.BASE_ZNODE_KEY,
+    assertEquals("Base path should reflect value of " +
+        GiraphJob.BASE_ZNODE_KEY,
         "/howdy", ZooKeeperManager.getBasePath(conf));
 
     conf.set(GiraphJob.BASE_ZNODE_KEY, "no_slash");



Mime
View raw message