This project has retired. For details please refer to its Attic page.
TestAutoCheckpoint 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;
20  
21  import org.apache.giraph.conf.GiraphConfiguration;
22  import org.apache.giraph.conf.GiraphConstants;
23  import org.apache.giraph.examples.SimpleCheckpoint;
24  import org.apache.giraph.examples.SimpleSuperstepComputation.SimpleSuperstepVertexInputFormat;
25  import org.apache.giraph.examples.SimpleSuperstepComputation.SimpleSuperstepVertexOutputFormat;
26  import org.apache.giraph.job.GiraphJob;
27  import org.apache.hadoop.fs.Path;
28  import org.junit.Test;
29  
30  import java.io.IOException;
31  
32  import static org.junit.Assert.assertTrue;
33  
34  /**
35   * Unit test for automated checkpoint restarting
36   */
37  public class TestAutoCheckpoint extends BspCase {
38  
39    public TestAutoCheckpoint() {
40      super(TestAutoCheckpoint.class.getName());
41    }
42  
43    /**
44     * Run a job that requires checkpointing and will have a worker crash
45     * and still recover from a previous checkpoint.
46     *
47     * @throws IOException
48     * @throws ClassNotFoundException
49     * @throws InterruptedException
50     */
51    @Test
52    public void testSingleFault()
53      throws IOException, InterruptedException, ClassNotFoundException {
54      if (!runningInDistributedMode()) {
55        System.out.println(
56            "testSingleFault: Ignore this test in local mode.");
57        return;
58      }
59      Path outputPath = getTempPath(getCallingMethodName());
60      GiraphConfiguration conf = new GiraphConfiguration();
61      conf.setComputationClass(
62          SimpleCheckpoint.SimpleCheckpointComputation.class);
63      conf.setWorkerContextClass(
64          SimpleCheckpoint.SimpleCheckpointVertexWorkerContext.class);
65      conf.setMasterComputeClass(
66          SimpleCheckpoint.SimpleCheckpointVertexMasterCompute.class);
67      conf.setVertexInputFormatClass(SimpleSuperstepVertexInputFormat.class);
68      conf.setVertexOutputFormatClass(SimpleSuperstepVertexOutputFormat.class);
69      conf.setBoolean(SimpleCheckpoint.ENABLE_FAULT, true);
70      conf.setInt("mapred.map.max.attempts", 4);
71      // Trigger failure faster
72      conf.setInt("mapred.task.timeout", 10000);
73      conf.setMaxMasterSuperstepWaitMsecs(10000);
74      conf.setEventWaitMsecs(1000);
75      conf.setCheckpointFrequency(2);
76      GiraphConstants.CHECKPOINT_DIRECTORY.set(conf,
77          getTempPath("_singleFaultCheckpoints").toString());
78      GiraphConstants.CLEANUP_CHECKPOINTS_AFTER_SUCCESS.set(conf, false);
79      GiraphConstants.ZOOKEEPER_SESSION_TIMEOUT.set(conf, 10000);
80      GiraphConstants.ZOOKEEPER_MIN_SESSION_TIMEOUT.set(conf, 10000);
81      GiraphJob job = prepareJob(getCallingMethodName(), conf, outputPath);
82      assertTrue(job.run(true));
83    }
84  }