Search in sources :

Example 41 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestMigration method canReadAndUpgradeOldIndexStoreFormat.

@Test
public void canReadAndUpgradeOldIndexStoreFormat() throws Exception {
    String path = "target/var/old-index-store";
    Neo4jTestCase.deleteFileOrDirectory(new File(path));
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    db.shutdown();
    InputStream stream = getClass().getClassLoader().getResourceAsStream("old-index.db");
    writeFile(stream, new File(path, "index.db"));
    db = new EmbeddedGraphDatabase(path);
    assertTrue(db.index().existsForNodes("indexOne"));
    Index<Node> indexOne = db.index().forNodes("indexOne");
    verifyConfiguration(db, indexOne, LuceneIndexImplementation.EXACT_CONFIG);
    assertTrue(db.index().existsForNodes("indexTwo"));
    Index<Node> indexTwo = db.index().forNodes("indexTwo");
    verifyConfiguration(db, indexTwo, LuceneIndexImplementation.FULLTEXT_CONFIG);
    assertTrue(db.index().existsForRelationships("indexThree"));
    Index<Relationship> indexThree = db.index().forRelationships("indexThree");
    verifyConfiguration(db, indexThree, LuceneIndexImplementation.EXACT_CONFIG);
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) InputStream(java.io.InputStream) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) File(java.io.File) Test(org.junit.Test)

Example 42 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class ServerProcess method startup.

