Search in sources :

Example 6 with Backend

use of org.janusgraph.diskstorage.Backend in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testNestedWrites.

private void testNestedWrites(String initialValue, String updatedValue) throws BackendException {
    // This method touches a single vertex with multiple transactions,
    // leading to deadlock under BDB and cascading test failures. Check for
    // the hasTxIsolation() store feature, which is currently true for BDB
    // but false for HBase/Cassandra. This is kind of a hack; a more robust
    // approach might implement different methods/assertions depending on
    // whether the store is capable of deadlocking or detecting conflicting
    // writes and aborting a transaction.
    Backend b = null;
    try {
        b = graph.getConfiguration().getBackend();
        if (b.getStoreFeatures().hasTxIsolation()) {
            log.info("Skipping " + getClass().getSimpleName() + "." + methodName.getMethodName());
            return;
        }
    } finally {
        if (null != b)
            b.close();
    }
    final String propName = "foo";
    // Write schema and one vertex
    PropertyKey prop = makeKey(propName, String.class);
    createExternalVertexIndex(prop, INDEX);
    finishSchema();
    JanusGraphVertex v = graph.addVertex();
    if (null != initialValue)
        v.property(VertexProperty.Cardinality.single, propName, initialValue);
    graph.tx().commit();
    Object id = v.id();
    // Open two transactions and modify the same vertex
    JanusGraphTransaction vertexDeleter = graph.newTransaction();
    JanusGraphTransaction propDeleter = graph.newTransaction();
    getV(vertexDeleter, id).remove();
    if (null == updatedValue)
        getV(propDeleter, id).property(propName).remove();
    else
        getV(propDeleter, id).property(VertexProperty.Cardinality.single, propName, updatedValue);
    vertexDeleter.commit();
    propDeleter.commit();
    // The vertex must not exist after deletion
    graph.tx().rollback();
    assertEquals(null, getV(graph, id));
    assertEmpty(graph.query().has(propName).vertices());
    if (null != updatedValue)
        assertEmpty(graph.query().has(propName, updatedValue).vertices());
    graph.tx().rollback();
}
Also used : Backend(org.janusgraph.diskstorage.Backend) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey)

Example 7 with Backend

use of org.janusgraph.diskstorage.Backend in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testClearStorage.

/**
 * Ensure clearing storage actually removes underlying graph and index databases.
 * @throws Exception
 */
@Test
public void testClearStorage() throws Exception {
    GraphOfTheGodsFactory.load(graph);
    tearDown();
    config.set(ConfigElement.getPath(GraphDatabaseConfiguration.DROP_ON_CLEAR), true);
    final Backend backend = getBackend(config, false);
    assertStorageExists(backend, true);
    clearGraph(config);
    try {
        backend.close();
    } catch (Exception e) {
    /* Most backends do not support closing after clearing */
    }
    try (final Backend newBackend = getBackend(config, false)) {
        assertStorageExists(newBackend, false);
    }
}
Also used : Backend(org.janusgraph.diskstorage.Backend) JanusGraphException(org.janusgraph.core.JanusGraphException) BackendException(org.janusgraph.diskstorage.BackendException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Backend (org.janusgraph.diskstorage.Backend)7 Test (org.junit.Test)2 ExecutionException (java.util.concurrent.ExecutionException)1 JanusGraphException (org.janusgraph.core.JanusGraphException)1 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 PropertyKey (org.janusgraph.core.PropertyKey)1 BackendException (org.janusgraph.diskstorage.BackendException)1 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)1 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)1 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)1