Search in sources :

Example 6 with Transaction

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

the class CountsRotationTest method rotationShouldNotCauseUnmappedFileProblem.

@Test
public void rotationShouldNotCauseUnmappedFileProblem() throws IOException {
    // GIVEN
    GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase();
    DependencyResolver resolver = db.getDependencyResolver();
    RecordStorageEngine storageEngine = resolver.resolveDependency(RecordStorageEngine.class);
    CountsTracker countStore = storageEngine.testAccessNeoStores().getCounts();
    AtomicBoolean workerContinueFlag = new AtomicBoolean(true);
    AtomicLong lookupsCounter = new AtomicLong();
    int rotations = 100;
    for (int i = 0; i < 5; i++) {
        threadingRule.execute(countStoreLookup(workerContinueFlag, lookupsCounter), countStore);
    }
    long startTxId = countStore.txId();
    for (int i = 1; (i < rotations) || (lookupsCounter.get() == 0); i++) {
        try (Transaction tx = db.beginTx()) {
            db.createNode(B);
            tx.success();
        }
        checkPoint(db);
    }
    workerContinueFlag.set(false);
    assertEquals("Should perform at least 100 rotations.", rotations, Math.min(rotations, countStore.txId() - startTxId));
    assertTrue("Should perform more then 0 lookups without exceptions.", lookupsCounter.get() > 0);
    db.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

Example 7 with Transaction

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

the class TestGraphProperties method basicProperties.

@Test
public void basicProperties() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    PropertyContainer graphProperties = properties(db);
    assertThat(graphProperties, inTx(db, not(hasProperty("test"))));
    Transaction tx = db.beginTx();
    graphProperties.setProperty("test", "yo");
    assertEquals("yo", graphProperties.getProperty("test"));
    tx.success();
    tx.close();
    assertThat(graphProperties, inTx(db, hasProperty("test").withValue("yo")));
    tx = db.beginTx();
    assertNull(graphProperties.removeProperty("something non existent"));
    assertEquals("yo", graphProperties.removeProperty("test"));
    assertNull(graphProperties.getProperty("test", null));
    graphProperties.setProperty("other", 10);
    assertEquals(10, graphProperties.getProperty("other"));
    graphProperties.setProperty("new", "third");
    tx.success();
    tx.close();
    assertThat(graphProperties, inTx(db, not(hasProperty("test"))));
    assertThat(graphProperties, inTx(db, hasProperty("other").withValue(10)));
    assertThat(getPropertyKeys(db, graphProperties), containsOnly("other", "new"));
    tx = db.beginTx();
    graphProperties.setProperty("rollback", true);
    assertEquals(true, graphProperties.getProperty("rollback"));
    tx.close();
    assertThat(graphProperties, inTx(db, not(hasProperty("rollback"))));
    db.shutdown();
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 8 with Transaction

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

the class TestGraphProperties method shouldBeAbleToCreateLongGraphPropertyChainsAndReadTheCorrectNextPointerFromTheStore.

@Test
public void shouldBeAbleToCreateLongGraphPropertyChainsAndReadTheCorrectNextPointerFromTheStore() {
    GraphDatabaseService database = factory.newImpermanentDatabase();
    PropertyContainer graphProperties = properties((GraphDatabaseAPI) database);
    try (Transaction tx = database.beginTx()) {
        graphProperties.setProperty("a", new String[] { "A", "B", "C", "D", "E" });
        graphProperties.setProperty("b", true);
        graphProperties.setProperty("c", "C");
        tx.success();
    }
    try (Transaction tx = database.beginTx()) {
        graphProperties.setProperty("d", new String[] { "A", "F" });
        graphProperties.setProperty("e", true);
        graphProperties.setProperty("f", "F");
        tx.success();
    }
    try (Transaction tx = database.beginTx()) {
        graphProperties.setProperty("g", new String[] { "F" });
        graphProperties.setProperty("h", false);
        graphProperties.setProperty("i", "I");
        tx.success();
    }
    try (Transaction tx = database.beginTx()) {
        assertArrayEquals(new String[] { "A", "B", "C", "D", "E" }, (String[]) graphProperties.getProperty("a"));
        assertTrue((boolean) graphProperties.getProperty("b"));
        assertEquals("C", graphProperties.getProperty("c"));
        assertArrayEquals(new String[] { "A", "F" }, (String[]) graphProperties.getProperty("d"));
        assertTrue((boolean) graphProperties.getProperty("e"));
        assertEquals("F", graphProperties.getProperty("f"));
        assertArrayEquals(new String[] { "F" }, (String[]) graphProperties.getProperty("g"));
        assertFalse((boolean) graphProperties.getProperty("h"));
        assertEquals("I", graphProperties.getProperty("i"));
        tx.success();
    }
    database.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) PropertyContainer(org.neo4j.graphdb.PropertyContainer) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 9 with Transaction

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

the class TestGraphProperties method setManyGraphProperties.

@Test
public void setManyGraphProperties() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    Transaction tx = db.beginTx();
    Object[] values = new Object[] { 10, "A string value", new float[] { 1234.567F, 7654.321F }, "A rather longer string which wouldn't fit inlined #!)(&ยค" };
    int count = 200;
    for (int i = 0; i < count; i++) {
        properties(db).setProperty("key" + i, values[i % values.length]);
    }
    tx.success();
    tx.close();
    for (int i = 0; i < count; i++) {
        assertThat(properties(db), inTx(db, hasProperty("key" + i).withValue(values[i % values.length])));
    }
    for (int i = 0; i < count; i++) {
        assertThat(properties(db), inTx(db, hasProperty("key" + i).withValue(values[i % values.length])));
    }
    db.shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 10 with Transaction

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

the class TestGraphProperties method firstRecordOtherThanZeroIfNotFirst.

@Test
public void firstRecordOtherThanZeroIfNotFirst() throws Exception {
    File storeDir = new File("/store/dir").getAbsoluteFile();
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(storeDir);
    Transaction tx = db.beginTx();
    Node node = db.createNode();
    node.setProperty("name", "Yo");
    tx.success();
    tx.close();
    db.shutdown();
    db = (GraphDatabaseAPI) factory.newImpermanentDatabase(storeDir);
    tx = db.beginTx();
    properties(db).setProperty("test", "something");
    tx.success();
    tx.close();
    db.shutdown();
    Config config = Config.embeddedDefaults(Collections.emptyMap());
    StoreFactory storeFactory = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fs.get()), pageCacheRule.getPageCache(fs.get()), fs.get(), NullLogProvider.getInstance());
    NeoStores neoStores = storeFactory.openAllNeoStores();
    long prop = neoStores.getMetaDataStore().getGraphNextProp();
    assertTrue(prop != 0);
    neoStores.close();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Config(org.neo4j.kernel.configuration.Config) Node(org.neo4j.graphdb.Node) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) File(java.io.File) Test(org.junit.Test)

Aggregations

Transaction (org.neo4j.graphdb.Transaction)2409 Node (org.neo4j.graphdb.Node)1086 Test (org.junit.jupiter.api.Test)751 Test (org.junit.Test)607 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)352 Relationship (org.neo4j.graphdb.Relationship)307 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)302 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)241 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)177 Label (org.neo4j.graphdb.Label)154 Result (org.neo4j.graphdb.Result)142 HashMap (java.util.HashMap)105 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)104 MethodSource (org.junit.jupiter.params.provider.MethodSource)103 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)86 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)77 File (java.io.File)74 ArrayList (java.util.ArrayList)73 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)67 Path (java.nio.file.Path)64