@Override
public void startup(Pair<String, String> config) throws Throwable {
    String storeDir = config.first();
    String backupConfigValue = config.other();
    if (backupConfigValue == null) {
        this.db = new EmbeddedGraphDatabase(storeDir);
    } else {
        this.db = new EmbeddedGraphDatabase(storeDir, stringMap(ENABLE_ONLINE_BACKUP, backupConfigValue));
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase)

Example 43 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestBigBatchStore method testHighIds.

private void testHighIds(long highMark, int minus, int requiredHeapMb) {
    assumeTrue(machineIsOkToRunThisTest(testName.getMethodName(), requiredHeapMb));
    long idBelow = highMark - minus;
    setHighId(IdType.NODE, idBelow);
    setHighId(IdType.RELATIONSHIP, idBelow);
    setHighId(IdType.PROPERTY, idBelow);
    setHighId(IdType.ARRAY_BLOCK, idBelow);
    setHighId(IdType.STRING_BLOCK, idBelow);
    String propertyKey = "name";
    int intPropertyValue = 123;
    String stringPropertyValue = "Long string, longer than would fit in shortstring";
    long[] arrayPropertyValue = new long[] { 1021L, 321L, 343212L };
    long nodeBelowTheLine = db.createNode(map(propertyKey, intPropertyValue));
    assertEquals(idBelow, nodeBelowTheLine);
    long nodeAboveTheLine = db.createNode(map(propertyKey, stringPropertyValue));
    long relBelowTheLine = db.createRelationship(nodeBelowTheLine, nodeAboveTheLine, this, map(propertyKey, arrayPropertyValue));
    assertEquals(idBelow, relBelowTheLine);
    long relAboveTheLine = db.createRelationship(nodeAboveTheLine, nodeBelowTheLine, this, null);
    assertEquals(highMark, relAboveTheLine);
    assertEquals(highMark, nodeAboveTheLine);
    assertEquals(intPropertyValue, db.getNodeProperties(nodeBelowTheLine).get(propertyKey));
    assertEquals(stringPropertyValue, db.getNodeProperties(nodeAboveTheLine).get(propertyKey));
    assertTrue(Arrays.equals(arrayPropertyValue, (long[]) db.getRelationshipProperties(relBelowTheLine).get(propertyKey)));
    assertEquals(asSet(asList(relBelowTheLine, relAboveTheLine)), asIds(db.getRelationships(idBelow)));
    db.shutdown();
    db = new BatchInserterImpl(PATH);
    assertEquals(asSet(asList(relBelowTheLine, relAboveTheLine)), asIds(db.getRelationships(idBelow)));
    db.shutdown();
    GraphDatabaseService edb = new EmbeddedGraphDatabase(PATH);
    assertEquals(nodeAboveTheLine, edb.getNodeById(highMark).getId());
    assertEquals(relBelowTheLine, edb.getNodeById(idBelow).getSingleRelationship(this, Direction.OUTGOING).getId());
    assertEquals(relAboveTheLine, edb.getNodeById(idBelow).getSingleRelationship(this, Direction.INCOMING).getId());
    assertEquals(asSet(asList(edb.getRelationshipById(relBelowTheLine), edb.getRelationshipById(relAboveTheLine))), asSet(asCollection(edb.getNodeById(idBelow).getRelationships())));
    edb.shutdown();
    db = new BatchInserterImpl(PATH);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService)

Example 44 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestBigStore method testHighIds.

private void testHighIds(long highMark, int minus, int requiredHeapMb) {
    if (!machineIsOkToRunThisTest(testName.getMethodName(), requiredHeapMb)) {
        return;
    }
    long idBelow = highMark - minus;
    setHighIds(idBelow);
    String propertyKey = "name";
    int intPropertyValue = 123;
    String stringPropertyValue = "Long string, longer than would fit in shortstring";
    long[] arrayPropertyValue = new long[] { 1021L, 321L, 343212L };
    Transaction tx = db.beginTx();
    Node nodeBelowTheLine = db.createNode();
    nodeBelowTheLine.setProperty(propertyKey, intPropertyValue);
    assertEquals(idBelow, nodeBelowTheLine.getId());
    Node nodeAboveTheLine = db.createNode();
    nodeAboveTheLine.setProperty(propertyKey, stringPropertyValue);
    Relationship relBelowTheLine = nodeBelowTheLine.createRelationshipTo(nodeAboveTheLine, this);
    relBelowTheLine.setProperty(propertyKey, arrayPropertyValue);
    assertEquals(idBelow, relBelowTheLine.getId());
    Relationship relAboveTheLine = nodeAboveTheLine.createRelationshipTo(nodeBelowTheLine, this);
    assertEquals(highMark, relAboveTheLine.getId());
    assertEquals(highMark, nodeAboveTheLine.getId());
    assertEquals(intPropertyValue, nodeBelowTheLine.getProperty(propertyKey));
    assertEquals(stringPropertyValue, nodeAboveTheLine.getProperty(propertyKey));
    assertTrue(Arrays.equals(arrayPropertyValue, (long[]) relBelowTheLine.getProperty(propertyKey)));
    tx.success();
    tx.finish();
    for (int i = 0; i < 2; i++) {
        assertEquals(nodeAboveTheLine, db.getNodeById(highMark));
        assertEquals(idBelow, nodeBelowTheLine.getId());
        assertEquals(highMark, nodeAboveTheLine.getId());
        assertEquals(idBelow, relBelowTheLine.getId());
        assertEquals(highMark, relAboveTheLine.getId());
        assertEquals(relBelowTheLine, db.getNodeById(idBelow).getSingleRelationship(this, Direction.OUTGOING));
        assertEquals(relAboveTheLine, db.getNodeById(idBelow).getSingleRelationship(this, Direction.INCOMING));
        assertEquals(idBelow, relBelowTheLine.getId());
        assertEquals(highMark, relAboveTheLine.getId());
        assertEquals(asSet(asList(relBelowTheLine, relAboveTheLine)), asSet(asCollection(db.getNodeById(idBelow).getRelationships())));
        if (i == 0) {
            db.shutdown();
            db = new EmbeddedGraphDatabase(PATH);
        }
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship)

Example 45 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestNeo4j method testKeepLogsConfig.

@Test
public void testKeepLogsConfig() {
    Map<String, String> config = new HashMap<String, String>();
    config.put(Config.KEEP_LOGICAL_LOGS, "nioneodb");
    String storeDir = "target/configdb";
    deleteFileOrDirectory(storeDir);
    EmbeddedGraphDatabase db = new EmbeddedGraphDatabase(storeDir, config);
    XaDataSourceManager xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    XaDataSource xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(xaDs.isLogicalLogKept());
    db.shutdown();
    config.remove(Config.KEEP_LOGICAL_LOGS);
    db = new EmbeddedGraphDatabase(storeDir, config);
    xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(!xaDs.isLogicalLogKept());
    db.shutdown();
    config.put(Config.KEEP_LOGICAL_LOGS, "true");
    db = new EmbeddedGraphDatabase(storeDir, config);
    xaDsMgr = db.getConfig().getTxModule().getXaDataSourceManager();
    xaDs = xaDsMgr.getXaDataSource("nioneodb");
    assertTrue(xaDs.isLogicalLogKept());
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) HashMap(java.util.HashMap) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) Test(org.junit.Test)

Aggregations

EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)84 Test (org.junit.Test)50 File (java.io.File)35 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)32 Node (org.neo4j.graphdb.Node)26 Transaction (org.neo4j.graphdb.Transaction)17 Relationship (org.neo4j.graphdb.Relationship)14 BeforeClass (org.junit.BeforeClass)13 HashMap (java.util.HashMap)7 BatchInserterImpl (org.neo4j.kernel.impl.batchinsert.BatchInserterImpl)6 RandomAccessFile (java.io.RandomAccessFile)5 BatchInserter (org.neo4j.kernel.impl.batchinsert.BatchInserter)5 BatchInserterIndex (org.neo4j.graphdb.index.BatchInserterIndex)4 TransactionManager (javax.transaction.TransactionManager)3 Before (org.junit.Before)3 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)3 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)3 BatchInserterIndexProvider (org.neo4j.graphdb.index.BatchInserterIndexProvider)3 IndexManager (org.neo4j.graphdb.index.IndexManager)3 Transaction (javax.transaction.Transaction)2