0
votes

I am trying to create a simple test that:

  1. Activates a full server embedded instance (Embedded Server and Distributed Configuration)
  2. Creates an initial test database in document mode during the first run (Create a Database)
  3. Opens the test database (Open a Database)
  4. Insert a sample record
  5. Fetch the sample record
  6. Add another node and repeat

I can roughly understand the steps individually but I am having some difficulty piecing together a simple test case. For example, the API documentation assumes a remote connection. I am not sure whether that is the applicable method here, and if so, what URL I should specify.

Once I have completed steps 1, 2 and 3 correctly, I should be able to just refer to the API documentation for steps 4 and 5.

As a novice user, I find difficult to interpret the documentation in context. Any help or clarification would be appreciated.

I am trying to run this test as a jUnit test. Here is what I have so far:

public class TestOrientDb {
private static final Logger log = Logger.getLogger(TestOrientDb.class);

@Test
public void testFullEmbeddedServer() throws Exception {
    log.debug("connectiong to database server...");
    String orientdbHome = new File("src/test/resources").getAbsolutePath(); //Set OrientDB home to current directory

    log.debug("the orientdb home: " + orientdbHome);
    System.setProperty("ORIENTDB_HOME", orientdbHome);

    OServer server = OServerMain.create();
    URL configUrl = this.getClass().getResource("/orientdb-config.xml");
    server.startup(configUrl.openStream());
    server.activate();

    //HOW DO I CREATE A DATABASE HERE?

    //HOW DO I OPEN MY DATABASE TO USE THE API LIKE THIS: http://orientdb.com/docs/last/Document-Database.html

    //SHOULD I PAUSE THE THREAD TO KEEP THE SERVER ACTIVE?
    log.debug("shutting down orientdb...");
    server.shutdown();
}}

Here is orientdb-config.xml:

<orient-server>
<users>
    <user name="root" password="password" resources="*"/>
</users>
<properties>
    <entry value="/etc/kwcn/databases" name="server.database.path"/>
    <entry name="log.console.level" value="fine"/>
</properties>
<handler class="com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin">
    <parameters>
        <!-- NODE-NAME. IF NOT SET IS AUTO GENERATED THE FIRST TIME THE SERVER RUN -->
        <!-- <parameter name="nodeName" value="europe1" /> -->
        <parameter name="enabled" value="true"/>
        <parameter name="configuration.db.default" value="${ORIENTDB_HOME}/orientdb-config.json"/>
        <parameter name="configuration.hazelcast" value="${ORIENTDB_HOME}/hazelcast.xml"/>
    </parameters>
</handler>

Here is hazelcast.xml:

<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.0.xsd"
       xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group>
    <name>orientdb</name>
    <password>orientdb</password>
</group>
<network>
    <port auto-increment="true">2434</port>
    <join>
        <multicast enabled="true">
            <multicast-group>235.1.1.1</multicast-group>
            <multicast-port>2434</multicast-port>
        </multicast>
    </join>
</network>
<executor-service>
    <pool-size>16</pool-size>
</executor-service>

Here is orientdb-config.json:

{ "autoDeploy": true, "hotAlignment": false, "executionMode": "asynchronous", "readQuorum": 1, "writeQuorum": 2, "failureAvailableNodesLessQuorum": false, "readYourWrites": true, "servers": { "*": "master" }, "clusters": { "internal": { }, "index": { }, "*": { "servers": [ "<NEW_NODE>" ] } } }

Here is the output:

  2016-02-07 16:02:17:867 INFO OrientDB auto-config DISKCACHE=10,695MB (heap=3,641MB os=16,384MB disk=71,698MB) [orientechnologies] 2016-02-07 16:02:18:016 INFO Loading configuration from input stream [OServerConfigurationLoaderXml] 2016-02-07 16:02:18:127
  INFO OrientDB Server v2.2.0-beta is starting up... [OServer] 2016-02-07 16:02:18:133 INFO Databases directory: /etc/kwcn/databases [OServer] 2016-02-07 16:02:18:133 WARNI Network configuration was not found [OServer] 2016-02-07 16:02:18:133 WARNI Found
  ORIENTDB_ROOT_PASSWORD variable, using this value as root's password [OServer] 2016-02-07 16:02:18:523 INFO OrientDB Server is active v2.2.0-beta. [OServer] 2016-02-07 16:02:18:523 INFO OrientDB Server is shutting down... [OServer] 2016-02-07 16:02:18:523
  INFO Shutting down plugins: [OServerPluginManager] DEBUG [ kwcn.TestOrientDb]: shutting down orientdb... 2016-02-07 16:02:18:524 INFO Shutting down databases: [OServer] 2016-02-07 16:02:18:565 INFO OrientDB Engine shutdown complete [Orient] 2016-02-07
  16:02:18:566 INFO OrientDB Server shutdown complete
1

1 Answers

1
votes

I suggest you to take a look at

https://github.com/orientechnologies/orientdb/blob/2.1.x/distributed/src/test/java/com/orientechnologies/orient/server/distributed/AbstractServerClusterTest.java

it's the base class of OrientDB distributed tests. Its class hierarchy seems quite complex, but in the end it just instantiates multiple servers and delegates to subclasses to test operations against them.

You can also check

https://github.com/orientechnologies/orientdb/blob/2.1.x/distributed/src/test/java/com/orientechnologies/orient/server/distributed/HATest.java

that is one of its subclasses. Actually you could just copy or extend it and implement your own logic in executeTest() method.

About your questions:

HOW DO I CREATE A DATABASE HERE?

As a normal plocal db:

new ODatabaseDocumentTx("plocal:...").create()

or

new OrientGraph("plocal:...")

//HOW DO I OPEN MY DATABASE TO USE THE API LIKE THIS:

same as above:

new ODatabaseDocumentTx("plocal:...").open("admin", "admin");

//SHOULD I PAUSE THE THREAD TO KEEP THE SERVER ACTIVE?

There is no need to pause the thread, the server creates some non-daemon threads, so it will remain active. Just make sure that someone, at the end of the tests, invokes server.shutdown() (even from another thread)