This project has retired. For details please refer to its Attic page.
TestJsonBase64Format xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.io;
20  
21  import org.apache.giraph.BspCase;
22  import org.apache.giraph.benchmark.WeightedPageRankComputation;
23  import org.apache.giraph.conf.GiraphConfiguration;
24  import org.apache.giraph.io.formats.GiraphFileInputFormat;
25  import org.apache.giraph.io.formats.JsonBase64VertexInputFormat;
26  import org.apache.giraph.io.formats.JsonBase64VertexOutputFormat;
27  import org.apache.giraph.io.formats.PseudoRandomInputFormatConstants;
28  import org.apache.giraph.io.formats.PseudoRandomVertexInputFormat;
29  import org.apache.giraph.job.GiraphJob;
30  import org.apache.hadoop.fs.Path;
31  import org.junit.Test;
32  
33  import java.io.IOException;
34  
35  import static org.junit.Assert.assertEquals;
36  import static org.junit.Assert.assertTrue;
37  
38  /**
39   * Test out the JsonBase64 format.
40   */
41  public class TestJsonBase64Format extends BspCase {
42    /**
43     * Constructor.
44     */
45    public TestJsonBase64Format() {
46      super(TestJsonBase64Format.class.getName());
47    }
48  
49    /**
50     * Start a job and finish after i supersteps, then begin a new job and
51     * continue on more j supersteps.  Check the results against a single job
52     * with i + j supersteps.
53     *
54     * @throws IOException
55     * @throws ClassNotFoundException
56     * @throws InterruptedException
57     */
58    @Test
59    public void testContinue()
60        throws IOException, InterruptedException, ClassNotFoundException {
61  
62      Path outputPath = getTempPath(getCallingMethodName());
63      GiraphConfiguration conf = new GiraphConfiguration();
64      conf.setComputationClass(WeightedPageRankComputation.class);
65      conf.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
66      conf.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
67      GiraphJob job = prepareJob(getCallingMethodName(), conf, outputPath);
68      job.getConfiguration().setLong(
69          PseudoRandomInputFormatConstants.AGGREGATE_VERTICES, 101);
70      job.getConfiguration().setLong(
71          PseudoRandomInputFormatConstants.EDGES_PER_VERTEX, 2);
72      job.getConfiguration().setInt(
73          WeightedPageRankComputation.SUPERSTEP_COUNT, 2);
74      assertTrue(job.run(true));
75  
76      Path outputPath2 = getTempPath(getCallingMethodName() + "2");
77      conf = new GiraphConfiguration();
78      conf.setComputationClass(WeightedPageRankComputation.class);
79      conf.setVertexInputFormatClass(JsonBase64VertexInputFormat.class);
80      conf.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
81      job = prepareJob(getCallingMethodName(), conf, outputPath2);
82      job.getConfiguration().setInt(
83          WeightedPageRankComputation.SUPERSTEP_COUNT, 3);
84      GiraphFileInputFormat.addVertexInputPath(
85        job.getInternalJob().getConfiguration(), outputPath);
86      assertTrue(job.run(true));
87  
88      Path outputPath3 = getTempPath(getCallingMethodName() + "3");
89      conf = new GiraphConfiguration();
90      conf.setComputationClass(WeightedPageRankComputation.class);
91      conf.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
92      conf.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
93      job = prepareJob(getCallingMethodName(), conf, outputPath3);
94      conf = job.getConfiguration();
95      conf.setLong(PseudoRandomInputFormatConstants.AGGREGATE_VERTICES, 101);
96      conf.setLong(PseudoRandomInputFormatConstants.EDGES_PER_VERTEX, 2);
97      conf.setInt(
98          WeightedPageRankComputation.SUPERSTEP_COUNT, 5);
99      assertTrue(job.run(true));
100 
101     assertEquals(101, getNumResults(conf, outputPath));
102     assertEquals(101, getNumResults(conf, outputPath2));
103     assertEquals(101, getNumResults(conf, outputPath3));
104   }
105 }