com.thinkaurelius.titan.core.TitanFactory Java Examples

The following examples show how to use com.thinkaurelius.titan.core.TitanFactory. 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: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGraphConfigUsedByThreadBoundTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
    assertEquals("ALL",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("LOCAL_QUORUM",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
 
Example #2
Source File: TitanTxLongVersionedGraphTest.java    From antiquity with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected ActiveVersionedGraph<?, Long> generateGraph() {
    File f = new File("/tmp/testgraph");
    if (f.exists()) {
        if (f.isDirectory()) {
            try {
                FileUtils.deleteDirectory(f);
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        } else {
            f.delete();
        }

    }

    Configuration c = new BaseConfiguration();
    c.addProperty("storage.directory","/tmp/testgraph");
    TitanGraph g = TitanFactory.open(c);

    return new ActiveVersionedGraph.ActiveVersionedTransactionalGraphBuilder<TitanGraph, Long>(g, new LongGraphIdentifierBehavior())
            .init(true).conf(null).build();
}
 
Example #3
Source File: PopulateDB.java    From titan-web-example with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Configuration conf = new PropertiesConfiguration(TitanGraphFactory.PROPS_PATH);

    TitanGraph g = TitanFactory.open(conf);

    // Uncomment the following if your graph is already populated and you want to clear it out first.
    // g.close();
    // TitanCleanup.clear(g);
    // g = TitanFactory.open(conf);

    // Interested in the source?
    // https://github.com/thinkaurelius/titan/blob/titan05/titan-core/src/main/java/com/thinkaurelius/titan/example/GraphOfTheGodsFactory.java
    GraphOfTheGodsFactory.load(g);
    g.close();
    System.out.println("Success.");
}
 
Example #4
Source File: Titan0GraphDatabase.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static TitanGraph getGraphInstance() {
    if (graphInstance == null) {
        synchronized (Titan0GraphDatabase.class) {
            if (graphInstance == null) {
                Configuration config;
                try {
                    config = getConfiguration();
                } catch (AtlasException e) {
                    throw new RuntimeException(e);
                }

                graphInstance = TitanFactory.open(config);
                atlasGraphInstance = new Titan0Graph();
                validateIndexBackend(config);
            }
        }
    }
    return graphInstance;
}
 
Example #5
Source File: Titan1GraphDatabase.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static TitanGraph getGraphInstance() {
    if (graphInstance == null) {
        synchronized (Titan1GraphDatabase.class) {
            if (graphInstance == null) {
                Configuration config;
                try {
                    config = getConfiguration();
                } catch (AtlasException e) {
                    throw new RuntimeException(e);
                }

                graphInstance = TitanFactory.open(config);
                atlasGraphInstance = new Titan1Graph();
                validateIndexBackend(config);
            }
        }
    }
    return graphInstance;
}
 
Example #6
Source File: Driver.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
private void doWork()
    {
        TitanGraph graph = TitanFactory.build().set("storage.backend", "inmemory").open();

        // do "auto" transaction work
        graph.addVertex("type", "human");
        graph.tx().commit();

        // do "named" transaction work
//        TitanTransaction tx = graph.buildTransaction().logIdentifier("david1").start();
//        Vertex v = tx.addVertex("type", "dog");
//        Long id = (Long)v.id();
//        tx.commit();

//        GraphTraversalSource g = graph.traversal();
//        Vertex v1 = g.V(id.longValue()).next();
//        v1.remove();

        graph.close();
    }
 
Example #7
Source File: ElasticSearchConfigTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testTitanFactoryBuilder()
{
    String baseDir = Joiner.on(File.separator).join("target", "es", "titanfactory_jvmlocal_ext");
    TitanFactory.Builder builder = TitanFactory.build();
    builder.set("storage.backend", "inmemory");
    builder.set("index." + INDEX_NAME + ".elasticsearch.interface", "NODE");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
    TitanGraph graph = builder.open(); // Must not throw an exception
    assertTrue(graph.isOpen());
    graph.close();
}
 
Example #8
Source File: MizoRDD.java    From mizo with Apache License 2.0 6 votes vote down vote up
/**
 * Given a path for Titan config file, connects and gets the internal Titan types,
 * converting them to MizoTitanRelationTypes mapped by type-ids
 * @param titanConfigPath Path to Titan's config path
 * @return Mapping between relation type-ids to InternalRelationType instances
 */
protected static HashMap<Long, MizoTitanRelationType> loadRelationTypes(String titanConfigPath) {
    TitanGraph g = TitanFactory.open(titanConfigPath);
    StandardTitanTx tx = (StandardTitanTx)g.buildTransaction().readOnly().start();

    HashMap<Long, MizoTitanRelationType> relations = Maps.newHashMap();

    tx.query()
            .has(BaseKey.SchemaCategory, Contain.IN, Lists.newArrayList(TitanSchemaCategory.values()))
            .vertices()
            .forEach(v -> {
                if (v instanceof InternalRelationType)
                    relations.put(v.longId(), new MizoTitanRelationType((InternalRelationType)v));
            });

    tx.close();

    try {
        ((StandardTitanGraph)g).getBackend().close();
    } catch (BackendException e) {
        e.printStackTrace();
    }

    return relations;
}
 
Example #9
Source File: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGraphConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.newTransaction();
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("THREE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example #10
Source File: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
            .customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
            .customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();

    assertEquals("ONE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example #11
Source File: VertexIDAssignerTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private static TitanGraph getInMemoryGraph() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, InMemoryStoreManager.class.getCanonicalName());
    config.set(GraphDatabaseConfiguration.IDS_FLUSH, false);
    config.set(GraphDatabaseConfiguration.IDAUTHORITY_WAIT, Duration.ofMillis(1L));
    return TitanFactory.open(config);
}
 
Example #12
Source File: TinkerpopFeaturesTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public TitanGraph open(boolean useVertexIdSetting)
{
    TitanFactory.Builder builder = TitanFactory.build();
    builder.set("storage.backend", "inmemory");
    builder.set("graph.set-vertex-id", useVertexIdSetting);
    return builder.open();
}
 
Example #13
Source File: TitanGraphFactory.java    From titan-web-example with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    try {
        logger.info("Titan Properties Path: {}", PROPS_PATH);
        Configuration conf = new PropertiesConfiguration(PROPS_PATH);
        g = TitanFactory.open(conf);
        logger.info("Titan graph loaded successfully.");
    } catch (ConfigurationException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #14
Source File: TitanSuite.java    From peapod with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setGraphProvider() throws IOException {
    GraphTest.graphProvider = new GraphProvider() {
        public Graph getGraph() throws IOException {
            TitanGraph graph = TitanFactory.build().set("storage.backend", "inmemory").open();
            TitanManagement management = graph.openManagement();
            management.makePropertyKey("location").dataType(String.class).cardinality(Cardinality.LIST).make();
            management.makePropertyKey("firstName").dataType(String.class).cardinality(Cardinality.LIST).make();
            management.commit();
            return graph;
        }
    };

}
 
Example #15
Source File: HadoopVertexScanMapper.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
protected void setup(Context context) throws IOException, InterruptedException {
    /* Don't call super implementation super.setup(context); */
    org.apache.hadoop.conf.Configuration hadoopConf = DEFAULT_COMPAT.getContextConfiguration(context);
    ModifiableHadoopConfiguration scanConf = ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, hadoopConf);
    VertexScanJob vertexScan = getVertexScanJob(scanConf);
    ModifiableConfiguration graphConf = getTitanConfiguration(context);
    TitanGraph graph = TitanFactory.open(graphConf);
    job = VertexJobConverter.convert(graph, vertexScan);
    metrics = new HadoopContextScanMetrics(context);
    finishSetup(scanConf, graphConf);
}
 
Example #16
Source File: GraphOfTheGodsFactory.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static TitanGraph create(final String directory) {
    TitanFactory.Builder config = TitanFactory.build();
    config.set("storage.backend", "berkeleyje");
    config.set("storage.directory", directory);
    config.set("index." + INDEX_NAME + ".backend", "elasticsearch");
    config.set("index." + INDEX_NAME + ".directory", directory + File.separator + "es");
    config.set("index." + INDEX_NAME + ".elasticsearch.local-mode", true);
    config.set("index." + INDEX_NAME + ".elasticsearch.client-only", false);

    TitanGraph graph = config.open();
    GraphOfTheGodsFactory.load(graph);
    return graph;
}
 
Example #17
Source File: ThriftGraphSpeedTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
protected StandardTitanGraph getGraph() throws BackendException {


    if (null == graph) {
        GraphDatabaseConfiguration graphconfig = new GraphDatabaseConfiguration(conf);
        graphconfig.getBackend().clearStorage();
        log.debug("Cleared backend storage");
        graph = (StandardTitanGraph)TitanFactory.open(conf);
        initializeGraph(graph);
    }
    return graph;
}
 
Example #18
Source File: AbstractTitanGraphProvider.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test, String testMethodName, final LoadGraphWith.GraphData loadGraphWith) {
    ModifiableConfiguration conf = getTitanConfiguration(graphName, test, testMethodName);
    conf.set(GraphDatabaseConfiguration.COMPUTER_RESULT_MODE, "persist");
    conf.set(GraphDatabaseConfiguration.AUTO_TYPE, "tp3");
    Map<String, Object> result = new HashMap<>();
    conf.getAll().entrySet().stream().forEach(e -> result.put(ConfigElement.getPath(e.getKey().element, e.getKey().umbrellaElements), e.getValue()));
    result.put(Graph.GRAPH, TitanFactory.class.getName());
    return result;
}
 
Example #19
Source File: VertexListTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testLists() {

    int num = 13;

    TitanGraph g = TitanFactory.open("inmemory");
    StandardTitanTx tx = (StandardTitanTx) g.newTransaction();
    VertexLongList vll = new VertexLongList(tx);
    VertexArrayList val = new VertexArrayList(tx);
    for (int i=0; i<num; i++) {
        TitanVertex v = tx.addVertex();
        vll.add(v);
        val.add(v);
    }

    assertEquals(num, Iterables.size(vll));
    assertEquals(num, Iterables.size(val));

    vll.sort();
    val.sort();
    assertTrue(vll.isSorted());
    assertTrue(val.isSorted());

    for (Iterable<TitanVertex> iterable : new Iterable[]{val,vll}) {
        Iterator<TitanVertex> iter = iterable.iterator();
        TitanVertex previous = null;
        for (int i = 0; i < num; i++) {
            TitanVertex next = iter.next();
            if (previous!=null) assertTrue(previous.longId()<next.longId());
            previous = next;
        }
        try {
            iter.next();
            fail();
        } catch (NoSuchElementException ex) {

        }
    }


    tx.commit();
    g.close();

}
 
Example #20
Source File: TitanGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 4 votes vote down vote up
private static final TitanGraph buildTitanGraph(GraphDatabaseType type, File dbPath, BenchmarkConfiguration bench,
    boolean batchLoading)
{
    final Configuration conf = generateBaseTitanConfiguration(type, dbPath, batchLoading, bench);
    final Configuration storage = conf.subset(GraphDatabaseConfiguration.STORAGE_NS.getName());

    if (GraphDatabaseType.TITAN_CASSANDRA == type)
    {
        storage.addProperty("hostname", "localhost");
        storage.addProperty("transactions", Boolean.toString(batchLoading));
    }
    else if (GraphDatabaseType.TITAN_CASSANDRA_EMBEDDED == type)
    {
        // TODO(amcp) - this line seems broken:
        // throws: Unknown configuration element in namespace
        // [root.storage]: cassandra-config-dir
        storage.addProperty("cassandra-config-dir", "configuration/cassandra.yaml");
        storage.addProperty("transactions", Boolean.toString(batchLoading));
    }
    else if (GraphDatabaseType.TITAN_DYNAMODB == type)
    {
        final Configuration dynamodb = storage.subset("dynamodb");
        final Configuration client = dynamodb.subset(Constants.DYNAMODB_CLIENT_NAMESPACE.getName());
        final Configuration credentials = client.subset(Constants.DYNAMODB_CLIENT_CREDENTIALS_NAMESPACE.getName());
        storage.addProperty("transactions", Boolean.toString(batchLoading));
        if (bench.getDynamodbDataModel() == null)
        {
            throw new IllegalArgumentException("data model must be set for dynamodb benchmarking");
        }
        if (GraphDatabaseType.TITAN_DYNAMODB == type && bench.getDynamodbEndpoint() != null
            && !bench.getDynamodbEndpoint().isEmpty())
        {
            client.addProperty(Constants.DYNAMODB_CLIENT_ENDPOINT.getName(), bench.getDynamodbEndpoint());
            client.addProperty(Constants.DYNAMODB_CLIENT_MAX_CONN.getName(), bench.getDynamodbWorkerThreads());
        } else {
            throw new IllegalArgumentException("require endpoint");
        }

        if (bench.getDynamodbCredentialsFqClassName() != null
            && !bench.getDynamodbCredentialsFqClassName().isEmpty())
        {
            credentials.addProperty(Constants.DYNAMODB_CREDENTIALS_CLASS_NAME.getName(), bench.getDynamodbCredentialsFqClassName());
        }

        if (bench.getDynamodbCredentialsCtorArguments() != null)
        {
            credentials.addProperty(Constants.DYNAMODB_CREDENTIALS_CONSTRUCTOR_ARGS.getName(),
                bench.getDynamodbCredentialsCtorArguments());
        }

        dynamodb.addProperty(Constants.DYNAMODB_FORCE_CONSISTENT_READ.getName(), bench.dynamodbConsistentRead());
        Configuration executor = client.subset(Constants.DYNAMODB_CLIENT_EXECUTOR_NAMESPACE.getName());
        executor.addProperty(Constants.DYNAMODB_CLIENT_EXECUTOR_CORE_POOL_SIZE.getName(), bench.getDynamodbWorkerThreads());
        executor.addProperty(Constants.DYNAMODB_CLIENT_EXECUTOR_MAX_POOL_SIZE.getName(), bench.getDynamodbWorkerThreads());
        executor.addProperty(Constants.DYNAMODB_CLIENT_EXECUTOR_KEEP_ALIVE.getName(), TimeUnit.MINUTES.toMillis(1));
        executor.addProperty(Constants.DYNAMODB_CLIENT_EXECUTOR_QUEUE_MAX_LENGTH.getName(), bench.getTitanBufferSize());

        final long writeTps = bench.getDynamodbTps();
        final long readTps = Math.max(1, bench.dynamodbConsistentRead() ? writeTps : writeTps / 2);

        final Configuration stores = dynamodb.subset(Constants.DYNAMODB_STORES_NAMESPACE.getName());
        for (String storeName : Constants.REQUIRED_BACKEND_STORES)
        {
            final Configuration store = stores.subset(storeName);
            store.addProperty(Constants.STORES_DATA_MODEL.getName(), bench.getDynamodbDataModel().name());
            store.addProperty(Constants.STORES_CAPACITY_READ.getName(), readTps);
            store.addProperty(Constants.STORES_CAPACITY_WRITE.getName(), writeTps);
            store.addProperty(Constants.STORES_READ_RATE_LIMIT.getName(), readTps);
            store.addProperty(Constants.STORES_WRITE_RATE_LIMIT.getName(), writeTps);
        }
    }
    return TitanFactory.open(conf);
}
 
Example #21
Source File: VertexJobConverter.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public void initializeGraph(Configuration config) {
    if (!provided) {
        this.graph = (StandardTitanGraph) TitanFactory.open((BasicConfiguration) config);
    }
}
 
Example #22
Source File: TitanHadoopSetupImpl.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public TitanHadoopSetupImpl(final Configuration config) {
    scanConf = ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, config);
    BasicConfiguration bc = scanConf.getTitanGraphConf();
    graph = (StandardTitanGraph) TitanFactory.open(bc);
    tx = (StandardTitanTx)graph.buildTransaction().readOnly().vertexCacheSize(200).start();
}
 
