org.apache.tinkerpop.gremlin.structure.util.GraphFactory Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.GraphFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiGraphsTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static HugeGraph openGraphWithBackend(String graph, String backend,
                                             String serializer,
                                             String... configs) {
    PropertiesConfiguration conf = Utils.getConf();
    Configuration config = new BaseConfiguration();
    for (Iterator<String> keys = conf.getKeys(); keys.hasNext();) {
        String key = keys.next();
        config.setProperty(key, conf.getProperty(key));
    }
    ((BaseConfiguration) config).setDelimiterParsingDisabled(true);
    config.setProperty(CoreOptions.STORE.name(), graph);
    config.setProperty(CoreOptions.BACKEND.name(), backend);
    config.setProperty(CoreOptions.SERIALIZER.name(), serializer);
    for (int i = 0; i < configs.length;) {
        config.setProperty(configs[i++], configs[i++]);
    }
    return ((HugeGraph) GraphFactory.open(config));
}
 
Example #2
Source File: InputOutputRDDTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReadFromWriteToArbitraryRDD() throws Exception {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName());
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, ExampleInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, ExampleOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, TestHelper.makeTestDataDirectory(this.getClass(), "shouldReadFromWriteToArbitraryRDD"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    ////////
    Graph graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(SparkGraphComputer.class),
                            "gremlin-groovy",
                            "g.V()").create(graph)).submit().get();
}
 
Example #3
Source File: PersistedInputOutputRDDIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotPersistRDDAcrossJobs() throws Exception {
    Spark.create("local[4]");
    final String rddName = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDIntegrateTest.class, UUID.randomUUID().toString());
    final Configuration configuration = super.getBaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, false);  // because the spark context is NOT persisted, neither is the RDD
    Graph graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(SparkGraphComputer.class),
                            "gremlin-groovy",
                            "g.V()").create(graph)).submit().get();
    ////////
    Spark.create("local[4]");
    assertFalse(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(0, Spark.getContext().getPersistentRDDs().size());
    Spark.close();
}
 
Example #4
Source File: PersistedInputOutputRDDIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotHaveDanglingPersistedComputeRDDs() throws Exception {
    Spark.create("local[4]");
    final String rddName = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDIntegrateTest.class, UUID.randomUUID().toString());
    final Configuration configuration = super.getBaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, GryoOutputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    Graph graph = GraphFactory.open(configuration);
    ///
    assertEquals(6, graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class)).V().out().count().next().longValue());
    assertFalse(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(0, Spark.getContext().getPersistentRDDs().size());
    //
    assertEquals(2, graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class)).V().out().out().count().next().longValue());
    assertFalse(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(0, Spark.getContext().getPersistentRDDs().size());
    ///////
    Spark.close();
}
 
Example #5
Source File: InputRDDTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSupportHadoopGraphOLTP() {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName());
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, ExampleInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, GryoOutputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, TestHelper.makeTestDataDirectory(this.getClass(), "shouldSupportHadoopGraphOLTP"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    ////////
    Graph graph = GraphFactory.open(configuration);
    GraphTraversalSource g = graph.traversal(); // OLTP;
    assertEquals("person", g.V().has("age", 29).next().label());
    assertEquals(Long.valueOf(4), g.V().count().next());
    assertEquals(Long.valueOf(0), g.E().count().next());
    assertEquals(Long.valueOf(2), g.V().has("age", P.gt(30)).count().next());
}
 
Example #6
Source File: OutputRDDTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldWriteToArbitraryRDD() throws Exception {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName());
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, ExampleOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, TestHelper.makeTestDataDirectory(this.getClass(), "shouldWriteToArbitraryRDD"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    ////////
    Graph graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class)),
                            "gremlin-groovy",
                            "g.V()").create(graph)).submit().get();
}
 
Example #7
Source File: GraphConstructionTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * A {@link Graph} should maintain the original {@code Configuration} object passed to it via {@link GraphFactory}.
 */
@Test
public void shouldMaintainOriginalConfigurationObjectGivenToFactory() throws Exception {
    final Configuration originalConfig = graphProvider.newGraphConfiguration("temp2", this.getClass(), name.getMethodName(), null);
    final Graph createdGraph = GraphFactory.open(originalConfig);

    final Configuration configInGraph = createdGraph.configuration();
    final AtomicInteger keyCount = new AtomicInteger(0);
    originalConfig.getKeys().forEachRemaining(k -> {
        assertTrue(configInGraph.containsKey(k));
        keyCount.incrementAndGet();
    });

    // need some keys in the originalConfig for this test to be meaningful
    assertTrue(keyCount.get() > 0);
    assertEquals(keyCount.get(), IteratorUtils.count(configInGraph.getKeys()));

    graphProvider.clear(createdGraph, originalConfig);
}
 
