2016-02-07 37 views
0

我試圖創建一個簡單的測試:OrientDB完整的嵌入式羣集測試

  1. 激活整個服務器的嵌入式實例(Embedded ServerDistributed Configuration
  2. 第一次運行時創建的文檔模式中的最初的測試數據庫(Create a Database
  3. 打開測試數據庫(Open a Database
  4. 插入樣本記錄
  5. 抓取樣品記錄
  6. 添加另一個節點,並重復

我可以大致瞭解單獨的步驟,但我有一些困難,拼湊一個簡單的測試用例。例如,API文檔假定有一個遠程連接。我不確定這是否是適用的方法,如果是,我應該指定哪個URL。

一旦我已經完成的步驟1,2和3正確地,我應該能夠以僅僅將API文檔步驟4和5

作爲新手用戶,我發現難以解釋的文檔中上下文。任何幫助或澄清將不勝感激。

我試圖運行這個測試作爲一個jUnit測試。以下是我迄今爲止:

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(); 
}} 

這裏是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> 

這裏是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> 

這是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>" ] } } } 

這裏是輸出:

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

我建議你看一看

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

它的基類OrientDB分佈式試驗。它的類層次結構看起來相當複雜,但最後它只是實例化多個服務器並委託給子類來測試針對它們的操作。

您還可以檢查

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

這是它的一個子類。實際上你可以複製或擴展它,並在executeTest()方法中實現你自己的邏輯。

關於你的問題:

如何創建一個數據庫嗎?

作爲正常plocal分貝:

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

new OrientGraph("plocal:...") 

//如何打開MY數據庫以使用像這樣的API:

同上:

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

//我應該暫停THR EAD保持服務器活動?

沒有必要暫停線程,服務器創建一些非守護線程,因此它將保持活動狀態。只要確保某人在測試結束時調用server.shutdown()(甚至可以從另一個線程調用)