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 */18package org.apache.giraph.io.gora;
1920importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_DATASTORE_CLASS;
21importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_END_KEY;
22importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_KEYS_FACTORY_CLASS;
23importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_KEY_CLASS;
24importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_PERSISTENT_CLASS;
25importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_START_KEY;
26importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_OUTPUT_DATASTORE_CLASS;
27importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_OUTPUT_KEY_CLASS;
28importstatic org.apache.giraph.io.gora.constants.GiraphGoraConstants.GIRAPH_GORA_OUTPUT_PERSISTENT_CLASS;
2930import java.io.IOException;
3132import org.apache.giraph.conf.GiraphConfiguration;
33import org.apache.giraph.graph.BasicComputation;
34import org.apache.giraph.graph.Vertex;
35import org.apache.giraph.utils.InternalVertexRunner;
36import org.apache.hadoop.io.DoubleWritable;
37import org.apache.hadoop.io.FloatWritable;
38import org.apache.hadoop.io.LongWritable;
39import org.junit.Assert;
40import org.junit.Test;
4142/**43 * Test class for Gora edge output formats.44 */45publicclassTestGoraEdgeOutputFormat {
4647 @Test
48publicvoid getWritingDb() throws Exception {
49 Iterable<String> results;
50 GiraphConfiguration conf = new GiraphConfiguration();
51// Parameters for input52 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 output67 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 }
7677/*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 */81publicstaticclassEmptyComputation82extends BasicComputation<LongWritable, DoubleWritable,
83 FloatWritable, LongWritable> {
8485 @Override
86publicvoid compute(
87 Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
88 Iterable<LongWritable> messages) throws IOException {
89 Assert.assertNotNull(vertex);
90 vertex.voteToHalt();
91 }
92 }
93 }