Example #8
Source File: DocumentGraphConsumerTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testDocumentGraphConsumerCanCopeWithSameEntityExternalId()
    throws AnalysisEngineProcessException, ResourceInitializationException, IOException,
        URISyntaxException {

  properties.setProperty(
      TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY,
      VertexProperty.Cardinality.list.name());
  writeProperties();

  Person p1 = Annotations.createPerson(jCas, 0, 4, "test");
  Person p2 = Annotations.createPerson(jCas, 0, 4, "test");

  assertEquals(p1.getExternalId(), p2.getExternalId());

  processJCas(
      DocumentGraphConsumer.PARAM_GRAPH_CONFIG,
      propertiesFile.getAbsolutePath(),
      DocumentGraphConsumer.PARAM_OUTPUT_RELATIONS_AS_LINKS,
      true);
  Graph graph = GraphFactory.open(propertiesFile.getAbsolutePath());

  assertTrue(graph.traversal().V(p1.getExternalId()).hasNext());
}
 
Example #9
Source File: SimpleAuthenticator.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void setup(final Map<String,Object> config) {
    logger.info("Initializing authentication with the {}", SimpleAuthenticator.class.getName());

    if (null == config) {
        throw new IllegalArgumentException(String.format(
                "Could not configure a %s - provide a 'config' in the 'authentication' settings",
                SimpleAuthenticator.class.getName()));
    }

    if (!config.containsKey(CONFIG_CREDENTIALS_DB)) {
        throw new IllegalStateException(String.format(
                "Credentials configuration missing the %s key that points to a graph config file", CONFIG_CREDENTIALS_DB));
    }

    final Graph graph = GraphFactory.open((String) config.get(CONFIG_CREDENTIALS_DB));

    if (graph instanceof TinkerGraph) {
        // have to create the indices because they are not stored in gryo
        final TinkerGraph tinkerGraph = (TinkerGraph) graph;
        tinkerGraph.createIndex(PROPERTY_USERNAME, Vertex.class);
    }

    credentialStore = graph.traversal(CredentialTraversalSource.class);
    logger.info("CredentialGraph initialized at {}", credentialStore);
}
 
Example #10
Source File: GremlinConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
public void doInitialize(UimaContext aContext) throws ResourceInitializationException {
  try {
    g = GraphFactory.open(graphConfig);
  } catch (RuntimeException re) {
    throw new ResourceInitializationException(re);
  }

  Collections.addAll(listMergeTypes, mergeTypes);
}
 
Example #11
Source File: PersistedInputOutputRDDIntegrateTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPersistRDDBasedOnStorageLevel() throws Exception {
    Spark.create("local[4]");
    int counter = 0;
    for (final String storageLevel : Arrays.asList("MEMORY_ONLY", "DISK_ONLY", "MEMORY_ONLY_SER", "MEMORY_AND_DISK_SER")) {
        assertEquals(counter, Spark.getRDDs().size());
        assertEquals(counter, Spark.getContext().getPersistentRDDs().size());
        counter++;
        final String rddName = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDIntegrateTest.class, UUID.randomUUID().toString());
        final Configuration configuration = super.getBaseConfiguration();
        configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
        configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
        configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
        configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_STORAGE_LEVEL, storageLevel);
        configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName);
        configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
        Graph graph = GraphFactory.open(configuration);
        graph.compute(SparkGraphComputer.class)
                .result(GraphComputer.ResultGraph.NEW)
                .persist(GraphComputer.Persist.EDGES)
                .program(TraversalVertexProgram.build()
                        .traversal(graph.traversal().withComputer(SparkGraphComputer.class),
                                "gremlin-groovy",
                                "g.V().groupCount('m').by('name').out()").create(graph)).submit().get();
        ////////
        assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
        assertEquals(StorageLevel.fromString(storageLevel), Spark.getRDD(Constants.getGraphLocation(rddName)).getStorageLevel());
        assertEquals(counter, Spark.getRDDs().size());
        assertEquals(counter, Spark.getContext().getPersistentRDDs().size());
    }
    Spark.close();
}
 
