diff --git a/java/server/src/main/java/org/softwareheritage/graph/App.java b/java/server/src/main/java/org/softwareheritage/graph/App.java index a191203..0aeb17c 100644 --- a/java/server/src/main/java/org/softwareheritage/graph/App.java +++ b/java/server/src/main/java/org/softwareheritage/graph/App.java @@ -1,199 +1,199 @@ package org.softwareheritage.graph; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.martiansoftware.jsap.FlaggedOption; import com.martiansoftware.jsap.JSAP; import com.martiansoftware.jsap.JSAPException; import com.martiansoftware.jsap.JSAPResult; import com.martiansoftware.jsap.Parameter; import com.martiansoftware.jsap.SimpleJSAP; import com.martiansoftware.jsap.Switch; import com.martiansoftware.jsap.UnflaggedOption; import io.javalin.Javalin; import io.javalin.http.Context; import io.javalin.plugin.json.JavalinJackson; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.algo.Stats; /** * Web framework of the swh-graph server REST API. * * @author Thibault Allançon * @version 0.0.1 * @since 0.0.1 */ public class App { /** * Main entrypoint. * * @param args command line arguments */ public static void main(String[] args) throws IOException, JSAPException { SimpleJSAP jsap = new SimpleJSAP( App.class.getName(), "Server to load and query a compressed graph representation of Software Heritage archive.", new Parameter[] { new FlaggedOption("port", JSAP.INTEGER_PARSER, "5009", JSAP.NOT_REQUIRED, 'p', "port", "Binding port of the server."), new UnflaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the compressed graph."), new Switch("timings", 't', "timings", "Show timings in API result metadata."), } ); JSAPResult config = jsap.parse(args); if (jsap.messagePrinted()) { System.exit(1); } String graphPath = config.getString("graphPath"); int port = config.getInt("port"); boolean showTimings = config.getBoolean("timings"); startServer(graphPath, port, showTimings); } /** * Loads compressed graph and starts the web server to query it. * * @param graphPath basename of the compressed graph * @param port binding port of the server * @param showTimings true if timings should be in results metadata, false otherwise */ private static void startServer(String graphPath, int port, boolean showTimings) throws IOException { Graph graph = new Graph(graphPath); Stats stats = new Stats(graphPath); // Clean up on exit Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { graph.cleanUp(); } catch (IOException e) { System.out.println("Could not clean up graph on exit: " + e); } } }); // Configure Jackson JSON to use snake case naming style ObjectMapper objectMapper = JavalinJackson.getObjectMapper(); objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); JavalinJackson.configure(objectMapper); Javalin app = Javalin.create().start(port); app.before("/stats/*", ctx -> { checkQueryStrings(ctx, ""); }); app.before("/leaves/*", ctx -> { checkQueryStrings(ctx, "direction|edges"); }); app.before("/neighbors/*", ctx -> { checkQueryStrings(ctx, "direction|edges"); }); app.before("/visit/*", ctx -> { checkQueryStrings(ctx, "direction|edges"); }); app.before("/walk/*", ctx -> { checkQueryStrings(ctx, "direction|edges|traversal"); }); app.get("/stats/", ctx -> { ctx.json(stats); }); // Graph traversal endpoints // By default the traversal is a forward DFS using all edges app.get("/leaves/:src", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); Endpoint.Output output = endpoint.leaves(src); ctx.json(formatEndpointOutput(output, showTimings)); }); app.get("/neighbors/:src", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); Endpoint.Output output = endpoint.neighbors(src); ctx.json(formatEndpointOutput(output, showTimings)); }); app.get("/visit/nodes/:src", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); Endpoint.Output output = endpoint.visitNodes(src); ctx.json(formatEndpointOutput(output, showTimings)); }); app.get("/visit/paths/:src", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); Endpoint.Output output = endpoint.visitPaths(src); ctx.json(formatEndpointOutput(output, showTimings)); }); app.get("/walk/:src/:dst", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String dstFmt = ctx.pathParam("dst"); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); String algorithm = ctx.queryParam("traversal", "dfs"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); Endpoint.Output output = endpoint.walk(src, dstFmt, algorithm); ctx.json(formatEndpointOutput(output, showTimings)); }); app.exception(IllegalArgumentException.class, (e, ctx) -> { ctx.status(400); ctx.result(e.getMessage()); }); } /** * Checks query strings names provided to the REST API. * * @param ctx Javalin HTTP request context * @param allowedFmt a regular expression describing allowed query strings names * @throws IllegalArgumentException unknown query string provided */ private static void checkQueryStrings(Context ctx, String allowedFmt) { Map> queryParamMap = ctx.queryParamMap(); for (String key : queryParamMap.keySet()) { if (!key.matches(allowedFmt)) { throw new IllegalArgumentException("Unknown query string: " + key); } } } /** * Formats endpoint result into final JSON for the REST API. *

* Removes unwanted information if necessary, such as timings (to prevent use of side channels * attacks). * * @param output endpoint operation output which needs formatting * @param showTimings true if timings should be in results metadata, false otherwise * @return final Object with desired JSON format */ private static Object formatEndpointOutput(Endpoint.Output output, boolean showTimings) { if (showTimings) { return output; } else { Map outputNoTimings = new HashMap<>(); outputNoTimings.put("result", output.result); return outputNoTimings; } } } diff --git a/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java b/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java index 1827da3..a1f124d 100644 --- a/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java +++ b/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java @@ -1,281 +1,281 @@ package org.softwareheritage.graph; import java.util.ArrayList; import org.softwareheritage.graph.Graph; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.SwhPath; import org.softwareheritage.graph.algo.Traversal; import org.softwareheritage.graph.utils.Timing; /** * REST API endpoints wrapper functions. *

* Graph operations are segmented between high-level class (this one) and the low-level class * ({@link Traversal}). The {@link Endpoint} class creates wrappers for each endpoints by performing * all the input/output node ids conversions and logging timings. * * @author Thibault Allançon * @version 0.0.1 * @since 0.0.1 * @see org.softwareheritage.graph.algo.Traversal */ public class Endpoint { /** * Wrapper class to return both the endpoint result and metadata (such as timings). */ public class Output { /** The result content itself */ public T result; /** Various metadata about the result */ public Meta meta; public Output() { this.result = null; this.meta = new Meta(); } /** * Endpoint result metadata. */ public class Meta { /** Operations timings */ public Timings timings; public Meta() { this.timings = new Timings(); } /** * Wrapper class for JSON output format. */ public class Timings { /** Time in seconds to do the traversal */ public float traversal; /** Time in seconds to convert input SWH PID to node id */ public float pid2node; /** Time in seconds to convert output node ids to SWH PIDs */ public float node2pid; } } } /** Graph where traversal endpoint is performed */ Graph graph; /** Internal traversal API */ Traversal traversal; /** * Constructor. * * @param graph the graph used for traversal endpoint * @param direction a string (either "forward" or "backward") specifying edge orientation * @param edgesFmt a formatted string describing allowed edges */ public Endpoint(Graph graph, String direction, String edgesFmt) { this.graph = graph; this.traversal = new Traversal(graph, direction, edgesFmt); } /** * Converts a list of (internal) long node ids to a list of corresponding (external) SWH PIDs. * * @param nodeIds the list of long node ids * @return a list of corresponding SWH PIDs */ - private ArrayList convertNodesToSwhIds(ArrayList nodeIds) { - ArrayList swhIds = new ArrayList<>(); + private ArrayList convertNodesToSwhPIDs(ArrayList nodeIds) { + ArrayList swhPIDs = new ArrayList<>(); for (long nodeId : nodeIds) { - swhIds.add(graph.getSwhId(nodeId)); + swhPIDs.add(graph.getSwhPID(nodeId)); } - return swhIds; + return swhPIDs; } /** * Converts a list of (internal) long node ids to the corresponding {@link SwhPath}. * * @param nodeIds the list of long node ids * @return the corresponding {@link SwhPath} * @see org.softwareheritage.graph.SwhPath */ private SwhPath convertNodesToSwhPath(ArrayList nodeIds) { SwhPath path = new SwhPath(); for (long nodeId : nodeIds) { - path.add(graph.getSwhId(nodeId)); + path.add(graph.getSwhPID(nodeId)); } return path; } /** * Converts a list of paths made of (internal) long node ids to one made of {@link SwhPath}-s. * * @param pathsNodeId the list of paths with long node ids * @return a list of corresponding {@link SwhPath} * @see org.softwareheritage.graph.SwhPath */ - private ArrayList convertPathsToSwhIds(ArrayList> pathsNodeId) { + private ArrayList convertPathsToSwhPIDs(ArrayList> pathsNodeId) { ArrayList paths = new ArrayList<>(); for (ArrayList path : pathsNodeId) { paths.add(convertNodesToSwhPath(path)); } return paths; } /** * Leaves endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} - * @return the resulting list of {@link SwhId} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @param src source node of endpoint call specified as a {@link SwhPID} + * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#leaves(long) */ - public Output leaves(SwhId src) { - Output> output = new Output<>(); + public Output leaves(SwhPID src) { + Output> output = new Output<>(); long startTime; startTime = Timing.start(); long srcNodeId = graph.getNodeId(src); output.meta.timings.pid2node = Timing.stop(startTime); startTime = Timing.start(); ArrayList nodeIds = traversal.leaves(srcNodeId); output.meta.timings.traversal = Timing.stop(startTime); startTime = Timing.start(); - output.result = convertNodesToSwhIds(nodeIds); + output.result = convertNodesToSwhPIDs(nodeIds); output.meta.timings.node2pid = Timing.stop(startTime); return output; } /** * Neighbors endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} - * @return the resulting list of {@link SwhId} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @param src source node of endpoint call specified as a {@link SwhPID} + * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#neighbors(long) */ - public Output neighbors(SwhId src) { - Output> output = new Output<>(); + public Output neighbors(SwhPID src) { + Output> output = new Output<>(); long startTime; startTime = Timing.start(); long srcNodeId = graph.getNodeId(src); output.meta.timings.pid2node = Timing.stop(startTime); startTime = Timing.start(); ArrayList nodeIds = traversal.neighbors(srcNodeId); output.meta.timings.traversal = Timing.stop(startTime); startTime = Timing.start(); - output.result = convertNodesToSwhIds(nodeIds); + output.result = convertNodesToSwhPIDs(nodeIds); output.meta.timings.node2pid = Timing.stop(startTime); return output; } /** * Walk endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} + * @param src source node of endpoint call specified as a {@link SwhPID} * @param dstFmt destination formatted string as described in the API * @param algorithm traversal algorithm used in endpoint call (either "dfs" or "bfs") * @return the resulting {@link SwhPath} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.SwhPath * @see org.softwareheritage.graph.algo.Traversal#walk */ - public Output walk(SwhId src, String dstFmt, String algorithm) { + public Output walk(SwhPID src, String dstFmt, String algorithm) { Output output = new Output<>(); long startTime; startTime = Timing.start(); long srcNodeId = graph.getNodeId(src); output.meta.timings.pid2node = Timing.stop(startTime); ArrayList nodeIds = new ArrayList(); - // Destination is either a SWH ID or a node type + // Destination is either a SWH PID or a node type try { - SwhId dstSwhId = new SwhId(dstFmt); - long dstNodeId = graph.getNodeId(dstSwhId); + SwhPID dstSwhPID = new SwhPID(dstFmt); + long dstNodeId = graph.getNodeId(dstSwhPID); startTime = Timing.start(); nodeIds = traversal.walk(srcNodeId, dstNodeId, algorithm); output.meta.timings.traversal = Timing.stop(startTime); } catch (IllegalArgumentException ignored1) { try { Node.Type dstType = Node.Type.fromStr(dstFmt); startTime = Timing.start(); nodeIds = traversal.walk(srcNodeId, dstType, algorithm); output.meta.timings.traversal = Timing.stop(startTime); } catch (IllegalArgumentException ignored2) { } } startTime = Timing.start(); output.result = convertNodesToSwhPath(nodeIds); output.meta.timings.node2pid = Timing.stop(startTime); return output; } /** * VisitNodes endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} - * @return the resulting list of {@link SwhId} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @param src source node of endpoint call specified as a {@link SwhPID} + * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#visitNodes(long) */ - public Output visitNodes(SwhId src) { - Output> output = new Output<>(); + public Output visitNodes(SwhPID src) { + Output> output = new Output<>(); long startTime; startTime = Timing.start(); long srcNodeId = graph.getNodeId(src); output.meta.timings.pid2node = Timing.stop(startTime); startTime = Timing.start(); ArrayList nodeIds = traversal.visitNodes(srcNodeId); output.meta.timings.traversal = Timing.stop(startTime); startTime = Timing.start(); - output.result = convertNodesToSwhIds(nodeIds); + output.result = convertNodesToSwhPIDs(nodeIds); output.meta.timings.node2pid = Timing.stop(startTime); return output; } /** * VisitPaths endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} + * @param src source node of endpoint call specified as a {@link SwhPID} * @return the resulting list of {@link SwhPath} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.SwhPath * @see org.softwareheritage.graph.algo.Traversal#visitPaths(long) */ - public Output visitPaths(SwhId src) { + public Output visitPaths(SwhPID src) { Output> output = new Output<>(); long startTime; startTime = Timing.start(); long srcNodeId = graph.getNodeId(src); output.meta.timings.pid2node = Timing.stop(startTime); startTime = Timing.start(); ArrayList> paths = traversal.visitPaths(srcNodeId); output.meta.timings.traversal = Timing.stop(startTime); startTime = Timing.start(); - output.result = convertPathsToSwhIds(paths); + output.result = convertPathsToSwhPIDs(paths); output.meta.timings.node2pid = Timing.stop(startTime); return output; } } diff --git a/java/server/src/main/java/org/softwareheritage/graph/Graph.java b/java/server/src/main/java/org/softwareheritage/graph/Graph.java index 46ed699..0186839 100644 --- a/java/server/src/main/java/org/softwareheritage/graph/Graph.java +++ b/java/server/src/main/java/org/softwareheritage/graph/Graph.java @@ -1,196 +1,196 @@ package org.softwareheritage.graph; import java.io.IOException; import it.unimi.dsi.big.webgraph.BVGraph; import it.unimi.dsi.big.webgraph.LazyLongIterator; import org.softwareheritage.graph.Node; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.backend.NodeIdMap; import org.softwareheritage.graph.backend.NodeTypesMap; /** * Main class storing the compressed graph and node id mappings. *

* The compressed graph is stored using the WebGraph * ecosystem. Additional mappings are necessary because Software Heritage uses string based persistent * identifiers (PID) while WebGraph uses integers internally. These two mappings (long id ↔ * PID) are used for the input (users refer to the graph using PID) and the output (convert back to * PID for users results). However, since graph traversal can be restricted depending on the node * type (see {@link AllowedEdges}), a long id → node type map is stored as well to avoid a full * PID lookup. * * @author Thibault Allançon * @version 0.0.1 * @since 0.0.1 * @see org.softwareheritage.graph.AllowedEdges * @see org.softwareheritage.graph.NodeIdMap; * @see org.softwareheritage.graph.NodeTypesMap; */ public class Graph { /** File extension for the SWH PID to long node id map */ public static final String PID_TO_NODE = ".pid2node.csv"; /** File extension for the long node id to SWH PID map */ public static final String NODE_TO_PID = ".node2pid.csv"; /** File extension for the long node id to node typ map */ public static final String NODE_TO_TYPE = ".node2type.map"; /** Compressed graph stored as a {@link it.unimi.dsi.big.webgraph.BVGraph} */ BVGraph graph; /** Transposed compressed graph (used for backward traversals) */ BVGraph graphTransposed; /** Path and basename of the compressed graph */ String path; /** Mapping long id ↔ SWH PIDs */ NodeIdMap nodeIdMap; /** Mapping long id → node types */ NodeTypesMap nodeTypesMap; /** * Constructor. * * @param path path and basename of the compressed graph to load */ public Graph(String path) throws IOException { this.graph = BVGraph.load(path); this.graphTransposed = BVGraph.load(path + "-transposed"); this.path = path; this.nodeIdMap = new NodeIdMap(path, getNbNodes()); this.nodeTypesMap = new NodeTypesMap(path); } /** * Cleans up graph resources after use. */ public void cleanUp() throws IOException { nodeIdMap.close(); } /** * Returns the graph full path. * * @return graph full path */ public String getPath() { return path; } /** - * Converts {@link SwhId} node to long. + * Converts {@link SwhPID} node to long. * - * @param swhId node specified as a {@link SwhId} + * @param swhPID node specified as a {@link SwhPID} * @return internal long node id - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID */ - public long getNodeId(SwhId swhId) { - return nodeIdMap.getNodeId(swhId); + public long getNodeId(SwhPID swhPID) { + return nodeIdMap.getNodeId(swhPID); } /** - * Converts long id node to {@link SwhId}. + * Converts long id node to {@link SwhPID}. * * @param nodeId node specified as a long id * @return external SWH PID - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID */ - public SwhId getSwhId(long nodeId) { - return nodeIdMap.getSwhId(nodeId); + public SwhPID getSwhPID(long nodeId) { + return nodeIdMap.getSwhPID(nodeId); } /** * Returns node type. * * @param nodeId node specified as a long id * @return corresponding node type * @see org.softwareheritage.graph.Node.Type */ public Node.Type getNodeType(long nodeId) { return nodeTypesMap.getType(nodeId); } /** * Returns number of nodes in the graph. * * @return number of nodes in the graph */ public long getNbNodes() { return graph.numNodes(); } /** * Returns number of edges in the graph. * * @return number of edges in the graph */ public long getNbEdges() { return graph.numArcs(); } /** * Returns lazy iterator of successors of a node. * * @param nodeId node specified as a long id * @return lazy iterator of successors of the node, specified as a WebGraph LazyLongIterator */ public LazyLongIterator successors(long nodeId) { return graph.successors(nodeId); } /** * Returns the outdegree of a node. * * @param nodeId node specified as a long id * @return outdegree of a node */ public long outdegree(long nodeId) { return graph.outdegree(nodeId); } /** * Returns lazy iterator of predecessors of a node. * * @param nodeId node specified as a long id * @return lazy iterator of predecessors of the node, specified as a WebGraph LazyLongIterator */ public LazyLongIterator predecessors(long nodeId) { return graphTransposed.successors(nodeId); } /** * Returns the indegree of a node. * * @param nodeId node specified as a long id * @return indegree of a node */ public long indegree(long nodeId) { return graphTransposed.outdegree(nodeId); } /** * Returns the degree of a node, depending on graph orientation. * * @param nodeId node specified as a long id * @param useTransposed boolean value to use transposed graph * @return degree of a node */ public long degree(long nodeId, boolean useTransposed) { return (useTransposed) ? indegree(nodeId) : outdegree(nodeId); } /** * Returns the neighbors of a node (as a lazy iterator), depending on graph orientation. * * @param nodeId node specified as a long id * @param useTransposed boolean value to use transposed graph * @return lazy iterator of neighbors of the node, specified as a WebGraph LazyLongIterator */ public LazyLongIterator neighbors(long nodeId, boolean useTransposed) { return (useTransposed) ? predecessors(nodeId) : successors(nodeId); } } diff --git a/java/server/src/main/java/org/softwareheritage/graph/SwhId.java b/java/server/src/main/java/org/softwareheritage/graph/SwhPID.java similarity index 71% rename from java/server/src/main/java/org/softwareheritage/graph/SwhId.java rename to java/server/src/main/java/org/softwareheritage/graph/SwhPID.java index d89dd69..3a847c2 100644 --- a/java/server/src/main/java/org/softwareheritage/graph/SwhId.java +++ b/java/server/src/main/java/org/softwareheritage/graph/SwhPID.java @@ -1,97 +1,97 @@ package org.softwareheritage.graph; import com.fasterxml.jackson.annotation.JsonValue; import org.softwareheritage.graph.Node; /** * A Software Heritage PID, see persistent * identifier documentation. * * @author Thibault Allançon * @version 0.0.1 * @since 0.0.1 */ -public class SwhId { +public class SwhPID { /** Fixed hash length of the PID */ public static final int HASH_LENGTH = 40; /** Full PID as a string */ - String swhId; + String swhPID; /** PID node type */ Node.Type type; /** PID hex-encoded SHA1 hash */ String hash; /** * Constructor. * - * @param swhId full PID as a string + * @param swhPID full PID as a string */ - public SwhId(String swhId) { - this.swhId = swhId; + public SwhPID(String swhPID) { + this.swhPID = swhPID; // PID format: 'swh:1:type:hash' - String[] parts = swhId.split(":"); + String[] parts = swhPID.split(":"); if (parts.length != 4 || !parts[0].equals("swh") || !parts[1].equals("1")) { - throw new IllegalArgumentException("Expected SWH ID format to be 'swh:1:type:hash', got: " + swhId); + throw new IllegalArgumentException("Expected SWH PID format to be 'swh:1:type:hash', got: " + swhPID); } this.type = Node.Type.fromStr(parts[2]); this.hash = parts[3]; if (!hash.matches("[0-9a-f]{" + HASH_LENGTH + "}")) { - throw new IllegalArgumentException("Wrong SWH ID hash format in: " + swhId); + throw new IllegalArgumentException("Wrong SWH PID hash format in: " + swhPID); } } @Override public boolean equals(Object otherObj) { if (otherObj == this) return true; - if (!(otherObj instanceof SwhId)) return false; + if (!(otherObj instanceof SwhPID)) return false; - SwhId other = (SwhId) otherObj; - return swhId.equals(other.getSwhId()); + SwhPID other = (SwhPID) otherObj; + return swhPID.equals(other.getSwhPID()); } @Override public int hashCode() { - return swhId.hashCode(); + return swhPID.hashCode(); } @Override public String toString() { - return swhId; + return swhPID; } /** * Returns full PID as a string. * * @return full PID string */ @JsonValue - public String getSwhId() { - return swhId; + public String getSwhPID() { + return swhPID; } /** * Returns PID node type. * * @return PID corresponding {@link Node.Type} * @see org.softwareheritage.graph.Node.Type */ public Node.Type getType() { return type; } /** * Returns PID hex-encoded SHA1 hash. * * @return PID string hash */ public String getHash() { return hash; } } diff --git a/java/server/src/main/java/org/softwareheritage/graph/SwhPath.java b/java/server/src/main/java/org/softwareheritage/graph/SwhPath.java index f77c835..fd3385d 100644 --- a/java/server/src/main/java/org/softwareheritage/graph/SwhPath.java +++ b/java/server/src/main/java/org/softwareheritage/graph/SwhPath.java @@ -1,124 +1,124 @@ package org.softwareheritage.graph; import java.util.ArrayList; import com.fasterxml.jackson.annotation.JsonValue; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; /** - * Wrapper class to store a list of {@link SwhId}. + * Wrapper class to store a list of {@link SwhPID}. * * @author Thibault Allançon * @version 0.0.1 * @since 0.0.1 - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID */ public class SwhPath { - /** Internal list of {@link SwhId} */ - ArrayList path; + /** Internal list of {@link SwhPID} */ + ArrayList path; /** * Constructor. */ public SwhPath() { - this.path = new ArrayList(); + this.path = new ArrayList(); } /** * Constructor. * - * @param swhIds variable number of string PIDs to initialize this path with + * @param swhPIDs variable number of string PIDs to initialize this path with */ - public SwhPath(String ...swhIds) { + public SwhPath(String ...swhPIDs) { this(); - for (String swhId : swhIds) { - add(new SwhId(swhId)); + for (String swhPID : swhPIDs) { + add(new SwhPID(swhPID)); } } /** * Constructor. * - * @param swhIds variable number of {@link SwhId} to initialize this path with - * @see org.softwareheritage.graph.SwhId + * @param swhPIDs variable number of {@link SwhPID} to initialize this path with + * @see org.softwareheritage.graph.SwhPID */ - public SwhPath(SwhId ...swhIds) { + public SwhPath(SwhPID ...swhPIDs) { this(); - for (SwhId swhId : swhIds) { - add(swhId); + for (SwhPID swhPID : swhPIDs) { + add(swhPID); } } /** - * Returns this path as a list of {@link SwhId}. + * Returns this path as a list of {@link SwhPID}. * - * @return list of {@link SwhId} constituting the path - * @see org.softwareheritage.graph.SwhId + * @return list of {@link SwhPID} constituting the path + * @see org.softwareheritage.graph.SwhPID */ @JsonValue - public ArrayList getPath() { + public ArrayList getPath() { return path; } /** - * Adds a {@link SwhId} to this path. + * Adds a {@link SwhPID} to this path. * - * @param {@link SwhId} to add to this path - * @see org.softwareheritage.graph.SwhId + * @param {@link SwhPID} to add to this path + * @see org.softwareheritage.graph.SwhPID */ - public void add(SwhId swhId) { - path.add(swhId); + public void add(SwhPID swhPID) { + path.add(swhPID); } /** - * Returns the {@link SwhId} at the specified position in this path. + * Returns the {@link SwhPID} at the specified position in this path. * - * @param index position of the {@link SwhId} to return - * @return {@link SwhId} at the specified position - * @see org.softwareheritage.graph.SwhId + * @param index position of the {@link SwhPID} to return + * @return {@link SwhPID} at the specified position + * @see org.softwareheritage.graph.SwhPID */ - public SwhId get(int index) { + public SwhPID get(int index) { return path.get(index); } /** * Returns the number of elements in this path. * * @return number of elements in this path */ public int size() { return path.size(); } @Override public boolean equals(Object otherObj) { if (otherObj == this) return true; if (!(otherObj instanceof SwhPath)) return false; SwhPath other = (SwhPath) otherObj; if (size() != other.size()) { return false; } for (int i = 0; i < size(); i++) { - SwhId thisSwhId = get(i); - SwhId otherSwhId = other.get(i); - if (!thisSwhId.equals(otherSwhId)) { + SwhPID thisSwhPID = get(i); + SwhPID otherSwhPID = other.get(i); + if (!thisSwhPID.equals(otherSwhPID)) { return false; } } return true; } @Override public String toString() { String str = new String(); - for (SwhId swhId : path) { - str += swhId + "/"; + for (SwhPID swhPID : path) { + str += swhPID + "/"; } return str; } } diff --git a/java/server/src/main/java/org/softwareheritage/graph/backend/NodeIdMap.java b/java/server/src/main/java/org/softwareheritage/graph/backend/NodeIdMap.java index 3d68dce..9620914 100644 --- a/java/server/src/main/java/org/softwareheritage/graph/backend/NodeIdMap.java +++ b/java/server/src/main/java/org/softwareheritage/graph/backend/NodeIdMap.java @@ -1,116 +1,116 @@ package org.softwareheritage.graph.backend; import java.io.IOException; import org.softwareheritage.graph.Graph; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.backend.MapFile; import org.softwareheritage.graph.backend.Setup; /** * Mapping between internal long node id and external SWH PID. *

* Mappings in both directions are pre-computed and dumped on disk in the {@link Setup} class, then * they are loaded here using mmap(). * * @author Thibault Allançon * @version 0.0.1 * @since 0.0.1 * @see org.softwareheritage.graph.backend.Setup */ public class NodeIdMap { /** Fixed length of full SWH PID */ public static final int SWH_ID_LENGTH = 50; /** Fixed length of long node id */ public static final int NODE_ID_LENGTH = 20; /** Graph path and basename */ String graphPath; /** Number of ids to map */ long nbIds; /** mmap()-ed PID_TO_NODE file */ MapFile swhToNodeMap; /** mmap()-ed NODE_TO_PID file */ MapFile nodeToSwhMap; /** * Constructor. * * @param graphPath full graph path * @param nbNodes number of nodes in the graph */ public NodeIdMap(String graphPath, long nbNodes) throws IOException { this.graphPath = graphPath; this.nbIds = nbNodes; // +1 are for spaces and end of lines int swhToNodeLineLength = SWH_ID_LENGTH + 1 + NODE_ID_LENGTH + 1; int nodeToSwhLineLength = SWH_ID_LENGTH + 1; this.swhToNodeMap = new MapFile(graphPath + Graph.PID_TO_NODE, swhToNodeLineLength); this.nodeToSwhMap = new MapFile(graphPath + Graph.NODE_TO_PID, nodeToSwhLineLength); } /** * Converts SWH PID to corresponding long node id. * - * @param swhId node represented as a {@link SwhId} + * @param swhPID node represented as a {@link SwhPID} * @return corresponding node as a long id - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID */ - public long getNodeId(SwhId swhId) { - // Each line in PID_TO_NODE is formatted as: swhId nodeId - // The file is sorted by swhId, hence we can binary search on swhId to get corresponding nodeId + public long getNodeId(SwhPID swhPID) { + // Each line in PID_TO_NODE is formatted as: swhPID nodeId + // The file is sorted by swhPID, hence we can binary search on swhPID to get corresponding nodeId long start = 0; long end = nbIds - 1; while (start <= end) { long lineNumber = (start + end) / 2L; String[] parts = swhToNodeMap.readAtLine(lineNumber).split(" "); if (parts.length != 2) { break; } - String currentSwhId = parts[0]; + String currentSwhPID = parts[0]; long currentNodeId = Long.parseLong(parts[1]); - int cmp = currentSwhId.compareTo(swhId.toString()); + int cmp = currentSwhPID.compareTo(swhPID.toString()); if (cmp == 0) { return currentNodeId; } else if (cmp < 0) { start = lineNumber + 1; } else { end = lineNumber - 1; } } - throw new IllegalArgumentException("Unknown SWH id: " + swhId); + throw new IllegalArgumentException("Unknown SWH PID: " + swhPID); } /** * Converts a node long id to corresponding SWH PID. * * @param nodeId node as a long id - * @return corresponding node as a {@link SwhId} - * @see org.softwareheritage.graph.SwhId + * @return corresponding node as a {@link SwhPID} + * @see org.softwareheritage.graph.SwhPID */ - public SwhId getSwhId(long nodeId) { - // Each line in NODE_TO_PID is formatted as: swhId - // The file is ordered by nodeId, meaning node0's swhId is at line 0, hence we can read the - // nodeId-th line to get corresponding swhId + public SwhPID getSwhPID(long nodeId) { + // Each line in NODE_TO_PID is formatted as: swhPID + // The file is ordered by nodeId, meaning node0's swhPID is at line 0, hence we can read the + // nodeId-th line to get corresponding swhPID if (nodeId < 0 || nodeId >= nbIds) { throw new IllegalArgumentException("Node id " + nodeId + " should be between 0 and " + nbIds); } - String swhId = nodeToSwhMap.readAtLine(nodeId); - return new SwhId(swhId); + String swhPID = nodeToSwhMap.readAtLine(nodeId); + return new SwhPID(swhPID); } /** * Closes the mapping files. */ public void close() throws IOException { swhToNodeMap.close(); nodeToSwhMap.close(); } } diff --git a/java/server/src/main/java/org/softwareheritage/graph/backend/Setup.java b/java/server/src/main/java/org/softwareheritage/graph/backend/Setup.java index a3fa6c7..4482497 100644 --- a/java/server/src/main/java/org/softwareheritage/graph/backend/Setup.java +++ b/java/server/src/main/java/org/softwareheritage/graph/backend/Setup.java @@ -1,125 +1,125 @@ package org.softwareheritage.graph.backend; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Writer; import java.util.zip.GZIPInputStream; import it.unimi.dsi.bits.LongArrayBitVector; import it.unimi.dsi.fastutil.Size64; import it.unimi.dsi.fastutil.io.BinIO; import it.unimi.dsi.fastutil.longs.LongBigArrays; import it.unimi.dsi.fastutil.longs.LongBigList; import it.unimi.dsi.fastutil.objects.Object2LongFunction; import it.unimi.dsi.fastutil.objects.ObjectBigArrays; import it.unimi.dsi.io.FastBufferedReader; import it.unimi.dsi.io.LineIterator; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.Node; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.backend.NodeTypesMap; /** * Pre-processing steps (such as dumping mapping files on disk) before running the graph service. * * @author Thibault Allançon * @version 0.0.1 * @since 0.0.1 */ public class Setup { /** * Main entrypoint. * * @param args command line arguments */ public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println("Expected parameters: "); System.exit(1); } String nodesPath = args[0]; String graphPath = args[1]; System.out.println("Pre-computing node id maps..."); long startTime = System.nanoTime(); precomputeNodeIdMap(nodesPath, graphPath); long endTime = System.nanoTime(); double duration = (double) (endTime - startTime) / 1_000_000_000; System.out.println("Done in: " + duration + " seconds"); } /** * Computes and dumps on disk mapping files. * * @param nodesPath path of the compressed csv nodes file * @param graphPath path of the compressed graph */ // Suppress warning for Object2LongFunction cast @SuppressWarnings("unchecked") static void precomputeNodeIdMap(String nodesPath, String graphPath) throws IOException { - // First internal mapping: SWH id (string) -> WebGraph MPH (long) + // First internal mapping: SWH PID (string) -> WebGraph MPH (long) Object2LongFunction mphMap = null; try { mphMap = (Object2LongFunction) BinIO.loadObject(graphPath + ".mph"); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("The .mph file contains unknown class object: " + e); } long nbIds = (mphMap instanceof Size64) ? ((Size64) mphMap).size64() : mphMap.size(); // Second internal mapping: WebGraph MPH (long) -> BFS ordering (long) long[][] bfsMap = LongBigArrays.newBigArray(nbIds); long loaded = BinIO.loadLongs(graphPath + ".order", bfsMap); if (loaded != nbIds) { throw new IllegalArgumentException("Graph contains " + nbIds + " nodes, but read " + loaded); } - // Dump complete mapping for all nodes: SWH id (string) <=> WebGraph node id (long) + // Dump complete mapping for all nodes: SWH PID (string) <=> WebGraph node id (long) InputStream nodesStream = new GZIPInputStream(new FileInputStream(nodesPath)); FastBufferedReader buffer = new FastBufferedReader(new InputStreamReader(nodesStream, "UTF-8")); - LineIterator swhIdIterator = new LineIterator(buffer); + LineIterator swhPIDIterator = new LineIterator(buffer); try (Writer swhToNodeMap = new BufferedWriter(new FileWriter(graphPath + Graph.PID_TO_NODE)); Writer nodeToSwhMap = new BufferedWriter(new FileWriter(graphPath + Graph.NODE_TO_PID))) { - // nodeToSwhMap needs to write SWH id in order of node id, so use a temporary array - Object[][] nodeToSwhId = ObjectBigArrays.newBigArray(nbIds); + // nodeToSwhMap needs to write SWH PID in order of node id, so use a temporary array + Object[][] nodeToSwhPID = ObjectBigArrays.newBigArray(nbIds); // To effectively run edge restriction during graph traversals, we store node id (long) -> SWH // type map. This is represented as a bitmap using minimum number of bits per Node.Type. final int log2NbTypes = (int) Math.ceil(Math.log(Node.Type.values().length) / Math.log(2)); final int nbBitsPerNodeType = log2NbTypes; LongArrayBitVector nodeTypesBitVector = LongArrayBitVector.ofLength(nbBitsPerNodeType * nbIds); LongBigList nodeTypesMap = nodeTypesBitVector.asLongBigList(nbBitsPerNodeType); - for (long iNode = 0; iNode < nbIds && swhIdIterator.hasNext(); iNode++) { - String strSwhId = swhIdIterator.next().toString(); - long mphId = mphMap.getLong(strSwhId); + for (long iNode = 0; iNode < nbIds && swhPIDIterator.hasNext(); iNode++) { + String strSwhPID = swhPIDIterator.next().toString(); + long mphId = mphMap.getLong(strSwhPID); long nodeId = LongBigArrays.get(bfsMap, mphId); String paddedNodeId = String.format("%0" + NodeIdMap.NODE_ID_LENGTH + "d", nodeId); - String line = strSwhId + " " + paddedNodeId + "\n"; + String line = strSwhPID + " " + paddedNodeId + "\n"; swhToNodeMap.write(line); - ObjectBigArrays.set(nodeToSwhId, nodeId, strSwhId); + ObjectBigArrays.set(nodeToSwhPID, nodeId, strSwhPID); - SwhId swhId = new SwhId(strSwhId); - nodeTypesMap.set(nodeId, swhId.getType().ordinal()); + SwhPID swhPID = new SwhPID(strSwhPID); + nodeTypesMap.set(nodeId, swhPID.getType().ordinal()); } BinIO.storeObject(nodeTypesMap, graphPath + Graph.NODE_TO_TYPE); for (long iNode = 0; iNode < nbIds; iNode++) { - String line = ObjectBigArrays.get(nodeToSwhId, iNode).toString() + "\n"; + String line = ObjectBigArrays.get(nodeToSwhPID, iNode).toString() + "\n"; nodeToSwhMap.write(line); } } } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java b/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java index d75e8c9..8eada2b 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java @@ -1,103 +1,103 @@ package org.softwareheritage.graph; import java.util.ArrayList; import org.junit.Test; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") public class LeavesTest extends GraphTest { @Test public void forwardFromSnp() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } @Test public void forwardFromRel() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:rel:0000000000000000000000000000000000000019"); + SwhPID src = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000015")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000014")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000011")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000011")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } @Test public void backwardFromLeaf() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - SwhId src1 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000015"); - ArrayList expectedLeaves1 = new ArrayList<>(); - expectedLeaves1.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000019")); + SwhPID src1 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); + ArrayList expectedLeaves1 = new ArrayList<>(); + expectedLeaves1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); GraphTest.assertEqualsAnyOrder(expectedLeaves1, (ArrayList) endpoint.leaves(src1).result); - SwhId src2 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); - ArrayList expectedLeaves2 = new ArrayList<>(); - expectedLeaves2.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); - expectedLeaves2.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000019")); + SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); + ArrayList expectedLeaves2 = new ArrayList<>(); + expectedLeaves2.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); + expectedLeaves2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); GraphTest.assertEqualsAnyOrder(expectedLeaves2, (ArrayList) endpoint.leaves(src2).result); } @Test public void forwardRevToRevOnly() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:rev:0000000000000000000000000000000000000018"); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000003")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } @Test public void forwardDirToAll() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:dir:0000000000000000000000000000000000000008"); + SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint = new Endpoint(graph, "forward", "dir:*"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } @Test public void backwardCntToDirDirToDir() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:cnt:0000000000000000000000000000000000000005"); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005"); Endpoint endpoint = new Endpoint(graph, "backward", "cnt:dir,dir:dir"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000012")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000012")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java index 4f55956..a14573c 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java @@ -1,129 +1,129 @@ package org.softwareheritage.graph; import java.util.ArrayList; import org.junit.Test; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") public class NeighborsTest extends GraphTest { @Test public void zeroNeighbor() { Graph graph = getGraph(); - ArrayList expectedNodes = new ArrayList<>(); + ArrayList expectedNodes = new ArrayList<>(); - SwhId src1 = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); + SwhPID src1 = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint1.neighbors(src1).result); - SwhId src2 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); + SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint2.neighbors(src2).result); - SwhId src3 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000015"); + SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); Endpoint endpoint3 = new Endpoint(graph, "forward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint3.neighbors(src3).result); - SwhId src4 = new SwhId("swh:1:rel:0000000000000000000000000000000000000019"); + SwhPID src4 = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); Endpoint endpoint4 = new Endpoint(graph, "backward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint4.neighbors(src4).result); - SwhId src5 = new SwhId("swh:1:dir:0000000000000000000000000000000000000008"); + SwhPID src5 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint5 = new Endpoint(graph, "forward", "snp:*,rev:*,rel:*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint5.neighbors(src5).result); } @Test public void oneNeighbor() { Graph graph = getGraph(); - SwhId src1 = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); + SwhPID src1 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000002")); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); - SwhId src2 = new SwhId("swh:1:dir:0000000000000000000000000000000000000017"); + SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000017"); Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000014")); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); - SwhId src3 = new SwhId("swh:1:dir:0000000000000000000000000000000000000012"); + SwhPID src3 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes3 = new ArrayList<>(); - expectedNodes3.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList expectedNodes3 = new ArrayList<>(); + expectedNodes3.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); GraphTest.assertEqualsAnyOrder(expectedNodes3, (ArrayList) endpoint3.neighbors(src3).result); - SwhId src4 = new SwhId("swh:1:rev:0000000000000000000000000000000000000009"); + SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:rev"); - ArrayList expectedNodes4 = new ArrayList<>(); - expectedNodes4.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList expectedNodes4 = new ArrayList<>(); + expectedNodes4.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); GraphTest.assertEqualsAnyOrder(expectedNodes4, (ArrayList) endpoint4.neighbors(src4).result); - SwhId src5 = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID src5 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint5 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes5 = new ArrayList<>(); - expectedNodes5.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); + ArrayList expectedNodes5 = new ArrayList<>(); + expectedNodes5.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); GraphTest.assertEqualsAnyOrder(expectedNodes5, (ArrayList) endpoint5.neighbors(src5).result); } @Test public void twoNeighbors() { Graph graph = getGraph(); - SwhId src1 = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID src1 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes1.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009")); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes1.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); - SwhId src2 = new SwhId("swh:1:dir:0000000000000000000000000000000000000008"); + SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes2.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); - SwhId src3 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000001"); + SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes3 = new ArrayList<>(); - expectedNodes3.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000008")); - expectedNodes3.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000002")); + ArrayList expectedNodes3 = new ArrayList<>(); + expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); + expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); GraphTest.assertEqualsAnyOrder(expectedNodes3, (ArrayList) endpoint3.neighbors(src3).result); - SwhId src4 = new SwhId("swh:1:rev:0000000000000000000000000000000000000009"); + SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:snp,rev:rel"); - ArrayList expectedNodes4 = new ArrayList<>(); - expectedNodes4.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes4.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); + ArrayList expectedNodes4 = new ArrayList<>(); + expectedNodes4.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes4.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); GraphTest.assertEqualsAnyOrder(expectedNodes4, (ArrayList) endpoint4.neighbors(src4).result); } @Test public void threeNeighbors() { Graph graph = getGraph(); - SwhId src1 = new SwhId("swh:1:dir:0000000000000000000000000000000000000008"); + SwhPID src1 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000006")); - expectedNodes1.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes1.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); + expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); - SwhId src2 = new SwhId("swh:1:rev:0000000000000000000000000000000000000009"); + SwhPID src2 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes2.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes2.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes2.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java index 6ddbdbe..5bc52cf 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java @@ -1,535 +1,535 @@ package org.softwareheritage.graph; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; import org.junit.Test; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.SwhPath; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") public class VisitTest extends GraphTest { - private void assertSameNodesFromPaths(ArrayList paths, ArrayList nodes) { - Set expectedNodes = new HashSet(); + private void assertSameNodesFromPaths(ArrayList paths, ArrayList nodes) { + Set expectedNodes = new HashSet(); for (SwhPath path : paths) { - for (SwhId node : path.getPath()) { + for (SwhPID node : path.getPath()) { expectedNodes.add(node); } } GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); } @Test public void forwardFromRoot() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000007" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000001" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000004" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000005" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:dir:0000000000000000000000000000000000000002", "swh:1:cnt:0000000000000000000000000000000000000001" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000007" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000001" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000004" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000005" )); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:dir:0000000000000000000000000000000000000002", "swh:1:cnt:0000000000000000000000000000000000000001" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void forwardFromMiddle() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:dir:0000000000000000000000000000000000000012"); + SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000007" )); expectedPaths.add( new SwhPath( "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000001" )); expectedPaths.add( new SwhPath( "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000004" )); expectedPaths.add( new SwhPath( "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000005" )); expectedPaths.add( new SwhPath( "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:cnt:0000000000000000000000000000000000000011" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void forwardFromLeaf() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); + SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000004" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void backwardFromRoot() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:ori:0000000000000000000000000000000000000021" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void backwardFromMiddle() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:dir:0000000000000000000000000000000000000012"); + SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018", "swh:1:rel:0000000000000000000000000000000000000019" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void backwardFromLeaf() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); + SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000004", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018", "swh:1:rel:0000000000000000000000000000000000000019" )); expectedPaths.add( new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000004", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018", "swh:1:rel:0000000000000000000000000000000000000019" )); expectedPaths.add( new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000004", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:ori:0000000000000000000000000000000000000021" )); expectedPaths.add( new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000004", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:ori:0000000000000000000000000000000000000021" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void forwardSnpToRev() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", "snp:rev"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void forwardRelToRevRevToRev() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:rel:0000000000000000000000000000000000000010"); + SwhPID swhPID = new SwhPID("swh:1:rel:0000000000000000000000000000000000000010"); Endpoint endpoint = new Endpoint(graph, "forward", "rel:rev,rev:rev"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void forwardRevToAllDirToAll() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000013"); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000013"); Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000005" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000005" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000004" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000004" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000007" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000007" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:cnt:0000000000000000000000000000000000000011" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:dir:0000000000000000000000000000000000000002", "swh:1:cnt:0000000000000000000000000000000000000001" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000001" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000001" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void forwardSnpToAllRevToAll() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", "snp:*,rev:*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:dir:0000000000000000000000000000000000000002" )); expectedPaths.add( new SwhPath( "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008" )); expectedPaths.add( new SwhPath( "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void forwardNoEdges() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", ""); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:snp:0000000000000000000000000000000000000020" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void backwardRevToRevRevToRel() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev,rev:rel"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018", "swh:1:rel:0000000000000000000000000000000000000019" )); expectedPaths.add( new SwhPath( "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rel:0000000000000000000000000000000000000010" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); } @Test public void forwardFromRootNodesOnly() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; - - ArrayList expectedNodes = new ArrayList(); - expectedNodes.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); - expectedNodes.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000003")); - expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000002")); - expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000008")); - expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000006")); - expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + + ArrayList expectedNodes = new ArrayList(); + expectedNodes.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); + expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); } @Test public void backwardRevToAllNodesOnly() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; - - ArrayList expectedNodes = new ArrayList(); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000003")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009")); - expectedNodes.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000018")); - expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000019")); + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + + ArrayList expectedNodes = new ArrayList(); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); + expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000018")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java b/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java index 4dcac9c..a0f5b35 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java @@ -1,232 +1,232 @@ package org.softwareheritage.graph; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.junit.Assert; import org.junit.Test; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.SwhPath; public class WalkTest extends GraphTest { @Test public void forwardRootToLeaf() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - SwhId src = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; SwhPath solution1 = new SwhPath( "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000005" ); SwhPath solution2 = new SwhPath( "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000005" ); SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; List possibleSolutions = Arrays.asList(solution1, solution2); Assert.assertTrue(possibleSolutions.contains(dfsPath)); Assert.assertTrue(possibleSolutions.contains(bfsPath)); } @Test public void forwardLeafToLeaf() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - SwhId src = new SwhId("swh:1:cnt:0000000000000000000000000000000000000007"); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007"); String dstFmt = "cnt"; SwhPath expectedPath = new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000007" ); SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); } @Test public void forwardRevToRev() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); - SwhId src = new SwhId("swh:1:rev:0000000000000000000000000000000000000018"); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003"; SwhPath expectedPath = new SwhPath( "swh:1:rev:0000000000000000000000000000000000000018", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003" ); SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); } @Test public void backwardRevToRev() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev"); - SwhId src = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018"; SwhPath expectedPath = new SwhPath( "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018" ); SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); } @Test public void backwardCntToFirstSnp() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - SwhId src = new SwhId("swh:1:cnt:0000000000000000000000000000000000000001"); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); String dstFmt = "snp"; SwhPath solution1 = new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000001", "swh:1:dir:0000000000000000000000000000000000000002", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:snp:0000000000000000000000000000000000000020" ); SwhPath solution2 = new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000001", "swh:1:dir:0000000000000000000000000000000000000002", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:snp:0000000000000000000000000000000000000020" ); SwhPath solution3 = new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000001", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:snp:0000000000000000000000000000000000000020" ); SwhPath solution4 = new SwhPath( "swh:1:cnt:0000000000000000000000000000000000000001", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:snp:0000000000000000000000000000000000000020" ); SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); Assert.assertTrue(possibleSolutions.contains(dfsPath)); Assert.assertTrue(possibleSolutions.contains(bfsPath)); } @Test public void forwardRevToFirstCnt() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); - SwhId src = new SwhId("swh:1:rev:0000000000000000000000000000000000000009"); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); String dstFmt = "cnt"; SwhPath solution1 = new SwhPath( "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000007" ); SwhPath solution2 = new SwhPath( "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000005" ); SwhPath solution3 = new SwhPath( "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:cnt:0000000000000000000000000000000000000004" ); SwhPath solution4 = new SwhPath( "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:cnt:0000000000000000000000000000000000000001" ); SwhPath solution5 = new SwhPath( "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:dir:0000000000000000000000000000000000000002", "swh:1:cnt:0000000000000000000000000000000000000001" ); SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4, solution5); Assert.assertTrue(possibleSolutions.contains(dfsPath)); Assert.assertTrue(possibleSolutions.contains(bfsPath)); } @Test public void backwardDirToFirstRel() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); - SwhId src = new SwhId("swh:1:dir:0000000000000000000000000000000000000016"); + SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000016"); String dstFmt = "rel"; SwhPath expectedPath = new SwhPath( "swh:1:dir:0000000000000000000000000000000000000016", "swh:1:dir:0000000000000000000000000000000000000017", "swh:1:rev:0000000000000000000000000000000000000018", "swh:1:rel:0000000000000000000000000000000000000019" ); SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); } }