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.Lists;
22import org.apache.hadoop.io.DoubleWritable;
23import org.apache.hadoop.io.LongWritable;
24import org.junit.Before;
25import org.junit.Test;
2627import java.util.Collection;
28import java.util.List;
2930importstatic org.apache.giraph.graph.TestVertexAndEdges.instantiateOutEdges;
31importstatic org.junit.Assert.assertEquals;
32importstatic org.junit.Assert.assertNull;
3334/**35 * Tests {@link StrictRandomAccessOutEdges} implementations.36 */37publicclassTestStrictRandomAccessEdges {
38/** {@link StrictRandomAccessOutEdges} classes to be tested. */39private Collection<Class<? extends StrictRandomAccessOutEdges>>
40 edgesClasses = Lists.newArrayList();
4142 @Before
43publicvoid setUp() {
44 edgesClasses.add(HashMapEdges.class);
45 edgesClasses.add(LongDoubleHashMapEdges.class);
46 }
4748/**49 * Ensures that all {@link StrictRandomAccessOutEdges} implementations50 * correctly return edge values.51 */52 @Test
53publicvoid testParallelEdges() {
54for (Class<? extends StrictRandomAccessOutEdges> edgesClass :
55 edgesClasses) {
56 testParallelEdgesClass(edgesClass);
57 }
58 }
5960privatevoid testParallelEdgesClass(
61 Class<? extends StrictRandomAccessOutEdges> edgesClass) {
62 StrictRandomAccessOutEdges<LongWritable, DoubleWritable> edges =
63 (StrictRandomAccessOutEdges<LongWritable, DoubleWritable>)
64 instantiateOutEdges(edgesClass);
6566// Initial edges list contains parallel edges.67 List<Edge<LongWritable, DoubleWritable>> initialEdges = Lists.newArrayList(
68 EdgeFactory.create(new LongWritable(1), new DoubleWritable(1)),
69 EdgeFactory.create(new LongWritable(2), new DoubleWritable(2)),
70 EdgeFactory.create(new LongWritable(3), new DoubleWritable(3)),
71 EdgeFactory.create(new LongWritable(2), new DoubleWritable(20)));
7273 edges.initialize(initialEdges);
7475 assertEquals(3.0, edges.getEdgeValue(new LongWritable(3)).get(), 0.0);
76 assertNull(edges.getEdgeValue(new LongWritable(55)));
7778 edges.setEdgeValue(new LongWritable(2), new DoubleWritable(33.0));
79 assertEquals(33.0, edges.getEdgeValue(new LongWritable(2)).get(), 0);
80 }
81 }