1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.giraph.io;
2021import org.apache.giraph.BspCase;
22import org.apache.giraph.benchmark.WeightedPageRankComputation;
23import org.apache.giraph.conf.GiraphConfiguration;
24import org.apache.giraph.io.formats.GiraphFileInputFormat;
25import org.apache.giraph.io.formats.JsonBase64VertexInputFormat;
26import org.apache.giraph.io.formats.JsonBase64VertexOutputFormat;
27import org.apache.giraph.io.formats.PseudoRandomInputFormatConstants;
28import org.apache.giraph.io.formats.PseudoRandomVertexInputFormat;
29import org.apache.giraph.job.GiraphJob;
30import org.apache.hadoop.fs.Path;
31import org.junit.Test;
3233import java.io.IOException;
3435importstatic org.junit.Assert.assertEquals;
36importstatic org.junit.Assert.assertTrue;
3738/**39 * Test out the JsonBase64 format.40 */41publicclassTestJsonBase64FormatextendsBspCase {
42/**43 * Constructor.44 */45publicTestJsonBase64Format() {
46super(TestJsonBase64Format.class.getName());
47 }
4849/**50 * Start a job and finish after i supersteps, then begin a new job and51 * continue on more j supersteps. Check the results against a single job52 * with i + j supersteps.53 *54 * @throws IOException55 * @throws ClassNotFoundException56 * @throws InterruptedException57 */58 @Test
59publicvoid testContinue()
60throws IOException, InterruptedException, ClassNotFoundException {
6162 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));
7576 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));
8788 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));
100101 assertEquals(101, getNumResults(conf, outputPath));
102 assertEquals(101, getNumResults(conf, outputPath2));
103 assertEquals(101, getNumResults(conf, outputPath3));
104 }
105 }