This project has retired. For details please refer to its
Attic page.
TestSrcIdDstIdEdgeValueTextOutputFormat xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.io;
20
21 import static org.apache.giraph.conf.GiraphConstants.GIRAPH_TEXT_OUTPUT_FORMAT_REVERSE;
22 import static org.apache.giraph.conf.GiraphConstants.GIRAPH_TEXT_OUTPUT_FORMAT_SEPARATOR;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
26
27 import java.io.IOException;
28
29 import org.apache.giraph.conf.GiraphConfiguration;
30 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
31 import org.apache.giraph.edge.Edge;
32 import org.apache.giraph.io.formats.SrcIdDstIdEdgeValueTextOutputFormat;
33 import org.apache.giraph.utils.NoOpComputation;
34 import org.apache.hadoop.io.DoubleWritable;
35 import org.apache.hadoop.io.LongWritable;
36 import org.apache.hadoop.io.Text;
37 import org.apache.hadoop.mapreduce.RecordWriter;
38 import org.apache.hadoop.mapreduce.TaskAttemptContext;
39 import org.junit.Before;
40 import org.junit.Test;
41
42 public class TestSrcIdDstIdEdgeValueTextOutputFormat
43 extends SrcIdDstIdEdgeValueTextOutputFormat<LongWritable,
44 LongWritable, LongWritable> {
45
46 private ImmutableClassesGiraphConfiguration<
47 LongWritable, LongWritable, LongWritable> conf;
48
49
50
51 public static class DummyComputation extends NoOpComputation<Text,
52 DoubleWritable, DoubleWritable, DoubleWritable> { }
53
54 @Before
55 public void setUp() {
56 GiraphConfiguration giraphConfiguration = new GiraphConfiguration();
57 giraphConfiguration.setComputationClass(DummyComputation.class);
58 conf =
59 new ImmutableClassesGiraphConfiguration<LongWritable, LongWritable,
60 LongWritable>(giraphConfiguration);
61 }
62
63 @Test
64 public void testHappyPath() throws IOException, InterruptedException {
65 Text expected = new Text("0\t1\t5");
66
67 checkSrcIdDstIdEdgeValueWorker(expected);
68 }
69
70 @Test
71 public void testReverseIdAndValue() throws IOException, InterruptedException {
72 GIRAPH_TEXT_OUTPUT_FORMAT_REVERSE.set(this.conf, true);
73 Text expected = new Text("5\t1\t0");
74
75 checkSrcIdDstIdEdgeValueWorker(expected);
76 }
77
78 @Test
79 public void testWithDifferentDelimiter() throws IOException,
80 InterruptedException {
81 GIRAPH_TEXT_OUTPUT_FORMAT_SEPARATOR.set(this.conf, "->");
82 Text expected = new Text("0->1->5");
83
84 checkSrcIdDstIdEdgeValueWorker(expected);
85 }
86
87 private void checkSrcIdDstIdEdgeValueWorker(Text expected)
88 throws IOException, InterruptedException {
89
90 TaskAttemptContext tac = mock(TaskAttemptContext.class);
91 when(tac.getConfiguration()).thenReturn(conf);
92
93 Edge edge = mock(Edge.class);
94
95 when(edge.getTargetVertexId()).thenReturn(new LongWritable(1));
96 when(edge.getValue()).thenReturn(new LongWritable(5));
97
98 final RecordWriter<Text, Text> tw = mock(RecordWriter.class);
99 SrcIdDstIdEdgeValueEdgeWriter writer = new SrcIdDstIdEdgeValueEdgeWriter() {
100 @Override
101 protected RecordWriter<Text, Text> createLineRecordWriter(
102 TaskAttemptContext context) throws IOException, InterruptedException {
103
104 return tw;
105 }
106 };
107
108 writer.setConf(conf);
109 writer.initialize(tac);
110 writer.writeEdge(new LongWritable(0), new LongWritable(0), edge);
111
112 verify(tw).write(expected, null);
113 }
114 }