Example #12
Source File: InputRDDTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReadFromArbitraryRDD() {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName());
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, ExampleInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, GryoOutputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, TestHelper.makeTestDataDirectory(this.getClass(), "shouldReadFromArbitraryRDD"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    ////////
    Graph graph = GraphFactory.open(configuration);
    assertEquals(123l, graph.traversal().withComputer(SparkGraphComputer.class).V().values("age").sum().next());
    assertEquals(Long.valueOf(4l), graph.traversal().withComputer(SparkGraphComputer.class).V().count().next());
}
 
Example #13
Source File: GraphConstructionTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * All Gremlin Structure implementations should be constructable through {@link GraphFactory}.
 */
@Test
public void shouldOpenGraphThroughGraphFactoryViaApacheConfig() throws Exception {
    final Graph expectedGraph = graph;
    final Configuration c = graphProvider.newGraphConfiguration("temp1", this.getClass(), name.getMethodName(), null);
    final Graph createdGraph = GraphFactory.open(c);

    assertNotNull(createdGraph);
    assertEquals(expectedGraph.getClass(), createdGraph.getClass());

    graphProvider.clear(createdGraph, c);
}
 
Example #14
Source File: DefaultGraphManager.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new instance using the {@link Settings} from Gremlin Server.
 */
public DefaultGraphManager(final Settings settings) {
    settings.graphs.entrySet().forEach(e -> {
        try {
            final Graph newGraph = GraphFactory.open(e.getValue());
            graphs.put(e.getKey(), newGraph);
            logger.info("Graph [{}] was successfully configured via [{}].", e.getKey(), e.getValue());
        } catch (RuntimeException re) {
            logger.warn(String.format("Graph [%s] configured at [%s] could not be instantiated and will not be available in Gremlin Server.  GraphFactory message: %s",
                    e.getKey(), e.getValue(), re.getMessage()), re);
            if (re.getCause() != null) logger.debug("GraphFactory exception", re.getCause());
        }
    });
}
 
Example #15
Source File: MultiGraphsTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public static List<HugeGraph> openGraphs(String... graphNames) {
    List<HugeGraph> graphs = new ArrayList<>(graphNames.length);
    PropertiesConfiguration conf = Utils.getConf();
    Configuration config = new BaseConfiguration();
    for (Iterator<String> keys = conf.getKeys(); keys.hasNext();) {
        String key = keys.next();
        config.setProperty(key, conf.getProperty(key));
    }
    ((BaseConfiguration) config).setDelimiterParsingDisabled(true);
    for (String graphName : graphNames) {
        config.setProperty(CoreOptions.STORE.name(), graphName);
        graphs.add((HugeGraph) GraphFactory.open(config));
    }
    return graphs;
}
 
Example #16
Source File: DocumentGraphConsumerTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocumentGraphConsumerRelationAsLinkCanCopeWithSameRelationExternalId()
    throws AnalysisEngineProcessException, ResourceInitializationException, IOException,
        URISyntaxException {

  properties.setProperty(
      TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY,
      VertexProperty.Cardinality.list.name());
  writeProperties();

  Person p1 = Annotations.createPerson(jCas, 0, 10, "source");
  Person p2 = Annotations.createPerson(jCas, 10, 20, "target");

  Relation r1 = new Relation(jCas);
  r1.setBegin(0);
  r1.setEnd(4);
  r1.setValue("test");
  r1.setSource(p1);
  r1.setTarget(p2);
  r1.addToIndexes(jCas);

  Relation r2 = new Relation(jCas);
  r2.setBegin(0);
  r2.setEnd(4);
  r2.setValue("test");
  r2.setSource(p1);
  r2.setTarget(p2);
  r2.addToIndexes(jCas);

  assertEquals(r1.getExternalId(), r2.getExternalId());

  processJCas(
      DocumentGraphConsumer.PARAM_GRAPH_CONFIG,
      propertiesFile.getAbsolutePath(),
      DocumentGraphConsumer.PARAM_OUTPUT_RELATIONS_AS_LINKS,
      false);
  Graph graph = GraphFactory.open(propertiesFile.getAbsolutePath());

  assertTrue(graph.traversal().V(r1.getExternalId()).hasNext());
}
 
