Create in-memory OrientDB databases for unit tests

42 Views Asked by At

I have an application which connects to a separate OrientDB database.

I'd like to write some self-contained tests to test this, and I've done something similar with H2 and an in-memory database that works nicely.

I've tried using OrientDB embedded or memory but not had much luck.

I've got this far, based off this:

import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;

public class OrientDBTest {
    public static void main(final String args[]) {
    final String user = "admin", password = "adminpwd", name = "myDB";

    try (OrientDB orientDB = new OrientDB("embedded:/tmp/", user, password, OrientDBConfig.defaultConfig())) {
        orientDB.execute("create database " + name + " MEMORY users ( " + user + " identified by '" + password
            + "' role admin)");

        try (final ODatabaseSession databaseSession = orientDB.open(name, user, password)) {
        databaseSession.createClassIfNotExist("Case", "V").createProperty("CaseId", OType.INTEGER);

        }

        new OrientGraphFactory("memory:" + name, user, password).getNoTx().getVertices("Case.CaseId", "blah")
            .forEach(System.out::println);
    }
    }
}

With the following in my pom.xml:

    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-graphdb</artifactId>
        <version>3.2.18</version>
    </dependency>
    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-jdbc</artifactId>
        <version>3.2.18</version>
    </dependency>
    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>spring-data-orientdb-graph</artifactId>
        <version>0.14</version>
        <exclusions>
            <exclusion>
                <groupId>com.orientechnologies</groupId>
                <artifactId>orientdb-client</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.orientechnologies</groupId>
                <artifactId>orientdb-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.orientechnologies</groupId>
                <artifactId>orientdb-graphdb</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

But when executed throws java.lang.IllegalArgumentException: OClass not found in the schema: Case

This suggests that the database I'm connecting to isn't the one whose schema I've just constructed.

I'm hoping there's a very small, simple way to create a temporary in-memory OrientDB instance.

0

There are 0 best solutions below