Example usage for org.apache.hadoop.io DoubleWritable DoubleWritable

List of usage examples for org.apache.hadoop.io DoubleWritable DoubleWritable

Introduction

In this page you can find the example usage for org.apache.hadoop.io DoubleWritable DoubleWritable.

Prototype

public DoubleWritable(double value) 

Source Link

Usage

From source file:org.apache.giraph.io.TestTextDoubleDoubleAdjacencyListVertexInputFormat.java

License:Apache License

@Test
public void testLineSanitizer() throws Exception {
    String input = "Bye\t0.01\tCiao\t1.001\tTchau\t2.0001\tAdios\t3.00001";

    AdjacencyListTextVertexInputFormat.LineSanitizer toUpper = new AdjacencyListTextVertexInputFormat.LineSanitizer() {
        @Override/*ww w  . ja  v  a 2s  .co  m*/
        public String sanitize(String s) {
            return s.toUpperCase();
        }
    };

    when(rr.getCurrentValue()).thenReturn(new Text(input));
    TextVertexReader vr = createVertexReader(rr, toUpper);
    vr.setConf(conf);
    vr.initialize(null, tac);
    assertTrue("Should have been able to read vertex", vr.nextVertex());
    Vertex<Text, DoubleWritable, DoubleWritable> vertex = vr.getCurrentVertex();
    assertValidVertex(conf, vertex, new Text("BYE"), new DoubleWritable(0.01d),
            EdgeFactory.create(new Text("CIAO"), new DoubleWritable(1.001d)),
            EdgeFactory.create(new Text("TCHAU"), new DoubleWritable(2.0001d)),
            EdgeFactory.create(new Text("ADIOS"), new DoubleWritable(3.00001d)));

    assertEquals(vertex.getNumEdges(), 3);
}

From source file:org.apache.giraph.io.TestTextDoubleDoubleAdjacencyListVertexInputFormat.java

License:Apache License

@Test
public void testDifferentSeparators() throws Exception {
    String input = "alpha:42:beta:99";

    when(rr.getCurrentValue()).thenReturn(new Text(input));
    conf.set(AdjacencyListTextVertexInputFormat.LINE_TOKENIZE_VALUE, ":");
    TextVertexReader vr = createVertexReader(rr);
    vr.setConf(conf);//from  w w w.ja v  a 2s  . co m
    vr.initialize(null, tac);
    assertTrue("Should have been able to read vertex", vr.nextVertex());
    Vertex<Text, DoubleWritable, DoubleWritable> vertex = vr.getCurrentVertex();
    assertValidVertex(conf, vertex, new Text("alpha"), new DoubleWritable(42d),
            EdgeFactory.create(new Text("beta"), new DoubleWritable(99d)));
    assertEquals(vertex.getNumEdges(), 1);
}

From source file:org.apache.giraph.lib.TestAdjacencyListTextVertexOutputFormat.java

License:Apache License

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

    BasicVertex vertex = mock(BasicVertex.class);
    when(vertex.getVertexId()).thenReturn(new Text("The Beautiful South"));
    when(vertex.getVertexValue()).thenReturn(new DoubleWritable(32.2d));
    // Create empty iterator == no edges
    when(vertex.iterator()).thenReturn(new ArrayList<Text>().iterator());

    RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    AdjacencyListVertexWriter writer = new AdjacencyListVertexWriter(tw);
    writer.initialize(tac);/*from w w w  . ja  v  a2  s .c o m*/
    writer.writeVertex(vertex);

    Text expected = new Text("The Beautiful South\t32.2");
    verify(tw).write(expected, null);
    verify(vertex, times(1)).iterator();
    verify(vertex, times(0)).getEdgeValue(Matchers.<WritableComparable>any());
}

From source file:org.apache.giraph.lib.TestAdjacencyListTextVertexOutputFormat.java

License:Apache License

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

    BasicVertex vertex = mock(BasicVertex.class);
    when(vertex.getVertexId()).thenReturn(new Text("San Francisco"));
    when(vertex.getVertexValue()).thenReturn(new DoubleWritable(0d));
    when(vertex.getNumEdges()).thenReturn(2l);
    ArrayList<Text> cities = new ArrayList<Text>();
    Collections.addAll(cities, new Text("Los Angeles"), new Text("Phoenix"));

    when(vertex.iterator()).thenReturn(cities.iterator());
    mockEdgeValue(vertex, "Los Angeles", 347.16);
    mockEdgeValue(vertex, "Phoenix", 652.48);

    RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    AdjacencyListVertexWriter writer = new AdjacencyListVertexWriter(tw);
    writer.initialize(tac);/*from  w w w .  ja v a 2  s  . c om*/
    writer.writeVertex(vertex);

    Text expected = new Text("San Francisco\t0.0\tLos Angeles\t347.16\t" + "Phoenix\t652.48");
    verify(tw).write(expected, null);
    verify(vertex, times(1)).iterator();
    verify(vertex, times(2)).getEdgeValue(Matchers.<WritableComparable>any());
}

From source file:org.apache.giraph.lib.TestAdjacencyListTextVertexOutputFormat.java

License:Apache License

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

    BasicVertex vertex = mock(BasicVertex.class);
    when(vertex.getVertexId()).thenReturn(new Text("San Francisco"));
    when(vertex.getVertexValue()).thenReturn(new DoubleWritable(0d));
    when(vertex.getNumEdges()).thenReturn(2l);
    ArrayList<Text> cities = new ArrayList<Text>();
    Collections.addAll(cities, new Text("Los Angeles"), new Text("Phoenix"));

    when(vertex.iterator()).thenReturn(cities.iterator());
    mockEdgeValue(vertex, "Los Angeles", 347.16);
    mockEdgeValue(vertex, "Phoenix", 652.48);

    RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    AdjacencyListVertexWriter writer = new AdjacencyListVertexWriter(tw);
    writer.initialize(tac);// ww w.j  a  va2s . c o m
    writer.writeVertex(vertex);

    Text expected = new Text("San Francisco:::0.0:::Los Angeles:::347.16:::" + "Phoenix:::652.48");
    verify(tw).write(expected, null);
    verify(vertex, times(1)).iterator();
    verify(vertex, times(2)).getEdgeValue(Matchers.<WritableComparable>any());
}

