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.edge;
2021import com.google.common.collect.Iterables;
22import com.google.common.collect.Lists;
23import org.apache.hadoop.io.DoubleWritable;
24import org.apache.hadoop.io.LongWritable;
25import org.junit.Before;
26import org.junit.Test;
2728import java.util.Collection;
29import java.util.List;
3031importstatic org.apache.giraph.graph.TestVertexAndEdges.instantiateOutEdges;
32importstatic org.junit.Assert.assertEquals;
3334/**35 * Tests {@link MultiRandomAccessOutEdges} implementations.36 */37publicclassTestMultiRandomAccessEdges {
38/** {@link MultiRandomAccessOutEdges} classes to be tested. */39private Collection<Class<? extends MultiRandomAccessOutEdges>>
40 edgesClasses = Lists.newArrayList();
4142 @Before
43publicvoid setUp() {
44 edgesClasses.add(HashMultimapEdges.class);
45 }
4647/**48 * Ensures that all {@link MultiRandomAccessOutEdges} implementations49 * correctly return edge values.50 */51 @Test
52publicvoid testParallelEdges() {
53for (Class<? extends MultiRandomAccessOutEdges> edgesClass :
54 edgesClasses) {
55 testParallelEdgesClass(edgesClass);
56 }
57 }
5859privatevoid testParallelEdgesClass(
60 Class<? extends MultiRandomAccessOutEdges> edgesClass) {
61 MultiRandomAccessOutEdges<LongWritable, DoubleWritable> edges =
62 (MultiRandomAccessOutEdges<LongWritable, DoubleWritable>)
63 instantiateOutEdges(edgesClass);
6465// Initial edges list contains parallel edges.66 List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList(
67 EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)),
68 EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)),
69 EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)),
70 EdgeFactory.create(new LongWritable(2), new DoubleWritable(20)));
7172 edges.initialize(initialEdges);
7374 assertEquals(2,
75 Iterables.size(edges.getAllEdgeValues(new LongWritable(2))));
76 assertEquals(1,
77 Iterables.size(edges.getAllEdgeValues(new LongWritable(1))));
78 assertEquals(0,
79 Iterables.size(edges.getAllEdgeValues(new LongWritable(42))));
80 }
81 }