Search in sources :

Example 81 with Node

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

the class TestProperties method intRange.

@Test
public void intRange() throws Exception {
    Node node = getGraphDb().createNode();
    int stride = Integer.MAX_VALUE / VALUE_RANGE_SPLIT;
    for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; ) {
        setPropertyAndAssertIt(node, i);
        i = i > 0 && Integer.MAX_VALUE - i < stride ? Integer.MAX_VALUE : i + stride;
    }
}
Also used : Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 82 with Node

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

the class TestProperties method addAndRemovePropertiesWithinOneTransaction2.

@Test
public void addAndRemovePropertiesWithinOneTransaction2() throws Exception {
    Node node = getGraphDb().createNode();
    node.setProperty("foo", "bar");
    newTransaction();
    node.setProperty("foo2", "bar");
    node.removeProperty("foo");
    newTransaction();
    try {
        node.getProperty("foo");
        fail("property should not exist");
    } catch (NotFoundException e) {
    // good
    }
}
Also used : Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Example 83 with Node

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

the class ManualAcquireLockTest method releaseReleaseManually.

@Test
public void releaseReleaseManually() throws Exception {
    String key = "name";
    Node node = getGraphDb().createNode();
    tx.success();
    Transaction current = tx.begin();
    Lock nodeLock = current.acquireWriteLock(node);
    worker.beginTx();
    try {
        worker.setProperty(node, key, "ksjd");
        fail("Shouldn't be able to grab it");
    } catch (Exception ignored) {
    }
    nodeLock.release();
    worker.setProperty(node, key, "yo");
    try {
        worker.finishTx();
    } catch (ExecutionException e) {
    // Ok, interrupting the thread while it's waiting for a lock will lead to tx failure.
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Lock(org.neo4j.graphdb.Lock) Test(org.junit.Test)

Example 84 with Node

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

the class ManualAcquireLockTest method canOnlyReleaseOnce.

@Test
public void canOnlyReleaseOnce() throws Exception {
    Node node = getGraphDb().createNode();
    tx.success();
    Transaction current = tx.begin();
    Lock nodeLock = current.acquireWriteLock(node);
    nodeLock.release();
    try {
        nodeLock.release();
        fail("Shouldn't be able to release more than once");
    } catch (IllegalStateException e) {
    // Good
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Lock(org.neo4j.graphdb.Lock) Test(org.junit.Test)

Example 85 with Node

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

the class PartialTransactionFailureIT method concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction.

@Test
public void concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction() throws Exception {
    final ClassGuardedAdversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, false), Command.RelationshipCommand.class);
    adversary.disable();
    File storeDir = dir.graphDbDir();
    final Map<String, String> params = stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m");
    final EmbeddedGraphDatabase db = new TestEmbeddedGraphDatabase(storeDir, params) {

        @Override
        protected void create(File storeDir, Map<String, String> params, GraphDatabaseFacadeFactory.Dependencies dependencies) {
            new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, CommunityEditionModule::new) {

                @Override
                protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
                    return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {

                        @Override
                        protected FileSystemAbstraction createFileSystemAbstraction() {
                            return new AdversarialFileSystemAbstraction(adversary);
                        }
                    };
                }
            }.initFacade(storeDir, params, dependencies, this);
        }
    };
    Node a, b, c, d;
    try (Transaction tx = db.beginTx()) {
        a = db.createNode();
        b = db.createNode();
        c = db.createNode();
        d = db.createNode();
        tx.success();
    }
    adversary.enable();
    CountDownLatch latch = new CountDownLatch(1);
    Thread t1 = new Thread(createRelationship(db, a, b, latch), "T1");
    Thread t2 = new Thread(createRelationship(db, c, d, latch), "T2");
    t1.start();
    t2.start();
    // Wait for both threads to get going
    t1.join(10);
    t2.join(10);
    latch.countDown();
    // Wait for the transactions to finish
    t1.join(25000);
    t2.join(25000);
    db.shutdown();
    // We should observe the store in a consistent state
    EmbeddedGraphDatabase db2 = new TestEmbeddedGraphDatabase(storeDir, params);
    try (Transaction tx = db2.beginTx()) {
        Node x = db2.getNodeById(a.getId());
        Node y = db2.getNodeById(b.getId());
        Node z = db2.getNodeById(c.getId());
        Node w = db2.getNodeById(d.getId());
        Iterator<Relationship> itrRelX = x.getRelationships().iterator();
        Iterator<Relationship> itrRelY = y.getRelationships().iterator();
        Iterator<Relationship> itrRelZ = z.getRelationships().iterator();
        Iterator<Relationship> itrRelW = w.getRelationships().iterator();
        if (itrRelX.hasNext() != itrRelY.hasNext()) {
            fail("Node x and y have inconsistent relationship counts");
        } else if (itrRelX.hasNext()) {
            Relationship rel = itrRelX.next();
            assertEquals(rel, itrRelY.next());
            assertFalse(itrRelX.hasNext());
            assertFalse(itrRelY.hasNext());
        }
        if (itrRelZ.hasNext() != itrRelW.hasNext()) {
            fail("Node z and w have inconsistent relationship counts");
        } else if (itrRelZ.hasNext()) {
            Relationship rel = itrRelZ.next();
            assertEquals(rel, itrRelW.next());
            assertFalse(itrRelZ.hasNext());
            assertFalse(itrRelW.hasNext());
        }
    } finally {
        db2.shutdown();
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.internal.EmbeddedGraphDatabase) CountingAdversary(org.neo4j.adversaries.CountingAdversary) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ClassGuardedAdversary(org.neo4j.adversaries.ClassGuardedAdversary) Config(org.neo4j.kernel.configuration.Config) Node(org.neo4j.graphdb.Node) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) CountDownLatch(java.util.concurrent.CountDownLatch) Transaction(org.neo4j.graphdb.Transaction) Command(org.neo4j.kernel.impl.transaction.command.Command) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) Relationship(org.neo4j.graphdb.Relationship) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) File(java.io.File) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) Test(org.junit.Test)

Aggregations

Node (org.neo4j.graphdb.Node)1281 Test (org.junit.Test)781 Transaction (org.neo4j.graphdb.Transaction)540 Relationship (org.neo4j.graphdb.Relationship)375 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)146 NotFoundException (org.neo4j.graphdb.NotFoundException)78 File (java.io.File)65 LinkedList (java.util.LinkedList)60 RelationshipType (org.neo4j.graphdb.RelationshipType)58 HashMap (java.util.HashMap)57 Label (org.neo4j.graphdb.Label)57 Path (org.neo4j.graphdb.Path)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)46 HashSet (java.util.HashSet)45 Map (java.util.Map)45 WeightedPath (org.neo4j.graphalgo.WeightedPath)37 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)35 ArrayList (java.util.ArrayList)30 List (java.util.List)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26