public void testEdgesOnWeight() throws Exception {
    Configuration config = IntervalFilterMap.createConfiguration(Edge.class, "weight", 0.3f, 0.45f);
    mapReduceDriver.withConfiguration(config);
    Map<Long, FaunusVertex> graph =
        runWithGraph(
            startPath(generateGraph(BaseTest.ExampleGraph.TINKERGRAPH, config), Edge.class),
            mapReduceDriver);
    assertEquals(graph.size(), 6);

    long counter = 0;
    for (FaunusVertex vertex : graph.values()) {
      for (Edge edge : vertex.getEdges(Direction.BOTH)) {
        if (((StandardFaunusEdge) edge).hasPaths()) {
          counter = ((StandardFaunusEdge) edge).pathCount() + counter;
          assertEquals(edge.getProperty("weight"), 0.4d);
        }
      }
    }
    assertEquals(counter, 4);

    assertEquals(
        DEFAULT_COMPAT.getCounter(mapReduceDriver, IntervalFilterMap.Counters.VERTICES_FILTERED),
        0);
    assertEquals(
        DEFAULT_COMPAT.getCounter(mapReduceDriver, IntervalFilterMap.Counters.EDGES_FILTERED), 8);

    identicalStructure(graph, ExampleGraph.TINKERGRAPH);
  }
  public void testVerticesWithPaths() throws Exception {
    Configuration config = new Configuration();
    config.setBoolean(Tokens.TITAN_HADOOP_PIPELINE_TRACK_PATHS, true);

    mapReduceDriver.withConfiguration(config);

    Map<Long, FaunusVertex> graph =
        runWithGraph(generateGraph(BaseTest.ExampleGraph.TINKERGRAPH, config), mapReduceDriver);

    assertEquals(graph.size(), 6);
    for (FaunusVertex vertex : graph.values()) {
      assertEquals(vertex.pathCount(), 1);
      assertEquals(vertex.getPaths().get(0).size(), 1);
      assertEquals(vertex.getPaths().get(0).get(0).getId(), vertex.getLongId());
      for (Edge edge : vertex.getEdges(Direction.BOTH)) {
        assertEquals(((StandardFaunusEdge) edge).pathCount(), 0);
      }
    }

    assertEquals(
        DEFAULT_COMPAT.getCounter(mapReduceDriver, VerticesMap.Counters.EDGES_PROCESSED), 12);
    assertEquals(
        DEFAULT_COMPAT.getCounter(mapReduceDriver, VerticesMap.Counters.VERTICES_PROCESSED), 6);

    identicalStructure(graph, ExampleGraph.TINKERGRAPH);
  }
  public void testVerticesWithNoPaths() throws Exception {
    Configuration config = new Configuration();
    mapReduceDriver.withConfiguration(config);

    Map<Long, FaunusVertex> graph =
        runWithGraph(generateGraph(BaseTest.ExampleGraph.TINKERGRAPH, config), mapReduceDriver);

    assertEquals(graph.size(), 6);
    for (FaunusVertex vertex : graph.values()) {
      assertEquals(vertex.pathCount(), 1);
      for (Edge edge : vertex.getEdges(Direction.BOTH)) {
        assertEquals(((StandardFaunusEdge) edge).pathCount(), 0);
      }

      try {
        vertex.getPaths();
        assertTrue(false);
      } catch (IllegalStateException e) {
        assertTrue(true);
      }
    }

    assertEquals(
        DEFAULT_COMPAT.getCounter(mapReduceDriver, VerticesMap.Counters.EDGES_PROCESSED), 12);
    assertEquals(
        DEFAULT_COMPAT.getCounter(mapReduceDriver, VerticesMap.Counters.VERTICES_PROCESSED), 6);

    identicalStructure(graph, ExampleGraph.TINKERGRAPH);
  }
  public void testVerticesBiasedStart() throws Exception {
    Configuration config = BackFilterMapReduce.createConfiguration(Vertex.class, 0);
    mapReduceDriver.withConfiguration(config);

    Map<Long, FaunusVertex> graph = generateGraph(BaseTest.ExampleGraph.TINKERGRAPH, config);

    graph
        .get(1l)
        .addPath(
            (List)
                Arrays.asList(new FaunusVertex.MicroVertex(1l), new FaunusVertex.MicroVertex(1l)),
            false);
    graph
        .get(2l)
        .addPath(
            (List)
                Arrays.asList(new FaunusVertex.MicroVertex(1l), new FaunusVertex.MicroVertex(2l)),
            false);
    graph
        .get(3l)
        .addPath(
            (List)
                Arrays.asList(new FaunusVertex.MicroVertex(2l), new FaunusVertex.MicroVertex(3l)),
            false);
    graph
        .get(4l)
        .addPath(
            (List)
                Arrays.asList(new FaunusVertex.MicroVertex(3l), new FaunusVertex.MicroVertex(4l)),
            false);
    graph
        .get(5l)
        .addPath(
            (List)
                Arrays.asList(new FaunusVertex.MicroVertex(3l), new FaunusVertex.MicroVertex(5l)),
            false);

    graph = runWithGraph(graph, mapReduceDriver);

    assertEquals(graph.size(), 6);
    assertEquals(graph.get(1l).pathCount(), 2);
    assertEquals(graph.get(2l).pathCount(), 1);
    assertEquals(graph.get(3l).pathCount(), 2);
    assertEquals(graph.get(4l).pathCount(), 0);
    assertEquals(graph.get(5l).pathCount(), 0);
    assertEquals(graph.get(6l).pathCount(), 0);

    identicalStructure(graph, ExampleGraph.TINKERGRAPH);
  }
  public void testBackingUpToVerticesFromEdges() throws Exception {
    Configuration config = BackFilterMapReduce.createConfiguration(Edge.class, 0);
    mapReduceDriver.withConfiguration(config);

    Map<Long, FaunusVertex> graph = generateGraph(BaseTest.ExampleGraph.TINKERGRAPH, config);

    ((StandardFaunusEdge) graph.get(1l).getEdges(Direction.OUT, "created").iterator().next())
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(1l), new StandardFaunusEdge.MicroEdge(2l)),
            false);
    ((StandardFaunusEdge) graph.get(6l).getEdges(Direction.OUT, "created").iterator().next())
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(6l), new StandardFaunusEdge.MicroEdge(2l)),
            false);
    ((StandardFaunusEdge) graph.get(6l).getEdges(Direction.OUT, "created").iterator().next())
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(2l), new StandardFaunusEdge.MicroEdge(2l)),
            false);
    ((StandardFaunusEdge) graph.get(6l).getEdges(Direction.OUT, "created").iterator().next())
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(2l), new StandardFaunusEdge.MicroEdge(2l)),
            false);

    graph = runWithGraph(graph, mapReduceDriver);

    assertEquals(graph.size(), 6);
    assertEquals(graph.get(1l).pathCount(), 1);
    assertEquals(graph.get(2l).pathCount(), 2);
    assertEquals(graph.get(3l).pathCount(), 0);
    assertEquals(graph.get(4l).pathCount(), 0);
    assertEquals(graph.get(5l).pathCount(), 0);
    assertEquals(graph.get(6l).pathCount(), 1);

    for (Vertex vertex : graph.values()) {
      for (Edge e : vertex.getEdges(Direction.BOTH)) {
        assertEquals(((StandardFaunusEdge) e).pathCount(), 0);
      }
    }

    identicalStructure(graph, ExampleGraph.TINKERGRAPH);
  }
  public void testBackingUpToEdgesException() throws Exception {
    Configuration config = BackFilterMapReduce.createConfiguration(Vertex.class, 1);
    mapReduceDriver.withConfiguration(config);

    Map<Long, FaunusVertex> graph = generateGraph(BaseTest.ExampleGraph.TINKERGRAPH, config);

    graph
        .get(1l)
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(1l), new StandardFaunusEdge.MicroEdge(1l)),
            false);
    graph
        .get(2l)
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(1l), new StandardFaunusEdge.MicroEdge(2l)),
            false);
    graph
        .get(3l)
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(2l), new StandardFaunusEdge.MicroEdge(3l)),
            false);
    graph
        .get(4l)
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(3l), new StandardFaunusEdge.MicroEdge(4l)),
            false);
    graph
        .get(5l)
        .addPath(
            (List)
                Arrays.asList(
                    new FaunusVertex.MicroVertex(3l), new StandardFaunusEdge.MicroEdge(5l)),
            false);

    try {
      graph = runWithGraph(graph, mapReduceDriver);
      assertFalse(true);
    } catch (Exception e) {
      assertTrue(true);
    }
  }
  public void testVerticesFullStart() throws Exception {
    Configuration config = BackFilterMapReduce.createConfiguration(Vertex.class, 0);
    mapReduceDriver.withConfiguration(config);

    Map<Long, FaunusVertex> graph =
        runWithGraph(
            startPath(generateGraph(BaseTest.ExampleGraph.TINKERGRAPH, config), Vertex.class),
            mapReduceDriver);

    assertEquals(graph.size(), 6);
    assertEquals(graph.get(1l).pathCount(), 1);
    assertEquals(graph.get(2l).pathCount(), 1);
    assertEquals(graph.get(3l).pathCount(), 1);
    assertEquals(graph.get(4l).pathCount(), 1);
    assertEquals(graph.get(5l).pathCount(), 1);
    assertEquals(graph.get(6l).pathCount(), 1);

    identicalStructure(graph, ExampleGraph.TINKERGRAPH);
  }
  public void testVerticesOnAge() throws Exception {
    Configuration config = IntervalFilterMap.createConfiguration(Vertex.class, "age", 10, 30);
    mapReduceDriver.withConfiguration(config);

    Map<Long, FaunusVertex> graph =
        runWithGraph(
            startPath(generateGraph(BaseTest.ExampleGraph.TINKERGRAPH, config), Vertex.class),
            mapReduceDriver);
    assertEquals(graph.size(), 6);
    assertEquals(graph.get(1l).pathCount(), 1);
    assertEquals(graph.get(2l).pathCount(), 1);
    assertEquals(graph.get(3l).pathCount(), 0);
    assertEquals(graph.get(4l).pathCount(), 0);
    assertEquals(graph.get(5l).pathCount(), 0);
    assertEquals(graph.get(6l).pathCount(), 0);

    assertEquals(
        DEFAULT_COMPAT.getCounter(mapReduceDriver, IntervalFilterMap.Counters.VERTICES_FILTERED),
        4);
    assertEquals(
        DEFAULT_COMPAT.getCounter(mapReduceDriver, IntervalFilterMap.Counters.EDGES_FILTERED), 0);

    identicalStructure(graph, ExampleGraph.TINKERGRAPH);
  }