Search in sources :

Example 46 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class BiggerThanLogTxIT method shouldHandleSlaveCommittingLargeTx.

@Test
public void shouldHandleSlaveCommittingLargeTx() throws Exception {
    // GIVEN
    GraphDatabaseService slave = cluster.getAnySlave();
    long initialNodeCount = nodeCount(slave);
    // WHEN
    cluster.info("Before commit large");
    int nodeCount = commitLargeTx(slave);
    cluster.info("Before sync");
    cluster.sync();
    cluster.info("After sync");
    // THEN all should have that tx
    assertAllMembersHasNodeCount(initialNodeCount + nodeCount);
    // and if then master commits something, they should all get that too
    cluster.info("Before commit small");
    commitSmallTx(cluster.getMaster());
    cluster.info("Before sync small");
    cluster.sync();
    cluster.info("After sync small");
    assertAllMembersHasNodeCount(initialNodeCount + nodeCount + 1);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Test(org.junit.Test)

Example 47 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class UdcExtensionImplTest method shouldLoadForEachCreatedGraphdb.

/**
     * Expect separate counts for each graphdb.
     */
@Test
public void shouldLoadForEachCreatedGraphdb() throws IOException {
    GraphDatabaseService graphdb1 = createDatabase(null);
    GraphDatabaseService graphdb2 = createDatabase(null);
    Set<String> successCountValues = UdcTimerTask.successCounts.keySet();
    assertThat(successCountValues.size(), equalTo(2));
    assertThat("this", is(not("that")));
    cleanup(graphdb1);
    cleanup(graphdb2);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Test(org.junit.Test)

Example 48 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService 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 49 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService 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 50 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class BatchInsertionIT method shouldIndexNodesWithMultipleLabels.

@Test
public void shouldIndexNodesWithMultipleLabels() throws Exception {
    // Given
    File path = new File(dbRule.getStoreDirAbsolutePath());
    BatchInserter inserter = BatchInserters.inserter(path, fileSystemRule.get());
    inserter.createNode(map("name", "Bob"), label("User"), label("Admin"));
    inserter.createDeferredSchemaIndex(label("User")).on("name").create();
    inserter.createDeferredSchemaIndex(label("Admin")).on("name").create();
    // When
    inserter.shutdown();
    // Then
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    try (Transaction tx = db.beginTx()) {
        assertThat(count(db.findNodes(label("User"), "name", "Bob")), equalTo(1L));
        assertThat(count(db.findNodes(label("Admin"), "name", "Bob")), equalTo(1L));
    } finally {
        db.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) File(java.io.File) Test(org.junit.Test)

Aggregations

GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)322 Test (org.junit.Test)225 Transaction (org.neo4j.graphdb.Transaction)182 Node (org.neo4j.graphdb.Node)142 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)77 File (java.io.File)70 Relationship (org.neo4j.graphdb.Relationship)49 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)32 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 Result (org.neo4j.graphdb.Result)14 Label (org.neo4j.graphdb.Label)13 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)12 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 PageCache (org.neo4j.io.pagecache.PageCache)10 DbRepresentation (org.neo4j.test.DbRepresentation)10 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)9 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)8