Example #23
Source File: StorageSetup.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static TitanGraph getInMemoryGraph() {
    return TitanFactory.open(getInMemoryConfiguration());
}
 
Example #24
Source File: InMemoryConfigurationTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public void initialize(ConfigOption option, Object value) {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(option,value);
    graph = (StandardTitanGraph) TitanFactory.open(config);
}
 
Example #25
Source File: TitanFactoryShorthandTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testTitanFactoryShorthand() {
    TitanGraph g = TitanFactory.open("inmemory");
    g.close();
}
 
Example #26
Source File: TitanIndexTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Category({BrittleTests.class})
    @Test
    public void testIndexReplay() throws Exception {
        final TimestampProvider times = graph.getConfiguration().getTimestampProvider();
        final Instant startTime = times.getTime();
        clopen(option(SYSTEM_LOG_TRANSACTIONS), true
                , option(KCVSLog.LOG_READ_LAG_TIME, TRANSACTION_LOG), Duration.ofMillis(50)
                , option(LOG_READ_INTERVAL, TRANSACTION_LOG), Duration.ofMillis(250)
                , option(MAX_COMMIT_TIME), Duration.ofSeconds(1)
                , option(STORAGE_WRITE_WAITTIME), Duration.ofMillis(300)
                , option(TestMockIndexProvider.INDEX_BACKEND_PROXY, INDEX), readConfig.get(INDEX_BACKEND, INDEX)
                , option(INDEX_BACKEND, INDEX), TestMockIndexProvider.class.getName()
                , option(TestMockIndexProvider.INDEX_MOCK_FAILADD, INDEX), true
        );

        PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
        PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
        mgmt.buildIndex("mi", Vertex.class).addKey(name, getTextMapping()).addKey(age).buildMixedIndex(INDEX);
        finishSchema();
        Vertex vs[] = new TitanVertex[4];

        vs[0] = tx.addVertex("name", "Big Boy Bobson", "age", 55);
        newTx();
        vs[1] = tx.addVertex("name", "Long Little Lewis", "age", 35);
        vs[2] = tx.addVertex("name", "Tall Long Tiger", "age", 75);
        vs[3] = tx.addVertex("name", "Long John Don", "age", 15);
        newTx();
        vs[2] = getV(tx, vs[2]);
        vs[2].remove();
        vs[3] = getV(tx, vs[3]);
        vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy");
        vs[3].property("age").remove();
        newTx();
        vs[0] = getV(tx, vs[0]);
        vs[0].property(VertexProperty.Cardinality.single, "age", 66);
        newTx();

        clopen();
        //Just to make sure nothing has been persisted to index
        evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"),
                ElementCategory.VERTEX, 0, new boolean[]{true, true}, "mi");
        /*
        Transaction Recovery
         */
        TransactionRecovery recovery = TitanFactory.startTransactionRecovery(graph, startTime);
        //wait
        Thread.sleep(12000L);

        recovery.shutdown();
        long[] recoveryStats = ((StandardTransactionLogProcessor) recovery).getStatistics();

        clopen();

        evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"),
                ElementCategory.VERTEX, 2, new boolean[]{true, true}, "mi");
        evaluateQuery(tx.query().has("name", Text.CONTAINS, "long"),
                ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mi");
//        TitanVertex v = Iterables.getOnlyElement(tx.query().has("name",Text.CONTAINS,"long").vertices());
//        System.out.println(v.getProperty("age"));
        evaluateQuery(tx.query().has("name", Text.CONTAINS, "long").interval("age", 30, 40),
                ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mi");
        evaluateQuery(tx.query().has("age", 75),
                ElementCategory.VERTEX, 0, new boolean[]{true, true}, "mi");
        evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy").interval("age", 60, 70),
                ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mi");
        evaluateQuery(tx.query().interval("age", 0, 100),
                ElementCategory.VERTEX, 2, new boolean[]{true, true}, "mi");


        assertEquals(1, recoveryStats[0]); //schema transaction was successful
        assertEquals(4, recoveryStats[1]); //all 4 index transaction had provoked errors in the indexing backend
    }
 
Example #27
Source File: GraphOfTheGodsFactory.java    From titan1withtp3.1 with Apache License 2.0 3 votes vote down vote up
/**
 * Calls {@link TitanFactory#open(String)}, passing the Titan configuration file path
 * which must be the sole element in the {@code args} array, then calls
 * {@link #load(com.thinkaurelius.titan.core.TitanGraph)} on the opened graph,
 * then calls {@link com.thinkaurelius.titan.core.TitanGraph#close()}
 * and returns.
 * <p/>
 * This method may call {@link System#exit(int)} if it encounters an error, such as
 * failure to parse its arguments.  Only use this method when executing main from
 * a command line.  Use one of the other methods on this class ({@link #create(String)}
 * or {@link #load(com.thinkaurelius.titan.core.TitanGraph)}) when calling from
 * an enclosing application.
 *
 * @param args a singleton array containing a path to a Titan config properties file
 */
public static void main(String args[]) {
    if (null == args || 1 != args.length) {
        System.err.println("Usage: GraphOfTheGodsFactory <titan-config-file>");
        System.exit(1);
    }

    TitanGraph g = TitanFactory.open(args[0]);
    load(g);
    g.close();
}