/** * Initialize this output format - needs to be called before running the * application. Creates new instance of TestGraph * * @param conf Configuration */ public static void initializeOutputGraph(GiraphConfiguration conf) { OUTPUT_GRAPH = new TestGraph(conf); }
/** * Add vertex with given ID * * @param id the index * @param value the value * @param edges all edges * @return this */ public TestGraph<I, V, E> addVertex(I id, V value, Entry<I, E>... edges) { addVertex(makeVertex(id, value, edges)); return this; }
public ImmutableClassesGiraphConfiguration<I, V, E> getConf() { return testGraph.getConf(); }
/** * Set vertex, replace if there was already a vertex with same id added * * @param id the index * @param value the value * @param edges all edges * @return this */ public TestGraph<I, V, E> setVertex(I id, V value, Entry<I, E>... edges) { setVertex(makeVertex(id, value, edges)); return this; }
private static TestGraph<LongWritable, LongWritable, NullWritable> createTestGraph() { TestGraph<LongWritable, LongWritable, NullWritable> graph = new TestGraph<LongWritable, LongWritable, NullWritable>(createConf()); graph.addVertex(new LongWritable(1), new LongWritable()); graph.addVertex(new LongWritable(2), new LongWritable()); graph.addVertex(new LongWritable(3), new LongWritable()); graph.addVertex(new LongWritable(4), new LongWritable()); graph.addEdge(new LongWritable(1), new LongWritable(2), NullWritable.get()); graph.addEdge(new LongWritable(2), new LongWritable(1), NullWritable.get()); graph.addEdge(new LongWritable(2), new LongWritable(3), NullWritable.get()); graph.addEdge(new LongWritable(3), new LongWritable(2), NullWritable.get()); return graph; }
@Test public void testWorkerMessages() throws Exception { GiraphConfiguration conf = new GiraphConfiguration(); BlockUtils.setAndInitBlockFactoryClass(conf, TestWorkerMessagesBlockFactory.class); TestGraph testGraph = new TestGraph(conf); testGraph.addEdge(new LongWritable(1), new LongWritable(2), NullWritable.get()); LocalBlockRunner.runApp(testGraph); }
@Override public void writeVertex( Vertex<I, V, E> vertex) throws IOException, InterruptedException { synchronized (OUTPUT_GRAPH) { OUTPUT_GRAPH.addVertex(vertex); } } };
/** * Get Vertex for a given id. */ public Vertex<I, V, E> getVertex(Number vertexId) { return testGraph.getVertex(numberToVertexId(vertexId)); }
/** * Add Edge to the graph with provided Edge Value, by adding it to * outEdges of {@code fromVertex}, potentially creating {@code fromVertex} * if it doesn't exist. */ public void addEdge(Number fromVertex, Number toVertex, E edgeValue) { testGraph.addEdge( numberToVertexId(fromVertex), numberToVertexId(toVertex), edgeValueOrCreate(edgeValue)); }
public void postApplication() { for (Partition<I, V, E> partition : partitions) { for (Vertex<I, V, E> vertex : partition) { inputGraph.setVertex(vertex); } } } }
/** * Get number of vertices in the graph */ public int getVertexCount() { return testGraph.getVertexCount(); }
/** * Create a vertex * * @param id the id of the vertex * @param value the vertex value * @param edges edges to other vertices * @return a new vertex */ protected Vertex<I, V, E> makeVertex(I id, V value, Entry<I, E>... edges) { Vertex<I, V, E> vertex = conf.createVertex(); vertex.initialize(id, value, createEdges(edges)); return vertex; }
public InternalApi( TestGraph<I, V, E> graph, ImmutableClassesGiraphConfiguration conf, int numPartitions, boolean runAllChecks) { this.inputGraph = graph; this.partitions = new ArrayList<>(numPartitions); for (int i = 0; i < numPartitions; i++) { this.partitions.add(conf.createPartition(i, null)); } this.partitionerFactory = conf.createGraphPartitioner(); Preconditions.checkNotNull(this.partitionerFactory); Preconditions.checkState(this.partitions.size() == numPartitions); for (Vertex<I, V, E> vertex : graph) { getPartition(vertex.getId()).putVertex(vertex); } graph.clear(); this.conf = conf; this.runAllChecks = runAllChecks; this.globalComm = new InternalAggregators(runAllChecks); this.aggregators = new AggregatorToGlobalCommTranslation(conf, globalComm); this.mutations = new ConcurrentHashMap<>(); this.workerApi = new InternalWorkerApi(); this.workerApi.setConf(conf); this.workerApi.setWorkerGlobalCommUsage(this.globalComm); this.createVertexOnMsgs = GiraphConstants.RESOLVER_CREATE_VERTEX_ON_MSGS.get(conf); workerContextLogic = new BlockWorkerContextLogic(); }
private static TestGraph<LongWritable, LongWritable, NullWritable> createTestGraph() { TestGraph<LongWritable, LongWritable, NullWritable> graph = new TestGraph<>(createConf()); graph.addVertex(new LongWritable(1), new LongWritable()); graph.addVertex(new LongWritable(2), new LongWritable()); graph.addVertex(new LongWritable(3), new LongWritable()); graph.addVertex(new LongWritable(4), new LongWritable()); graph.addEdge(new LongWritable(1), new LongWritable(2), NullWritable.get()); graph.addEdge(new LongWritable(2), new LongWritable(1), NullWritable.get()); graph.addEdge(new LongWritable(2), new LongWritable(3), NullWritable.get()); graph.addEdge(new LongWritable(3), new LongWritable(2), NullWritable.get()); return graph; }
/** * Add Vertex with a given id and a given Vertex Value to the graph, * with listed outgoing edges, all initialized to same provided * {@code edgeValue}. */ public void addVertex(Number vertexId, Number vertexValue, Number edgeValue, Number... outEdges) { Vertex<I, V, E> vertex = makeVertex( vertexId, vertexValue, edgeValue, outEdges); testGraph.addVertex(vertex); }
/** * Get Vertex Value for a given id. */ public V getValue(Number vertexId) { return testGraph.getVertex(numberToVertexId(vertexId)).getValue(); }
/** * Add Edge to the graph with provided Edge Value, by adding it to * outEdges of {@code fromVertex}, potentially creating {@code fromVertex} * if it doesn't exist. */ public void addEdge(Number fromVertex, Number toVertex, Number edgeValue) { testGraph.addEdge( numberToVertexId(fromVertex), numberToVertexId(toVertex), numberToEdgeValue(edgeValue)); }
/** * Add Vertex with a given id and a given Vertex Value to the graph, * with listed outgoing edges, all initialized to same provided * {@code edgeSupplier}. */ public void addVertex(Number vertexId, V vertexValue, Supplier<E> edgeSupplier, Number... outEdges) { Vertex<I, V, E> vertex = makeVertex( vertexId, vertexValue, edgeSupplier, outEdges); testGraph.addVertex(vertex); }
/** * Run Block Application specified within the conf, on a given graph, * locally, in-memory, with a given vertexSaver. */ public static <I extends WritableComparable, V extends Writable, E extends Writable> void runAppWithVertexOutput( TestGraph<I, V, E> graph, final SimpleVertexWriter<I, V, E> vertexSaver) { BlockFactory<?> factory = BlockUtils.createBlockFactory(graph.getConf()); runBlockWithVertexOutput( factory.createBlock(graph.getConf()), factory.createExecutionStage(graph.getConf()), graph, vertexSaver); }
public NumericTestGraph(GiraphConfiguration conf) { this(new TestGraph<I, V, E>(conf)); }