Search in sources :

Example 71 with EmbeddedGraphDatabase

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

the class AbstractTestBase method beforeSuite.

@BeforeClass
public static final void beforeSuite() {
    deleteFileOrDirectory(new File(TARGET_NEODB));
    graphdb = new EmbeddedGraphDatabase(TARGET_NEODB);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 72 with EmbeddedGraphDatabase

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

the class Neo4jAlgoTestCase method setUpGraphDb.

@BeforeClass
public static void setUpGraphDb() throws Exception {
    String storeDir = "target/var/algotest";
    deleteFileOrDirectory(new File(storeDir));
    graphDb = new EmbeddedGraphDatabase(storeDir);
    graph = new SimpleGraphBuilder(graphDb, MyRelTypes.R1);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 73 with EmbeddedGraphDatabase

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

the class PathFindingExamplesTest method startDb.

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

Example 74 with EmbeddedGraphDatabase

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

the class TestKernelEvents method testRegisterUnregisterHandlers.

@Test
public void testRegisterUnregisterHandlers() {
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase(PATH);
    KernelEventHandler handler1 = new DummyKernelEventHandler(RESOURCE1) {

        public ExecutionOrder orderComparedTo(KernelEventHandler other) {
            return ExecutionOrder.DOESNT_MATTER;
        }
    };
    KernelEventHandler handler2 = new DummyKernelEventHandler(RESOURCE2) {

        public ExecutionOrder orderComparedTo(KernelEventHandler other) {
            return ExecutionOrder.DOESNT_MATTER;
        }
    };
    try {
        graphDb.unregisterKernelEventHandler(handler1);
        fail("Shouldn't be able to do unregister on a " + "unregistered handler");
    } catch (IllegalStateException e) {
    /* Good */
    }
    assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
    assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
    assertTrue(handler1 == graphDb.unregisterKernelEventHandler(handler1));
    try {
        graphDb.unregisterKernelEventHandler(handler1);
        fail("Shouldn't be able to do unregister on a " + "unregistered handler");
    } catch (IllegalStateException e) {
    /* Good */
    }
    assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
    assertTrue(handler2 == graphDb.registerKernelEventHandler(handler2));
    assertTrue(handler1 == graphDb.unregisterKernelEventHandler(handler1));
    assertTrue(handler2 == graphDb.unregisterKernelEventHandler(handler2));
    graphDb.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelEventHandler(org.neo4j.graphdb.event.KernelEventHandler) Test(org.junit.Test)

Example 75 with EmbeddedGraphDatabase

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

the class TestKernelPanic method panicTest.

@Test
public void panicTest() throws Exception {
    String path = "target/var/testdb";
    AbstractNeo4jTestCase.deleteFileOrDirectory(new File(path));
    EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(path);
    XaDataSourceManager xaDs = graphDb.getConfig().getTxModule().getXaDataSourceManager();
    IllBehavingXaDataSource noob = new IllBehavingXaDataSource();
    xaDs.registerDataSource("noob", noob, UTF8.encode("554342"));
    Panic panic = new Panic();
    graphDb.registerKernelEventHandler(panic);
    org.neo4j.graphdb.Transaction gdbTx = graphDb.beginTx();
    TransactionManager txMgr = graphDb.getConfig().getTxModule().getTxManager();
    Transaction tx = txMgr.getTransaction();
    graphDb.createNode();
    tx.enlistResource(noob.getXaConnection().getXaResource());
    try {
        gdbTx.success();
        gdbTx.finish();
        fail("Should fail");
    } catch (Throwable t) {
        // ok
        for (int i = 0; i < 10 && panic.panic == false; i++) {
            Thread.sleep(1000);
        }
    } finally {
        graphDb.unregisterKernelEventHandler(panic);
    }
    assertTrue(panic.panic);
    graphDb.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) XaDataSourceManager(org.neo4j.kernel.impl.transaction.XaDataSourceManager) Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager) 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