Skip to content

Commit

Permalink
Added pattern unit-tests and fixed discovered bugs
Browse files Browse the repository at this point in the history
* Integrated spock testing framework
* Attached bliss .dll for windows machines (so that tests can be run on windows machines)
* Fixed a bunch of bugs in the VICPattern implementation
* Some changes to allow correct feature test isolation

Relevant to #14
  • Loading branch information
AlexJF committed Nov 22, 2015
1 parent 9581787 commit 4e52ed5
Show file tree
Hide file tree
Showing 31 changed files with 1,719 additions and 167 deletions.
51 changes: 33 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,40 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addTestSources</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<!--<trimStackTrace>false</trimStackTrace>-->
<includes>
<include>**/*Spec.*</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -170,12 +194,6 @@
<version>${giraph.version}</version>
<scope>${giraph.scope}</scope>
</dependency>
<!-- <dependency>
<groupId>org.apache.giraph</groupId>
<artifactId>giraph-examples</artifactId>
<version>${giraph.version}</version>
<scope>${giraph.scope}</scope>
</dependency> -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
Expand All @@ -202,16 +220,13 @@
<artifactId>snakeyaml</artifactId>
<version>1.14</version>
</dependency>
<!-- <dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>3.6.2</version>
</dependency> -->
<!-- <dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections</artifactId>
<version>5.0.0</version>
</dependency> -->
<!-- Testing dependencies -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
7 changes: 7 additions & 0 deletions src/main/java/fi/tkk/ics/jbliss/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ else if (SystemUtils.IS_OS_LINUX) {
throw new UnsupportedOperationException("Library not compiled for Linux " + systemBits + " bits");
}
}
else if (SystemUtils.IS_OS_WINDOWS) {
if (systemBits == 64) {
NativeUtils.loadLibraryFromJar("/libjbliss-win.dll");
} else {
throw new UnsupportedOperationException("Library not compiled for Windows " + systemBits + " bits");
}
}
else {
throw new UnsupportedOperationException("Library not compiled for " + SystemUtils.OS_NAME);
}
Expand Down
34 changes: 20 additions & 14 deletions src/main/java/io/arabesque/conf/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import io.arabesque.optimization.OptimizationSetDescriptor;
import io.arabesque.pattern.Pattern;
import io.arabesque.pattern.VICPattern;
import io.arabesque.utils.pool.Pool;
import io.arabesque.utils.pool.PoolRegistry;
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
import org.apache.giraph.utils.ReflectionUtils;
import org.apache.hadoop.fs.Path;
Expand Down Expand Up @@ -119,7 +121,7 @@ public class Configuration<O extends Embedding> {
private MainGraph mainGraph;
private boolean isGraphEdgeLabelled;
private boolean initialized = false;
private boolean multiGraph;
private boolean isGraphMulti;

public static <C extends Configuration> C get() {
if (instance == null) {
Expand All @@ -137,6 +139,13 @@ public static void setIfUnset(Configuration configuration) {

public static void set(Configuration configuration) {
instance = configuration;

// Whenever we set configuration, reset all known pools
// Since they might have initialized things based on a previous configuration
// NOTE: This is essential for the unit tests
for (Pool pool : PoolRegistry.instance().getPools()) {
pool.reset();
}
}

public Configuration(ImmutableClassesGiraphConfiguration giraphConfiguration) {
Expand All @@ -161,16 +170,13 @@ public void initialize() {
forceGC = getBoolean(CONF_FORCE_GC, CONF_FORCE_GC_DEFAULT);
mainGraphClass = (Class<? extends MainGraph>) getClass(CONF_MAINGRAPH_CLASS, CONF_MAINGRAPH_CLASS_DEFAULT);
isGraphEdgeLabelled = getBoolean(CONF_MAINGRAPH_EDGE_LABELLED, CONF_MAINGRAPH_EDGE_LABELLED_DEFAULT);
multiGraph = getBoolean(CONF_MAINGRAPH_MULTIGRAPH, CONF_MAINGRAPH_MULTIGRAPH_DEFAULT);
isGraphMulti = getBoolean(CONF_MAINGRAPH_MULTIGRAPH, CONF_MAINGRAPH_MULTIGRAPH_DEFAULT);
optimizationSetDescriptorClass = (Class<? extends OptimizationSetDescriptor>) getClass(CONF_OPTIMIZATIONSETDESCRIPTOR_CLASS, CONF_OPTIMIZATIONSETDESCRIPTOR_CLASS_DEFAULT);
patternClass = (Class<? extends Pattern>) getClass(CONF_PATTERN_CLASS, CONF_PATTERN_CLASS_DEFAULT);

if (isGraphEdgeLabelled) {
// TODO: Make this more flexible
if (isGraphEdgeLabelled || isGraphMulti) {
patternClass = VICPattern.class;
} else {
if (multiGraph) {
throw new RuntimeException("Cannot have a multigraph without labels on edges");
}
patternClass = (Class<? extends Pattern>) getClass(CONF_PATTERN_CLASS, CONF_PATTERN_CLASS_DEFAULT);
}

computationClass = (Class<? extends Computation>) getClass(CONF_COMPUTATION_CLASS, CONF_COMPUTATION_CLASS_DEFAULT);
Expand Down Expand Up @@ -295,11 +301,11 @@ protected MainGraph createGraph() {
Constructor<? extends MainGraph> constructor;

if (useLocalGraph) {
constructor = mainGraphClass.getConstructor(java.nio.file.Path.class);
return constructor.newInstance(Paths.get(getMainGraphPath()));
constructor = mainGraphClass.getConstructor(java.nio.file.Path.class, Boolean.class, Boolean.class);
return constructor.newInstance(Paths.get(getMainGraphPath()), isGraphEdgeLabelled, isGraphMulti);
} else {
constructor = mainGraphClass.getConstructor(Path.class);
return constructor.newInstance(new Path(getMainGraphPath()));
constructor = mainGraphClass.getConstructor(Path.class, Boolean.class, Boolean.class);
return constructor.newInstance(new Path(getMainGraphPath()), isGraphEdgeLabelled, isGraphMulti);
}
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new RuntimeException("Could not load main graph", e);
Expand Down Expand Up @@ -395,8 +401,8 @@ public boolean isGraphEdgeLabelled() {
return isGraphEdgeLabelled;
}

public boolean isMultiGraph() {
return multiGraph;
public boolean isGraphMulti() {
return isGraphMulti;
}
}

2 changes: 1 addition & 1 deletion src/main/java/io/arabesque/conf/TestConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TestConfiguration(ImmutableClassesGiraphConfiguration underlyingConfigura
@Override
public MainGraph createGraph() {
try {
return new BasicMainGraph(Paths.get(getMainGraphPath()));
return new BasicMainGraph(Paths.get(getMainGraphPath()), false, false);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@ public String toOutputString() {
*/
@Override
public int getNumVerticesAddedWithExpansion() {
if (numWords == 0) {
return 0;
}

return 1;
}