Example #17
Source File: StandardAuthenticator.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(HugeConfig config) {
    String graphName = config.get(ServerOptions.AUTH_GRAPH_STORE);
    String graphPath = config.getMap(ServerOptions.GRAPHS).get(graphName);
    E.checkArgument(graphPath != null,
                    "Invalid graph name '%s'", graphName);
    this.graph = (HugeGraph) GraphFactory.open(graphPath);
}
 
Example #18
Source File: DocumentGraphConsumerTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocumentGraphConsumerCanCopeWithSameReferenceTargetExternalId()
    throws AnalysisEngineProcessException, ResourceInitializationException, IOException,
        URISyntaxException {

  properties.setProperty(
      TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY,
      VertexProperty.Cardinality.list.name());
  writeProperties();

  Person p1 = Annotations.createPerson(jCas, 0, 4, "test");
  Person p2 = Annotations.createPerson(jCas, 0, 4, "test");
  Annotations.createReferenceTarget(jCas, p1, p2);
  Annotations.createReferenceTarget(jCas, p1, p2);

  String externalId = ConsumerUtils.getExternalId(ImmutableList.of(p1, p2));

  processJCas(
      DocumentGraphConsumer.PARAM_GRAPH_CONFIG,
      propertiesFile.getAbsolutePath(),
      DocumentGraphConsumer.PARAM_OUTPUT_RELATIONS_AS_LINKS,
      true,
      DocumentGraphConsumer.PARAM_OUTPUT_REFERENTS,
      true);
  Graph graph = GraphFactory.open(propertiesFile.getAbsolutePath());

  assertTrue(graph.traversal().V(externalId).hasNext());
}
 
Example #19
Source File: GraphManager.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
private void loadGraph(String name, String path) {
    final Graph graph = GraphFactory.open(path);
    this.graphs.put(name, graph);
    LOG.info("Graph '{}' was successfully configured via '{}'", name, path);

    if (this.requireAuthentication() &&
        !(graph instanceof HugeGraphAuthProxy)) {
        LOG.warn("You may need to support access control for '{}' with {}",
                 path, HugeFactoryAuthProxy.GRAPH_FACTORY);
    }
}
 
Example #20
Source File: ComputeWeight.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) throws InterruptedException, IOException {
  Graph hadoopGraph = null;

  try {
    LOGGER.info("Connect to the hadoop graph");
    hadoopGraph = GraphFactory.open(new PropertiesConfiguration(HADOOP_CONFIG_FILE));
    ComputeWeightVertexProgram.Builder builder = ComputeWeightVertexProgram.build().withRwGraphConfig(Schema.CONFIG_FILE);

    ComputerResult result = hadoopGraph.
        compute().
        program(
            builder.create(hadoopGraph)
        ).
        vertices(hasLabel(Schema.USER)).
        submit().get();
    result.close();
    hadoopGraph.close();
    Spark.close();

    hadoopGraph = null;
  } catch (Exception e) {
    e.printStackTrace();
    try {
      if (hadoopGraph != null) {
        hadoopGraph.close();
        Spark.close();
      }
    } catch (Exception e1) {
      System.err.println("Couldn't close graph or spark...");
    }
  }

  // we need to call this one or else the program will be waiting forever
  LOGGER.info("bye bye");
  System.exit(0);
}
 
Example #21
Source File: DocumentGraphConsumerTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocumentGraphConsumerCanCopeWithSameRelationExternalId()
    throws AnalysisEngineProcessException, ResourceInitializationException, IOException,
        URISyntaxException {

  properties.setProperty(
      TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY,
      VertexProperty.Cardinality.list.name());
  writeProperties();

  Person p1 = Annotations.createPerson(jCas, 0, 10, "source");
  Person p2 = Annotations.createPerson(jCas, 10, 20, "target");

  Relation r1 = new Relation(jCas);
  r1.setBegin(0);
  r1.setEnd(4);
  r1.setValue("test");
  r1.setSource(p1);
  r1.setTarget(p2);
  r1.addToIndexes(jCas);

  Relation r2 = new Relation(jCas);
  r2.setBegin(0);
  r2.setEnd(4);
  r2.setValue("test");
  r2.setSource(p1);
  r2.setTarget(p2);
  r2.addToIndexes(jCas);

  assertEquals(r1.getExternalId(), r2.getExternalId());

  processJCas(
      DocumentGraphConsumer.PARAM_GRAPH_CONFIG,
      propertiesFile.getAbsolutePath(),
      DocumentGraphConsumer.PARAM_OUTPUT_RELATIONS_AS_LINKS,
      true);
  Graph graph = GraphFactory.open(propertiesFile.getAbsolutePath());

  assertTrue(graph.traversal().E(r1.getExternalId()).hasNext());
}
 
