Search in sources :

Example 1 with Backend

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

the class JanusGraphTest method testClearStorage.

/**
 * Ensure clearing storage actually removes underlying database.
 * @throws Exception
 */
@Test
public void testClearStorage() throws Exception {
    tearDown();
    config.set(ConfigElement.getPath(GraphDatabaseConfiguration.DROP_ON_CLEAR), true);
    final Backend backend = getBackend(config, false);
    assertTrue("graph should exist before clearing storage", backend.getStoreManager().exists());
    clearGraph(config);
    assertFalse("graph should not exist after clearing storage", backend.getStoreManager().exists());
}
Also used : Backend(org.janusgraph.diskstorage.Backend) Test(org.junit.Test)

Example 2 with Backend

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

the class JanusGraphBaseTest method getBackend.

public static Backend getBackend(WriteConfiguration config, boolean initialize) {
    ModifiableConfiguration adjustedConfig = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, config.copy(), BasicConfiguration.Restriction.NONE);
    adjustedConfig.set(GraphDatabaseConfiguration.LOCK_LOCAL_MEDIATOR_GROUP, "tmp");
    adjustedConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "inst");
    Backend backend = new Backend(adjustedConfig);
    if (initialize) {
        backend.initialize(adjustedConfig);
    }
    return backend;
}
Also used : Backend(org.janusgraph.diskstorage.Backend)

Example 3 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 4 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)

Example 5 with Backend

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

the class GraphDatabaseConfiguration method getBackend.

public Backend getBackend() {
    Backend backend = new Backend(configuration);
    backend.initialize(configuration);
    storeFeatures = backend.getStoreFeatures();
    return backend;
}
Also used : Backend(org.janusgraph.diskstorage.Backend)

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