-
Notifications
You must be signed in to change notification settings - Fork 105
/
GraphProcessorTest.java
79 lines (63 loc) · 2.35 KB
/
GraphProcessorTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package org.mazerunner.core.processor;
import junit.framework.TestCase;
import org.apache.spark.api.java.JavaSparkContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mazerunner.core.algorithms;
import org.mazerunner.core.config.ConfigurationLoader;
import org.mazerunner.core.hdfs.FileUtil;
import org.mazerunner.core.models.ProcessorMessage;
import org.mazerunner.core.models.ProcessorMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GraphProcessorTest extends TestCase {
JavaSparkContext javaSparkContext;
@Before
public void setUp() {
ConfigurationLoader.testPropertyAccess = true;
javaSparkContext = GraphProcessor.initializeSparkContext();
}
@After
public void tearDown() {
GraphProcessor.javaSparkContext.close();
}
@Test
public void testProcessEdgeList() throws Exception {
ConfigurationLoader.testPropertyAccess = true;
// Create test path
String path = ConfigurationLoader.getInstance().getHadoopHdfsUri() + "/test/edgeList.txt";
// Test writing the PageRank result to HDFS path
FileUtil.writeListFile(path, new ArrayList<>(Arrays.asList(
"0 1\n",
"1 3\n",
"3 0"
)).iterator());
GraphProcessor.processEdgeList(new ProcessorMessage(path, GraphProcessor.TRIANGLE_COUNT, ProcessorMode.Unpartitioned));
}
@Test
public void testShortestPaths() throws Exception {
ConfigurationLoader.testPropertyAccess = true;
List<String> nodeList = Arrays.asList(
"0 1\n",
"1 2\n",
"2 3\n",
"3 4\n",
"4 5\n",
"4 7\n",
"7 8\n",
"8 9\n",
"7 10\n",
"10 8\n",
"8 11\n",
"11 12\n",
"12 13");
// Create test path
String path = ConfigurationLoader.getInstance().getHadoopHdfsUri() + "/test/edgeList.txt";
// Test writing the PageRank result to HDFS path
FileUtil.writeListFile(path, nodeList.iterator());
Iterable<String> results = algorithms.closenessCentrality(GraphProcessor.javaSparkContext.sc(), path);
results.iterator().forEachRemaining(System.out::print);
}
}