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;
3233/**34 * Tests {@link OutEdges} implementations that allow parallel edges.35 */36publicclassTestMultiGraphEdges {
37/** {@link OutEdges} classes to be tested. */38private Collection<Class<? extends OutEdges>> edgesClasses =
39 Lists.newArrayList();
4041 @Before
42publicvoid setUp() {
43 edgesClasses.add(ByteArrayEdges.class);
44 edgesClasses.add(ArrayListEdges.class);
45 edgesClasses.add(HashMultimapEdges.class);
46 edgesClasses.add(LongDoubleArrayEdges.class);
47 }
4849/**50 * Ensures that all multigraph {@link OutEdges} implementations allow51 * parallel edges.52 */53 @Test
54publicvoid testParallelEdges() {
55for (Class<? extends OutEdges> edgesClass : edgesClasses) {
56 testParallelEdgesClass(edgesClass);
57 }
58 }
5960privatevoid testParallelEdgesClass(
61 Class<? extends OutEdges> edgesClass) {
62 OutEdges<LongWritable, DoubleWritable> edges =
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// The parallel edges should still be there.75 assertEquals(4, edges.size());
7677// Adding a parallel edge should increase the number of edges.78 edges.add(EdgeFactory.create(new LongWritable(3), new DoubleWritable(30)));
79 assertEquals(5, edges.size());
8081// Removing edges pointing to a given vertex should remove all parallel82// edges.83 edges.remove(new LongWritable(2));
84 assertEquals(3, edges.size());
85 }
86 }