From source file:org.apache.giraph.lib.TestAdjacencyListTextVertexOutputFormat.java

License:Apache License

private void mockEdgeValue(BasicVertex vertex, String s, double d) {
    when(vertex.getEdgeValue(new Text(s))).thenReturn(new DoubleWritable(d));
}

From source file:org.apache.giraph.lib.TestIdWithValueTextOutputFormat.java

License:Apache License

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

    BasicVertex vertex = mock(BasicVertex.class);
    when(vertex.getVertexId()).thenReturn(new Text("Four Tops"));
    when(vertex.getVertexValue()).thenReturn(new DoubleWritable(4d));

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

    RecordWriter<Text, Text> tw = mock(RecordWriter.class);
    IdWithValueVertexWriter writer = new IdWithValueVertexWriter(tw);
    writer.initialize(tac);/*from w w  w .  j a va 2  s.  co m*/
    writer.writeVertex(vertex);

    verify(tw).write(expected, null);
    verify(vertex, times(0)).iterator();
    verify(vertex, times(0)).getEdgeValue(Matchers.<WritableComparable>any());
}

From source file:org.apache.giraph.lib.TestLongDoubleDoubleAdjacencyListVertexInputFormat.java

License:Apache License

@Test
public void testHappyPath() throws Exception {
    String input = "42\t0.1\t99\t0.2\t2000\t0.3\t4000\t0.4";

    when(rr.getCurrentValue()).thenReturn(new Text(input));
    LongDoubleDoubleAdjacencyListVertexInputFormat.VertexReader<BooleanWritable> vr = new LongDoubleDoubleAdjacencyListVertexInputFormat.VertexReader<BooleanWritable>(
            rr);//from  ww w  .  ja v a  2s . c  o m

    vr.initialize(null, tac);

    assertTrue("Should have been able to read vertex", vr.nextVertex());
    BasicVertex<LongWritable, DoubleWritable, DoubleWritable, BooleanWritable> vertex = vr.getCurrentVertex();
    setGraphState(vertex, graphState);
    assertValidVertex(conf, graphState, vertex, new LongWritable(42), new DoubleWritable(0.1),
            new Edge<LongWritable, DoubleWritable>(new LongWritable(99), new DoubleWritable(0.2)),
            new Edge<LongWritable, DoubleWritable>(new LongWritable(2000), new DoubleWritable(0.3)),
            new Edge<LongWritable, DoubleWritable>(new LongWritable(4000), new DoubleWritable(0.4)));
    assertEquals(vertex.getNumOutEdges(), 3);
}

From source file:org.apache.giraph.lib.TestLongDoubleDoubleAdjacencyListVertexInputFormat.java

License:Apache License

@Test
public void testDifferentSeparators() throws Exception {
    String input = "12345:42.42:9999999:99.9";

    when(rr.getCurrentValue()).thenReturn(new Text(input));
    conf.set(AdjacencyListVertexReader.LINE_TOKENIZE_VALUE, ":");
    LongDoubleDoubleAdjacencyListVertexInputFormat.VertexReader<BooleanWritable> vr = new LongDoubleDoubleAdjacencyListVertexInputFormat.VertexReader<BooleanWritable>(
            rr);/*  w  ww.  jav  a  2  s.  co  m*/

    vr.initialize(null, tac);
    assertTrue("Should have been able to read vertex", vr.nextVertex());
    BasicVertex<LongWritable, DoubleWritable, DoubleWritable, BooleanWritable> vertex = vr.getCurrentVertex();
    setGraphState(vertex, graphState);
    assertValidVertex(conf, graphState, vertex, new LongWritable(12345), new DoubleWritable(42.42),
            new Edge<LongWritable, DoubleWritable>(new LongWritable(9999999), new DoubleWritable(99.9)));
    assertEquals(vertex.getNumOutEdges(), 1);
}

From source file:org.apache.giraph.lib.TestTextDoubleDoubleAdjacencyListVertexInputFormat.java

License:Apache License

@Test
public void testHappyPath() throws Exception {
    String input = "Hi\t0\tCiao\t1.123\tBomdia\t2.234\tOla\t3.345";

    when(rr.getCurrentValue()).thenReturn(new Text(input));
    TextDoubleDoubleAdjacencyListVertexInputFormat.VertexReader<BooleanWritable> vr = new TextDoubleDoubleAdjacencyListVertexInputFormat.VertexReader<BooleanWritable>(
            rr);//ww w.j av  a 2 s.  c  o  m

    vr.initialize(null, tac);
    assertTrue("Should have been able to add a vertex", vr.nextVertex());
    BasicVertex<Text, DoubleWritable, DoubleWritable, BooleanWritable> vertex = vr.getCurrentVertex();
    setGraphState(vertex, graphState);
    assertValidVertex(conf, graphState, vertex, new Text("Hi"), new DoubleWritable(0),
            new Edge<Text, DoubleWritable>(new Text("Ciao"), new DoubleWritable(1.123d)),
            new Edge<Text, DoubleWritable>(new Text("Bomdia"), new DoubleWritable(2.234d)),
            new Edge<Text, DoubleWritable>(new Text("Ola"), new DoubleWritable(3.345d)));
    assertEquals(vertex.getNumOutEdges(), 3);
}