Search in sources :

Example 21 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI 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 22 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI 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 23 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI 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 24 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class TestGraphProperties method graphPropertiesAreLockedPerTx.

@Test
public void graphPropertiesAreLockedPerTx() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    Worker worker1 = new Worker("W1", new State(db));
    Worker worker2 = new Worker("W2", new State(db));
    PropertyContainer properties = properties(db);
    worker1.beginTx();
    worker2.beginTx();
    String key1 = "name";
    String value1 = "Value 1";
    String key2 = "some other property";
    String value2 = "Value 2";
    String key3 = "say";
    String value3 = "hello";
    worker1.setProperty(key1, value1).get();
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertFalse(worker2.hasProperty(key1));
    Future<Void> blockedSetProperty = worker2.setProperty(key2, value2);
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    worker1.setProperty(key3, value3).get();
    assertFalse(blockedSetProperty.isDone());
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    assertThat(properties, inTx(db, not(hasProperty(key3))));
    worker1.commitTx();
    assertThat(properties, inTx(db, hasProperty(key1)));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    assertThat(properties, inTx(db, hasProperty(key3)));
    blockedSetProperty.get();
    assertTrue(blockedSetProperty.isDone());
    worker2.commitTx();
    assertThat(properties, inTx(db, hasProperty(key1).withValue(value1)));
    assertThat(properties, inTx(db, hasProperty(key2).withValue(value2)));
    assertThat(properties, inTx(db, hasProperty(key3).withValue(value3)));
    worker1.close();
    worker2.close();
    db.shutdown();
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.Test)

Example 25 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI 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

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)133 Test (org.junit.Test)96 Transaction (org.neo4j.graphdb.Transaction)50 File (java.io.File)25 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)25 Node (org.neo4j.graphdb.Node)20 DependencyResolver (org.neo4j.graphdb.DependencyResolver)19 Config (org.neo4j.kernel.configuration.Config)15 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)12 IOException (java.io.IOException)8 PageCache (org.neo4j.io.pagecache.PageCache)8 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)8 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)8 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)6 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)6 Before (org.junit.Before)5 Label (org.neo4j.graphdb.Label)5 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)5 GuardTimeoutException (org.neo4j.kernel.guard.GuardTimeoutException)5