Package org.apache.giraph.graph

Examples of org.apache.giraph.graph.Vertex


  @Test
  public void testVertexWithNoEdges() throws IOException, InterruptedException {
    TaskAttemptContext tac = mock(TaskAttemptContext.class);
    when(tac.getConfiguration()).thenReturn(conf);

    Vertex vertex = mock(Vertex.class);
    when(vertex.getId()).thenReturn(new Text("The Beautiful South"));
    when(vertex.getValue()).thenReturn(new DoubleWritable(32.2d));
    // Create empty iterable == no edges
    when(vertex.getEdges()).thenReturn(new ArrayList<Text>());

    RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    AdjacencyListTextVertexWriter writer = createVertexWriter(tw);
    writer.setConf(conf);
    writer.initialize(tac);
View Full Code Here


  @Test
  public void testVertexWithEdges() throws IOException, InterruptedException {
    TaskAttemptContext tac = mock(TaskAttemptContext.class);
    when(tac.getConfiguration()).thenReturn(conf);

    Vertex vertex = mock(Vertex.class);
    when(vertex.getId()).thenReturn(new Text("San Francisco"));
    when(vertex.getValue()).thenReturn(new DoubleWritable(0d));
    when(vertex.getTotalNumEdges()).thenReturn(2l);
    List<Edge<Text, DoubleWritable>> cities = Lists.newArrayList();
    Collections.addAll(cities,
        EdgeFactory.create(new Text("Los Angeles"), new DoubleWritable(347.16)),
        EdgeFactory.create(new Text("Phoenix"), new DoubleWritable(652.48)));

    when(vertex.getEdges()).thenReturn(cities);

    RecordWriter<Text,Text> tw = mock(RecordWriter.class);
    AdjacencyListTextVertexWriter writer = createVertexWriter(tw);
    writer.setConf(conf);
    writer.initialize(tac);
View Full Code Here

  public void testWithDifferentDelimiter() throws IOException, InterruptedException {
    conf.set(AdjacencyListTextVertexOutputFormat.LINE_TOKENIZE_VALUE, ":::");
    TaskAttemptContext tac = mock(TaskAttemptContext.class);
    when(tac.getConfiguration()).thenReturn(conf);

    Vertex vertex = mock(Vertex.class);
    when(vertex.getId()).thenReturn(new Text("San Francisco"));
    when(vertex.getValue()).thenReturn(new DoubleWritable(0d));
    when(vertex.getTotalNumEdges()).thenReturn(2l);
    List<Edge<Text, DoubleWritable>> cities = Lists.newArrayList();
    Collections.addAll(cities,
        EdgeFactory.create(new Text("Los Angeles"), new DoubleWritable(347.16)),
        EdgeFactory.create(new Text("Phoenix"), new DoubleWritable(652.48)));

    when(vertex.getEdges()).thenReturn(cities);

    RecordWriter<Text,Text> tw = mock(RecordWriter.class);
    AdjacencyListTextVertexWriter writer = createVertexWriter(tw);
    writer.setConf(conf);
    writer.initialize(tac);
View Full Code Here

    // Data to send
    int partitionId = 13;
    Partition<IntWritable, IntWritable, IntWritable, IntWritable> partition =
        conf.createPartition(partitionId, null);
    for (int i = 0; i < 10; ++i) {
      Vertex vertex = conf.createVertex();
      vertex.initialize(new IntWritable(i), new IntWritable(i));
      partition.putVertex(vertex);
    }

    // Send the request
    SendVertexRequest<IntWritable, IntWritable, IntWritable,
    IntWritable> request =
      new SendVertexRequest<IntWritable, IntWritable,
      IntWritable, IntWritable>(partition);
    client.sendWritableRequest(workerInfo.getTaskId(), request);
    client.waitAllRequests();

    // Stop the service
    client.stop();
    server.stop();

    // Check the output
    PartitionStore<IntWritable, IntWritable,
        IntWritable, IntWritable> partitionStore =
        serverData.getPartitionStore();
    assertTrue(partitionStore.hasPartition(partitionId));
    int total = 0;
    Partition<IntWritable, IntWritable, IntWritable, IntWritable> partition2 =
        partitionStore.getPartition(partitionId)
    for (Vertex<IntWritable, IntWritable,
        IntWritable, IntWritable> vertex : partition2) {
      total += vertex.getId().get();
    }
    partitionStore.putPartition(partition2);
    assertEquals(total, 45);
    partitionStore.shutdown();
  }
View Full Code Here

    for (int i = 0; i < 11; ++i) {
      VertexMutations<IntWritable, IntWritable, IntWritable, IntWritable>
      mutations = new VertexMutations<IntWritable, IntWritable,
          IntWritable, IntWritable>();
      for (int j = 0; j < 3; ++j) {
        Vertex vertex = conf.createVertex();
        vertex.initialize(new IntWritable(i), new IntWritable(j));
        mutations.addVertex(vertex);
      }
      for (int j = 0; j < 2; ++j) {
        mutations.removeVertex();
      }
      for (int j = 0; j < 5; ++j) {
        Edge<IntWritable, IntWritable> edge =
            EdgeFactory.create(new IntWritable(i), new IntWritable(2 * j));
        mutations.addEdge(edge);
      }
      for (int j = 0; j < 7; ++j) {
        mutations.removeEdge(new IntWritable(j));
      }
      vertexIdMutations.put(new IntWritable(i), mutations);
    }

    // Send the request
    SendPartitionMutationsRequest<IntWritable, IntWritable, IntWritable,
    IntWritable> request =
      new SendPartitionMutationsRequest<IntWritable, IntWritable,
      IntWritable, IntWritable>(partitionId, vertexIdMutations);
    GiraphMetrics.init(conf);
    client.sendWritableRequest(workerInfo.getTaskId(), request);
    client.waitAllRequests();

    // Stop the service
    client.stop();
    server.stop();

    // Check the output
    ConcurrentHashMap<IntWritable, VertexMutations<IntWritable, IntWritable,
    IntWritable, IntWritable>> inVertexIdMutations =
        serverData.getVertexMutations();
    int keySum = 0;
    for (Entry<IntWritable, VertexMutations<IntWritable, IntWritable,
        IntWritable, IntWritable>> entry :
          inVertexIdMutations.entrySet()) {
      synchronized (entry.getValue()) {
        keySum += entry.getKey().get();
        int vertexValueSum = 0;
        for (Vertex<IntWritable, IntWritable, IntWritable, IntWritable>
        vertex : entry.getValue().getAddedVertexList()) {
          vertexValueSum += vertex.getValue().get();
        }
        assertEquals(3, vertexValueSum);
        assertEquals(2, entry.getValue().getRemovedVertexCount());
        int removeEdgeValueSum = 0;
        for (Edge<IntWritable, IntWritable> edge :
View Full Code Here

  private void IdWithValueTestWorker(Text expected)
      throws IOException, InterruptedException {
    TaskAttemptContext tac = mock(TaskAttemptContext.class);
    when(tac.getConfiguration()).thenReturn(conf);

    Vertex vertex = mock(Vertex.class);
    when(vertex.getId()).thenReturn(new Text("Four Tops"));
    when(vertex.getValue()).thenReturn(new DoubleWritable(4d));

    // Create empty iterator == no edges
    when(vertex.getEdges()).thenReturn(new ArrayList<Text>());

    final RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    IdWithValueVertexWriter writer = new IdWithValueVertexWriter() {
      @Override
      protected RecordWriter<Text, Text> createLineRecordWriter(
View Full Code Here

  private void IdWithValueTestWorker(Text expected)
      throws IOException, InterruptedException {
    TaskAttemptContext tac = mock(TaskAttemptContext.class);
    when(tac.getConfiguration()).thenReturn(conf);

    Vertex vertex = mock(Vertex.class);
    when(vertex.getId()).thenReturn(new Text("Four Tops"));
    when(vertex.getValue()).thenReturn(new DoubleWritable(4d));

    // Create empty iterator == no edges
    when(vertex.getEdges()).thenReturn(new ArrayList<Text>());

    final RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    IdWithValueVertexWriter writer = new IdWithValueVertexWriter() {
      @Override
      protected RecordWriter<Text, Text> createLineRecordWriter(
View Full Code Here

  @Test
  public void testVertexWithNoEdges() throws IOException, InterruptedException {
    TaskAttemptContext tac = mock(TaskAttemptContext.class);
    when(tac.getConfiguration()).thenReturn(conf);

    Vertex vertex = mock(Vertex.class);
    when(vertex.getId()).thenReturn(new Text("The Beautiful South"));
    when(vertex.getValue()).thenReturn(new DoubleWritable(32.2d));
    // Create empty iterable == no edges
    when(vertex.getEdges()).thenReturn(new ArrayList<Text>());

    RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    AdjacencyListTextVertexWriter writer = createVertexWriter(tw);
    writer.setConf(conf);
    writer.initialize(tac);
View Full Code Here

  @Test
  public void testVertexWithEdges() throws IOException, InterruptedException {
    TaskAttemptContext tac = mock(TaskAttemptContext.class);
    when(tac.getConfiguration()).thenReturn(conf);

    Vertex vertex = mock(Vertex.class);
    when(vertex.getId()).thenReturn(new Text("San Francisco"));
    when(vertex.getValue()).thenReturn(new DoubleWritable(0d));
    List<Edge<Text, DoubleWritable>> cities = Lists.newArrayList();
    Collections.addAll(cities,
        EdgeFactory.create(new Text("Los Angeles"), new DoubleWritable(347.16)),
        EdgeFactory.create(new Text("Phoenix"), new DoubleWritable(652.48)));

    when(vertex.getEdges()).thenReturn(cities);

    RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    AdjacencyListTextVertexWriter writer = createVertexWriter(tw);
    writer.setConf(conf);
    writer.initialize(tac);
View Full Code Here

  public void testWithDifferentDelimiter() throws IOException, InterruptedException {
    conf.set(AdjacencyListTextVertexOutputFormat.LINE_TOKENIZE_VALUE, ":::");
    TaskAttemptContext tac = mock(TaskAttemptContext.class);
    when(tac.getConfiguration()).thenReturn(conf);

    Vertex vertex = mock(Vertex.class);
    when(vertex.getId()).thenReturn(new Text("San Francisco"));
    when(vertex.getValue()).thenReturn(new DoubleWritable(0d));
    List<Edge<Text, DoubleWritable>> cities = Lists.newArrayList();
    Collections.addAll(cities,
        EdgeFactory.create(new Text("Los Angeles"), new DoubleWritable(347.16)),
        EdgeFactory.create(new Text("Phoenix"), new DoubleWritable(652.48)));

    when(vertex.getEdges()).thenReturn(cities);

    RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    AdjacencyListTextVertexWriter writer = createVertexWriter(tw);
    writer.setConf(conf);
    writer.initialize(tac);
View Full Code Here

TOP

Related Classes of org.apache.giraph.graph.Vertex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.