Search in sources :

Example 56 with EmbeddedGraphDatabase

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

the class LuceneIndexSiteExamples method setUpDb.

@BeforeClass
public static void setUpDb() {
    String path = "target/var/examples";
    Neo4jTestCase.deleteFileOrDirectory(new File(path));
    graphDb = new EmbeddedGraphDatabase(path);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 57 with EmbeddedGraphDatabase

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

the class TestRecovery method testIndexDeleteIssue.

@Test
public void testIndexDeleteIssue() throws Exception {
    GraphDatabaseService db = newGraphDbService();
    db.index().forNodes("index");
    db.shutdown();
    assertEquals(0, Runtime.getRuntime().exec(new String[] { "java", "-cp", System.getProperty("java.class.path"), AddDeleteQuit.class.getName(), getDbPath() }).waitFor());
    new EmbeddedGraphDatabase(getDbPath()).shutdown();
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Test(org.junit.Test)

Example 58 with EmbeddedGraphDatabase

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

the class TestRecovery method testRecovery.

@Test
public void testRecovery() throws Exception {
    final GraphDatabaseService graphDb = newGraphDbService();
    final Index<Node> nodeIndex = graphDb.index().forNodes("node-index");
    final Index<Relationship> relIndex = graphDb.index().forRelationships("rel-index");
    final RelationshipType relType = DynamicRelationshipType.withName("recovery");
    graphDb.beginTx();
    Random random = new Random();
    Thread stopper = new Thread() {

        @Override
        public void run() {
            sleepNice(1000);
            graphDb.shutdown();
        }
    };
    final String[] keys = { "apoc", "zion", "neo" };
    try {
        stopper.start();
        for (int i = 0; i < 50; i++) {
            Node node = graphDb.createNode();
            Node otherNode = graphDb.createNode();
            Relationship rel = node.createRelationshipTo(otherNode, relType);
            for (int ii = 0; ii < 3; ii++) {
                nodeIndex.add(node, keys[random.nextInt(keys.length)], random.nextInt());
                relIndex.add(rel, keys[random.nextInt(keys.length)], random.nextInt());
            }
            sleepNice(10);
        }
    } catch (Exception e) {
    // Ok
    }
    // Wait until the stopper has run, i.e. the graph db is shut down
    while (stopper.getState() != State.TERMINATED) {
        sleepNice(100);
    }
    // Start up and let it recover
    final GraphDatabaseService newGraphDb = new EmbeddedGraphDatabase(getDbPath());
    newGraphDb.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) DynamicRelationshipType(org.neo4j.graphdb.DynamicRelationshipType) Random(java.util.Random) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 59 with EmbeddedGraphDatabase

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

the class TestLuceneBatchInsert method testFindCreatedIndex.

@Test
public void testFindCreatedIndex() {
    String indexName = "persons";
    String path = new File(PATH, "4").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    LuceneBatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex persons = indexProvider.nodeIndex("persons", stringMap("type", "exact"));
    Map<String, Object> properties = map("name", "test");
    long node = inserter.createNode(properties);
    persons.add(node, properties);
    indexProvider.shutdown();
    inserter.shutdown();
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase(path);
    Transaction tx = graphDb.beginTx();
    try {
        IndexManager indexManager = graphDb.index();
        Assert.assertFalse(indexManager.existsForRelationships(indexName));
        Assert.assertTrue(indexManager.existsForNodes(indexName));
        Assert.assertNotNull(indexManager.forNodes(indexName));
        Index<Node> nodes = graphDb.index().forNodes(indexName);
        Assert.assertTrue(nodes.get("name", "test").hasNext());
        tx.success();
        tx.finish();
    } finally {
        graphDb.shutdown();
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) Node(org.neo4j.graphdb.Node) IndexManager(org.neo4j.graphdb.index.IndexManager) BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) Transaction(org.neo4j.graphdb.Transaction) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) File(java.io.File) Test(org.junit.Test)

Example 60 with EmbeddedGraphDatabase

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

the class TestLuceneBatchInsert method testFulltext.

@Test
public void testFulltext() {
    String path = new File(PATH, "2").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    String name = "users";
    BatchInserterIndex index = provider.nodeIndex(name, stringMap("type", "fulltext"));
    long id1 = inserter.createNode(null);
    index.add(id1, map("name", "Mattias Persson", "email", "something@somewhere", "something", "bad"));
    long id2 = inserter.createNode(null);
    index.add(id2, map("name", "Lars PerssoN"));
    index.flush();
    assertContains(index.get("name", "Mattias Persson"), id1);
    assertContains(index.query("name", "mattias"), id1);
    assertContains(index.query("name", "bla"));
    assertContains(index.query("name", "persson"), id1, id2);
    assertContains(index.query("email", "*@*"), id1);
    assertContains(index.get("something", "bad"), id1);
    long id3 = inserter.createNode(null);
    index.add(id3, map("name", new String[] { "What Ever", "Anything" }));
    index.flush();
    assertContains(index.get("name", "What Ever"), id3);
    assertContains(index.get("name", "Anything"), id3);
    provider.shutdown();
    inserter.shutdown();
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    Index<Node> dbIndex = db.index().forNodes(name);
    Node node1 = db.getNodeById(id1);
    Node node2 = db.getNodeById(id2);
    assertContains(dbIndex.query("name", "persson"), node1, node2);
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) Node(org.neo4j.graphdb.Node) File(java.io.File) 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