Example #22
Source File: JanusGraphDriver.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void read(final String modelPath) throws XMLStreamException, IOException, ConfigurationException {
	//final PropertiesConfiguration conf = new PropertiesConfiguration("conf/jgex-berkeleyje.properties");
	final PropertiesConfiguration conf = new PropertiesConfiguration("conf/jgex-inmemory.properties");
	graph = GraphFactory.open(conf);
	graph.io(IoCore.graphml()).readGraph(modelPath);
}
 
Example #23
Source File: CassandraInputFormatIT.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadGraphOfTheGods() {
    GraphOfTheGodsFactory.load(graph, null, true);
    assertEquals(12L, (long) graph.traversal().V().count().next());
    Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties");
    GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class));
    assertEquals(12L, (long) t.V().count().next());
}
 
Example #24
Source File: GryoSerializerIntegrateTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldHaveAllRegisteredGryoSerializerClasses() throws Exception {
    // this is a stress test that ensures that when data is spilling to disk, persisted to an RDD, etc. the correct classes are registered with GryoSerializer.
    final TinkerGraph randomGraph = TinkerGraph.open();
    int totalVertices = 200000;
    TestHelper.createRandomGraph(randomGraph, totalVertices, 100);
    final String inputLocation = TestHelper.makeTestDataFile(GryoSerializerIntegrateTest.class,
                                                             UUID.randomUUID().toString(),
                                                             "random-graph.kryo");
    randomGraph.io(IoCore.gryo()).writeGraph(inputLocation);
    randomGraph.clear();
    randomGraph.close();

    final String outputLocation = TestHelper.makeTestDataDirectory(GryoSerializerIntegrateTest.class, UUID.randomUUID().toString());
    Configuration configuration = getBaseConfiguration();
    configuration.clearProperty(Constants.SPARK_SERIALIZER); // ensure proper default to GryoSerializer
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, inputLocation);
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, GryoOutputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, outputLocation);
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, false);
    Graph graph = GraphFactory.open(configuration);
    final GraphTraversal.Admin<Vertex, Map<Vertex, Collection<Vertex>>> traversal = graph.traversal().withComputer(SparkGraphComputer.class).V().group("m").<Map<Vertex, Collection<Vertex>>>cap("m").asAdmin();
    assertTrue(traversal.hasNext());
    assertEquals(traversal.next(), traversal.getSideEffects().get("m"));
    assertFalse(traversal.hasNext());
    assertTrue(traversal.getSideEffects().exists("m"));
    assertTrue(traversal.getSideEffects().get("m") instanceof Map);
    assertEquals(totalVertices, traversal.getSideEffects().<Map>get("m").size());

    configuration = getBaseConfiguration();
    configuration.clearProperty(Constants.SPARK_SERIALIZER); // ensure proper default to GryoSerializer
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, inputLocation);
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_STORAGE_LEVEL, "DISK_ONLY");
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, "persisted-rdd");
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    graph = GraphFactory.open(configuration);
    assertEquals(totalVertices, graph.compute(SparkGraphComputer.class).program(PageRankVertexProgram.build().iterations(2).create(graph)).submit().get().graph().traversal().V().count().next().longValue());

    configuration = getBaseConfiguration();
    configuration.clearProperty(Constants.SPARK_SERIALIZER); // ensure proper default to GryoSerializer
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, "persisted-rdd");
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, PersistedInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, GryoOutputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, outputLocation);
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    graph = GraphFactory.open(configuration);
    assertEquals(totalVertices, graph.traversal().withComputer(SparkGraphComputer.class).V().count().next().longValue());

    configuration = getBaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, "persisted-rdd");
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, PersistedInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, outputLocation);
    configuration.setProperty(Constants.GREMLIN_SPARK_GRAPH_STORAGE_LEVEL, "MEMORY_ONLY"); // this should be ignored as you can't change the persistence level once created
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_STORAGE_LEVEL, "MEMORY_AND_DISK");
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    graph = GraphFactory.open(configuration);
    assertEquals(totalVertices, graph.traversal().withComputer(SparkGraphComputer.class).V().count().next().longValue());
}
 
