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  package org.apache.giraph.io.gora;
19  
20  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_DATASTORE_CLASS;
21  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_END_KEY;
22  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_KEYS_FACTORY_CLASS;
23  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_KEY_CLASS;
24  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_PERSISTENT_CLASS;
25  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_START_KEY;
26  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_OUTPUT_DATASTORE_CLASS;
27  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_OUTPUT_KEY_CLASS;
28  import static org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_OUTPUT_PERSISTENT_CLASS;
29  
30  import java.io.IOException;
31  
32  import org.apache.giraph.conf.GiraphConfiguration;
33  import org.apache.giraph.graph.BasicComputation;
34  import org.apache.giraph.graph.Vertex;
35  import org.apache.giraph.utils.InternalVertexRunner;
36  import org.apache.hadoop.io.DoubleWritable;
37  import org.apache.hadoop.io.FloatWritable;
38  import org.apache.hadoop.io.LongWritable;
39  import org.junit.Assert;
40  import org.junit.Test;
41  
42  /**
43   * Test class for Gora edge output formats.
44   */
45  public class TestGoraEdgeOutputFormat {
46  
47    @Test
48    public void getWritingDb() throws Exception {
49      Iterable<String>    results;
50      GiraphConfiguration conf    = new GiraphConfiguration();
51      // Parameters for input
52      GIRAPH_GORA_DATASTORE_CLASS.
53      set(conf, "org.apache.gora.memory.store.MemStore");
54      GIRAPH_GORA_KEYS_FACTORY_CLASS.
55      set(conf,"org.apache.giraph.io.gora.utils.DefaultKeyFactory");
56      GIRAPH_GORA_KEY_CLASS.set(conf,"java.lang.String");
57      GIRAPH_GORA_PERSISTENT_CLASS.
58      set(conf,"org.apache.giraph.io.gora.generated.GEdge");
59      GIRAPH_GORA_START_KEY.set(conf,"1");
60      GIRAPH_GORA_END_KEY.set(conf,"4");
61      conf.set("io.serializations",
62          "org.apache.hadoop.io.serializer.WritableSerialization," +
63          "org.apache.hadoop.io.serializer.JavaSerialization");
64      conf.setComputationClass(EmptyComputation.class);
65      conf.setEdgeInputFormatClass(GoraTestEdgeInputFormat.class);
66      // Parameters for output
67      GIRAPH_GORA_OUTPUT_DATASTORE_CLASS.
68      set(conf, "org.apache.gora.memory.store.MemStore");
69      GIRAPH_GORA_OUTPUT_KEY_CLASS.set(conf, "java.lang.String");
70      GIRAPH_GORA_OUTPUT_PERSISTENT_CLASS.
71      set(conf,"org.apache.giraph.io.gora.generated.GEdgeResult");
72      conf.setEdgeOutputFormatClass(GoraTestEdgeOutputFormat.class);
73      results = InternalVertexRunner.run(conf, new String[0], new String[0]);
74      Assert.assertNotNull(results);
75    }
76  
77    /*
78    Test compute method that sends each edge a notification of its parents.
79    The test set only has a 1-1 parent-to-child ratio for this unit test.
80     */
81    public static class EmptyComputation
82      extends BasicComputation<LongWritable, DoubleWritable,
83      FloatWritable, LongWritable> {
84  
85      @Override
86      public void compute(
87          Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
88          Iterable<LongWritable> messages) throws IOException {
89        Assert.assertNotNull(vertex);
90        vertex.voteToHalt();
91      }
92    }
93  }