Search in sources :

Example 21 with EmbeddedGraphDatabase

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

the class TestUpgradeStore method makeSureStoreCantBeUpgradedIfNotExplicitlyToldTo2.

@Test
public void makeSureStoreCantBeUpgradedIfNotExplicitlyToldTo2() throws Exception {
    String path = path(12);
    new EmbeddedGraphDatabase(path).shutdown();
    setOlderNeoStoreVersion(path);
    try {
        new EmbeddedGraphDatabase(path, stringMap(ALLOW_STORE_UPGRADE, "false"));
        fail("Shouldn't be able to upgrade if not told to");
    } catch (TransactionFailureException e) {
        if (!(e.getCause() instanceof IllegalStoreVersionException)) {
            throw e;
        }
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Test(org.junit.Test)

Example 22 with EmbeddedGraphDatabase

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

the class TestKernelEvents method testShutdownEvents.

@Test
public void testShutdownEvents() {
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase("target/var/neodb");
    DummyKernelEventHandler handler1 = new DummyKernelEventHandler(RESOURCE1) {

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

        public ExecutionOrder orderComparedTo(KernelEventHandler other) {
            if (((DummyKernelEventHandler) other).resource == RESOURCE1) {
                return ExecutionOrder.BEFORE;
            }
            return ExecutionOrder.DOESNT_MATTER;
        }
    };
    graphDb.registerKernelEventHandler(handler1);
    graphDb.registerKernelEventHandler(handler2);
    graphDb.shutdown();
    assertEquals(Integer.valueOf(0), handler2.beforeShutdown);
    assertEquals(Integer.valueOf(1), handler1.beforeShutdown);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelEventHandler(org.neo4j.graphdb.event.KernelEventHandler) Test(org.junit.Test)

Example 23 with EmbeddedGraphDatabase

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

the class TestReadOnlyNeo4j method testReadOnlyOperationsAndNoTransaction.

@Test
public void testReadOnlyOperationsAndNoTransaction() {
    GraphDatabaseService db = new EmbeddedGraphDatabase(PATH);
    Transaction tx = db.beginTx();
    Node node1 = db.createNode();
    Node node2 = db.createNode();
    Relationship rel = node1.createRelationshipTo(node2, withName("TEST"));
    node1.setProperty("key1", "value1");
    rel.setProperty("key1", "value1");
    tx.success();
    tx.finish();
    // make sure write operations still throw exception
    try {
        db.createNode();
        fail("Write operation and no transaction should throw exception");
    } catch (NotInTransactionException e) {
    // good
    }
    try {
        node1.createRelationshipTo(node2, withName("TEST2"));
        fail("Write operation and no transaction should throw exception");
    } catch (NotInTransactionException e) {
    // good
    }
    try {
        node1.setProperty("key1", "value2");
        fail("Write operation and no transaction should throw exception");
    } catch (NotInTransactionException e) {
    // good
    }
    try {
        rel.removeProperty("key1");
        fail("Write operation and no transaction should throw exception");
    } catch (NotInTransactionException e) {
    // good
    }
    // clear caches and try reads
    ((AbstractGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().clearCache();
    assertEquals(node1, db.getNodeById(node1.getId()));
    assertEquals(node2, db.getNodeById(node2.getId()));
    assertEquals(rel, db.getRelationshipById(rel.getId()));
    ((AbstractGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().clearCache();
    assertEquals("value1", node1.getProperty("key1"));
    Relationship loadedRel = node1.getSingleRelationship(DynamicRelationshipType.withName("TEST"), Direction.OUTGOING);
    assertEquals(rel, loadedRel);
    assertEquals("value1", loadedRel.getProperty("key1"));
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 24 with EmbeddedGraphDatabase

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

the class UdcExtensionImplTest method shouldNotCrashNormalGraphdbCreation.

/**
     * Sanity check to make sure a database can be created
     * and destroyed.
     *
     * @throws java.io.IOException
     */
@Test
public void shouldNotCrashNormalGraphdbCreation() throws IOException {
    EmbeddedGraphDatabase graphdb = createTempDatabase(null);
    destroy(graphdb);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) Test(org.junit.Test)

Example 25 with EmbeddedGraphDatabase

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

the class UdcExtensionImplTest method shouldRecordFailuresWhenThereIsNoServer.

@Test
public void shouldRecordFailuresWhenThereIsNoServer() throws Exception {
    Map<String, String> config = new HashMap<String, String>();
    // first delay must be long enough to allow class initialization to complete
    config.put(UdcExtensionImpl.FIRST_DELAY_CONFIG_KEY, "100");
    config.put(UdcExtensionImpl.UDC_HOST_ADDRESS_KEY, "127.0.0.1:1");
    EmbeddedGraphDatabase graphdb = new EmbeddedGraphDatabase("should-record-failures", config);
    assertGotFailureWithRetry(IS_GREATER_THAN_ZERO);
    destroy(graphdb);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) HashMap(java.util.HashMap) 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