Example #25
Source File: SparkInterceptorStrategyTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldSuccessfullyEvaluateInterceptedTraversals() throws Exception {
    final Configuration configuration = getBaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, TestHelper.makeTestDataDirectory(SparkSingleIterationStrategyTest.class, UUID.randomUUID().toString()));
    configuration.setProperty(Constants.GREMLIN_HADOOP_DEFAULT_GRAPH_COMPUTER, SparkGraphComputer.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    ///
    Graph graph = GraphFactory.open(configuration);
    GraphTraversalSource g = graph.traversal().withComputer().withoutStrategies(SparkSingleIterationStrategy.class);
    assertFalse(g.getStrategies().getStrategy(SparkSingleIterationStrategy.class).isPresent());
    assertFalse(g.V().count().explain().toString().contains(SparkSingleIterationStrategy.class.getSimpleName()));
    assertTrue(g.getStrategies().getStrategy(SparkInterceptorStrategy.class).isPresent());
    assertTrue(g.V().count().explain().toString().contains(SparkInterceptorStrategy.class.getSimpleName()));
    /// SparkCountInterceptor matches
    test(SparkStarBarrierInterceptor.class, 6l, g.V().count());
    test(SparkStarBarrierInterceptor.class, 2l, g.V().hasLabel("software").count());
    test(SparkStarBarrierInterceptor.class, 2l, g.V().hasLabel("person").has("age", P.gt(30)).count());
    test(SparkStarBarrierInterceptor.class, 2l, g.V().hasLabel("person").has("age", P.gt(30)).values("name").count());
    test(SparkStarBarrierInterceptor.class, 2l, g.V().hasLabel("person").has("age", P.gt(30)).properties("name").count());
    test(SparkStarBarrierInterceptor.class, 4l, g.V().hasLabel("person").has("age", P.gt(30)).properties("name", "age").count());
    test(SparkStarBarrierInterceptor.class, 3l, g.V().hasLabel("person").has("age", P.gt(30)).out().count());
    test(SparkStarBarrierInterceptor.class, 0l, g.V().hasLabel("person").has("age", P.gt(30)).out("knows").count());
    test(SparkStarBarrierInterceptor.class, 3l, g.V().has(T.label, P.not(P.within("robot", "android")).and(P.within("person", "software"))).hasLabel("person").has("age", P.gt(30)).out("created").count());
    test(SparkStarBarrierInterceptor.class, 3l, g.V(1).out().count());
    test(SparkStarBarrierInterceptor.class, 2l, g.V(1).out("knows").count());
    test(SparkStarBarrierInterceptor.class, 3l, g.V(1).out("knows", "created").count());
    test(SparkStarBarrierInterceptor.class, 5l, g.V(1, 4).out("knows", "created").count());
    test(SparkStarBarrierInterceptor.class, 1l, g.V(2).in("knows").count());
    test(SparkStarBarrierInterceptor.class, 0l, g.V(6).has("name", "peter").in().count());
    test(SparkStarBarrierInterceptor.class, 6l, g.V().as("a").values("name").as("b").count());
    test(SparkStarBarrierInterceptor.class, 6l, g.V().as("a").count());
    test(SparkStarBarrierInterceptor.class, 1l, g.V().has("name", "marko").as("a").values("name").as("b").count());
    test(SparkStarBarrierInterceptor.class, 4l, g.V().has(T.label, P.not(P.within("robot", "android")).and(P.within("person", "software"))).hasLabel("person").has("age").out("created").count());
    test(SparkStarBarrierInterceptor.class, 123l, g.V().has("age").values("age").sum());
    test(SparkStarBarrierInterceptor.class, 67l, g.V().has("age").has("age", P.gt(30)).values("age").sum());
    test(SparkStarBarrierInterceptor.class, 27, g.V().hasLabel("person").values("age").min());
    test(SparkStarBarrierInterceptor.class, 35, g.V().hasLabel("person").values("age").max());
    test(SparkStarBarrierInterceptor.class, new HashMap<String, Long>() {{
        put("software", 2l);
        put("person", 4l);
    }}, g.V().<String>groupCount().by(T.label));
    test(SparkStarBarrierInterceptor.class, Collections.singletonMap("person", 2l), g.V().has("person", "age", P.lt(30)).<String>groupCount().by(T.label));
    test(SparkStarBarrierInterceptor.class, new HashMap<String, Long>() {{
        put("software", 2l);
        put("person", 4l);
    }}, g.V().<String, Long>group().by(T.label).by(__.count()));
    test(SparkStarBarrierInterceptor.class, 123l, g.V().hasLabel("person").values("age").fold(0l, Operator.sum));
    /// No interceptor matches
    test(2l, g.V().out().out().count());
    test(6l, g.E().count());
    test(2l, g.V().out().out().count());
    test(6l, g.V().out().values("name").count());
    test(2l, g.V().out("knows").values("name").count());
    test(3l, g.V().in().has("name", "marko").count());
    test(0l, g.V().repeat(__.dedup()).times(2).count());
    test(6l, g.V().dedup().count());
    test(4l, g.V().hasLabel("person").order().by("age").count());
    test(1l, g.V().count().count());
    test(2l, g.V().limit(2).count());
    test(3l, g.V().tail(3).count());
}
 