@Override
public int getNumEdgesAddedWithExpansion() {
if (numWords == 0) {
return 0;
}

return numAdded[numWords - 1];
}

Expand Down
75 changes: 45 additions & 30 deletions src/main/java/io/arabesque/graph/BasicMainGraph.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.arabesque.graph;

import io.arabesque.conf.Configuration;
import io.arabesque.utils.collection.ReclaimableIntCollection;
import net.openhft.koloboke.collect.IntCollection;
import org.apache.commons.io.input.BOMInputStream;
Expand Down Expand Up @@ -31,8 +30,10 @@ public class BasicMainGraph implements MainGraph {

private boolean isEdgeLabelled;
private boolean isMultiGraph;
private String name;

private void init() {
private void init(String name, boolean isEdgeLabelled, boolean isMultiGraph) {
this.name = name;
long start = 0;

if (LOG.isInfoEnabled()) {
Expand All @@ -47,19 +48,15 @@ private void init() {

reset();

Configuration conf = Configuration.get();

isEdgeLabelled = conf.isGraphEdgeLabelled();
isMultiGraph = conf.isMultiGraph();
this.isEdgeLabelled = isEdgeLabelled;
this.isMultiGraph = isMultiGraph;

if (LOG.isInfoEnabled()) {
LOG.info("Done in " + (System.currentTimeMillis() - start));
}
}

private void init(Object path) throws IOException {
init();

long start = 0;

if (LOG.isInfoEnabled()) {
Expand Down Expand Up @@ -158,17 +155,23 @@ private void ensureCanStoreNewEdge() {
ensureCanStoreNewEdges(1);
}

public BasicMainGraph() {
init();
public BasicMainGraph(String name) {
this(name, false, false);
}

public BasicMainGraph(String name, boolean isEdgeLabelled, boolean isMultiGraph) {
init(name, isEdgeLabelled, isMultiGraph);
}

public BasicMainGraph(Path filePath)
public BasicMainGraph(Path filePath, boolean isEdgeLabelled, boolean isMultiGraph)
throws IOException {
this(filePath.getFileName().toString(), isEdgeLabelled, isMultiGraph);
init(filePath);
}

public BasicMainGraph(org.apache.hadoop.fs.Path hdfsPath)
public BasicMainGraph(org.apache.hadoop.fs.Path hdfsPath, boolean isEdgeLabelled, boolean isMultiGraph)
throws IOException {
this(hdfsPath.getName(), isEdgeLabelled, isMultiGraph);
init(hdfsPath);
}

Expand Down Expand Up @@ -339,10 +342,14 @@ protected void readFromInputStream(InputStream is) {
}
}

int vertexId = parseVertex(tokenizer);
Vertex vertex = parseVertex(tokenizer);
addVertex(vertex);

int vertexId = vertex.getVertexId();

while (tokenizer.hasMoreTokens()) {
parseEdge(tokenizer, vertexId);
Edge edge = parseEdge(tokenizer, vertexId);
addEdge(edge);
}

line = reader.readLine();
Expand All @@ -354,36 +361,31 @@ protected void readFromInputStream(InputStream is) {
}
}

protected void parseEdge(StringTokenizer tokenizer, int vertexId) {
protected Edge parseEdge(StringTokenizer tokenizer, int vertexId) {
int neighborId = Integer.parseInt(tokenizer.nextToken());

Edge edge;

if (!isEdgeLabelled) {
edge = createEdge(vertexId, neighborId);
if (isEdgeLabelled) {
int edgeLabel = Integer.parseInt(tokenizer.nextToken());
return createEdge(vertexId, neighborId, edgeLabel);
}
else {
int edgeLabel = Integer.parseInt(tokenizer.nextToken());

edge = createEdge(vertexId, neighborId, edgeLabel);
return createEdge(vertexId, neighborId);
}

addEdge(edge);
}

protected int parseVertex(StringTokenizer tokenizer) {
protected Vertex parseVertex(StringTokenizer tokenizer) {
int vertexId = Integer.parseInt(tokenizer.nextToken());
int vertexLabel = Integer.parseInt(tokenizer.nextToken());

Vertex vertex = createVertex(vertexId, vertexLabel);

addVertex(vertex);

return vertexId;
return createVertex(vertexId, vertexLabel);
}

@Override
public String toString() {
return getName();
}

public String toDetailedString() {
return "Vertices: " + Arrays.toString(vertexIndexF) + "\n Edges: " + Arrays.toString(edgeIndexF);
}

Expand Down Expand Up @@ -443,4 +445,17 @@ public IntCollection getVertexNeighbours(int vertexId) {
return vertexNeighbourhood.getNeighbourVertices();
}

@Override
public boolean isEdgeLabelled() {
return isEdgeLabelled;
}

@Override
public boolean isMultiGraph() {
return isMultiGraph;
}

public String getName() {
return name;
}
}
4 changes: 4 additions & 0 deletions src/main/java/io/arabesque/graph/MainGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public interface MainGraph {
VertexNeighbourhood getVertexNeighbourhood(int vertexId);

IntCollection getVertexNeighbours(int vertexId);

boolean isEdgeLabelled();

boolean isMultiGraph();
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ public VertexNeighbourhood getVertexNeighbourhood(int vertexId) {
public IntCollection getVertexNeighbours(int vertexId) {
return orderedNeighbours[vertexId];
}

@Override
public boolean isEdgeLabelled() {
return underlyingMainGraph.isEdgeLabelled();
}

@Override
public boolean isMultiGraph() {
return underlyingMainGraph.isMultiGraph();
}
}
Loading

0 comments on commit 4e52ed5

Please sign in to comment.