Example #26
Source File: LocalPropertyTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldSetThreadLocalProperties() throws Exception {
    final String testName = "ThreadLocalProperties";
    final String rddName = TestHelper.makeTestDataDirectory(LocalPropertyTest.class, UUID.randomUUID().toString());
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName());
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    configuration.setProperty("spark.jobGroup.id", "22");
    Graph graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class)),
                            "gremlin-groovy",
                            "g.V()").create(graph)).submit().get();
    ////////
    SparkConf sparkConfiguration = new SparkConf();
    sparkConfiguration.setAppName(testName);
    ConfUtil.makeHadoopConfiguration(configuration).forEach(entry -> sparkConfiguration.set(entry.getKey(), entry.getValue()));
    JavaSparkContext sparkContext = new JavaSparkContext(SparkContext.getOrCreate(sparkConfiguration));
    JavaSparkStatusTracker statusTracker = sparkContext.statusTracker();
    assertTrue(statusTracker.getJobIdsForGroup("22").length >= 1);
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    ///////
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, PersistedInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, null);
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, null);

    // just a note that this value should have always been set to true, but from the initial commit was false.
    // interestingly the last assertion had always passed up to spark 2.3.x when it started to fail. apparently
    // that assertion should likely have never passed, so it stands to reason that there was a bug in spark in
    // 2.2.x that was resolved for 2.3.x....that's my story and i'm sticking to it.
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    configuration.setProperty("spark.jobGroup.id", "44");
    graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.NOTHING)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(SparkGraphComputer.class),
                            "gremlin-groovy",
                            "g.V()").create(graph)).submit().get();
    ///////
    assertTrue(statusTracker.getJobIdsForGroup("44").length >= 1);
}
 
Example #27
Source File: PersistedInputOutputRDDIntegrateTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test
public void testComplexChain() throws Exception {
    Spark.create("local[4]");

    final String rddName = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDIntegrateTest.class, "testComplexChain", "graphRDD");
    final String rddName2 = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDIntegrateTest.class, "testComplexChain", "graphRDD2");
    final Configuration configuration = super.getBaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);

    assertFalse(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(0, Spark.getContext().getPersistentRDDs().size());
    Graph graph = GraphFactory.open(configuration);
    graph = graph.compute(SparkGraphComputer.class).persist(GraphComputer.Persist.EDGES).program(PageRankVertexProgram.build().iterations(2).create(graph)).submit().get().graph();
    GraphTraversalSource g = graph.traversal();
    assertEquals(6l, g.V().count().next().longValue());
    assertEquals(6l, g.E().count().next().longValue());
    assertEquals(6l, g.V().values(PageRankVertexProgram.PAGE_RANK).count().next().longValue());
    ////
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(1, Spark.getContext().getPersistentRDDs().size());
    ////
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, PersistedInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName2);
    ////
    graph = GraphFactory.open(configuration);
    graph = graph.compute(SparkGraphComputer.class).persist(GraphComputer.Persist.EDGES).mapReduce(PageRankMapReduce.build().create()).program(PageRankVertexProgram.build().iterations(2).create(graph)).submit().get().graph();
    g = graph.traversal();
    assertEquals(6l, g.V().count().next().longValue());
    assertEquals(6l, g.E().count().next().longValue());
    assertEquals(6l, g.V().values(PageRankVertexProgram.PAGE_RANK).count().next().longValue());
    ////
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName2)));
    assertTrue(Spark.hasRDD(Constants.getMemoryLocation(rddName2, PageRankMapReduce.DEFAULT_MEMORY_KEY)));
    assertEquals(3, Spark.getContext().getPersistentRDDs().size());
    ////
    graph = GraphFactory.open(configuration);
    graph = graph.compute(SparkGraphComputer.class).persist(GraphComputer.Persist.VERTEX_PROPERTIES).program(PageRankVertexProgram.build().iterations(2).create(graph)).submit().get().graph();
    g = graph.traversal();
    assertEquals(6l, g.V().count().next().longValue());
    assertEquals(0l, g.E().count().next().longValue());
    assertEquals(6l, g.V().values(PageRankVertexProgram.PAGE_RANK).count().next().longValue());
    ////
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName2)));
    assertFalse(Spark.hasRDD(Constants.getMemoryLocation(rddName2, PageRankMapReduce.DEFAULT_MEMORY_KEY)));
    assertEquals(2, Spark.getContext().getPersistentRDDs().size());
    ////
    graph = GraphFactory.open(configuration);
    graph = graph.compute(SparkGraphComputer.class).persist(GraphComputer.Persist.NOTHING).program(PageRankVertexProgram.build().iterations(2).create(graph)).submit().get().graph();
    assertFalse(Spark.hasRDD(Constants.getGraphLocation(rddName2)));
    g = graph.traversal();
    assertEquals(0l, g.V().count().next().longValue());
    assertEquals(0l, g.E().count().next().longValue());
    assertEquals(0l, g.V().values(PageRankVertexProgram.PAGE_RANK).count().next().longValue());
    ////
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertFalse(Spark.hasRDD(Constants.getGraphLocation(rddName2)));
    assertFalse(Spark.hasRDD(Constants.getMemoryLocation(rddName2, PageRankMapReduce.DEFAULT_MEMORY_KEY)));
    assertEquals(1, Spark.getContext().getPersistentRDDs().size());
    Spark.close();
}
 
Example #28
Source File: PersistedInputOutputRDDIntegrateTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldPersistRDDAcrossJobs() throws Exception {
    Spark.create("local[4]");
    final String rddName = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDIntegrateTest.class, UUID.randomUUID().toString());
    final String rddName2 = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDIntegrateTest.class, UUID.randomUUID().toString());
    final Configuration configuration = super.getBaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    Graph graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(SparkGraphComputer.class),
                            "gremlin-groovy",
                            "g.V().count()").create(graph)).submit().get();
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(1, Spark.getContext().getPersistentRDDs().size());
    ///////
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, PersistedInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName2);
    graph = GraphFactory.open(configuration);
    assertEquals(6, graph.traversal().withComputer(SparkGraphComputer.class).V().out().count().next().longValue());
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(1, Spark.getContext().getPersistentRDDs().size());
    ///////
    graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(SparkGraphComputer.class),
                            "gremlin-groovy",
                            "g.V().count()").create(graph)).submit().get();
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName2)));
    assertEquals(2, Spark.getContext().getPersistentRDDs().size());
    ///////
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, PersistedInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName2);
    graph = GraphFactory.open(configuration);
    assertEquals(6, graph.traversal().withComputer(SparkGraphComputer.class).V().out().count().next().longValue());
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(1, Spark.getContext().getPersistentRDDs().size());
    ///////
    graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(SparkGraphComputer.class),
                            "gremlin-groovy",
                            "g.V().count()").create(graph)).submit().get();
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName2)));
    assertEquals(2, Spark.getContext().getPersistentRDDs().size());
    ///////
    graph = GraphFactory.open(configuration);
    assertEquals(6, graph.traversal().withComputer(SparkGraphComputer.class).V().out().count().next().longValue());
    assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(1, Spark.getContext().getPersistentRDDs().size());
    Spark.close();
}
 
Example #29
Source File: HadoopGraphFactory.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@VisibleForTesting
public synchronized HadoopGraph getGraph(Keyspace keyspace) {
    return (HadoopGraph) GraphFactory.open(addHadoopProperties(keyspace.name()).properties());
}
 
Example #30
Source File: HBaseGraphTest.java    From hgraphdb with Apache License 2.0 4 votes vote down vote up
@Before
public void makeGraph() {
    graph = (HBaseGraph) GraphFactory.open(generateGraphConfig("testgraph"));
}