use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class CountsRotationTest method shouldCreateEmptyCountsTrackerStoreWhenCreatingDatabase.
@Test
public void shouldCreateEmptyCountsTrackerStoreWhenCreatingDatabase() throws IOException {
// GIVEN
GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase();
// WHEN
db.shutdown();
// THEN
assertTrue(fs.fileExists(alphaStoreFile()));
assertFalse(fs.fileExists(betaStoreFile()));
try (Lifespan life = new Lifespan()) {
CountsTracker store = life.add(createCountsTracker(pageCache));
assertEquals(BASE_TX_ID, store.txId());
assertEquals(INITIAL_MINOR_VERSION, store.minorVersion());
assertEquals(0, store.totalEntriesStored());
assertEquals(0, allRecords(store).size());
}
try (Lifespan life = new Lifespan()) {
CountsTracker store = life.add(createCountsTracker(pageCache));
assertEquals(BASE_TX_ID, store.txId());
assertEquals(INITIAL_MINOR_VERSION, store.minorVersion());
assertEquals(0, store.totalEntriesStored());
assertEquals(0, allRecords(store).size());
}
}
use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class CountsRotationTest method shouldRotateCountsStoreWhenRotatingLog.
@Test
public void shouldRotateCountsStoreWhenRotatingLog() throws IOException {
// GIVEN
GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase();
// WHEN doing a transaction (actually two, the label-mini-tx also counts)
try (Transaction tx = db.beginTx()) {
db.createNode(B);
tx.success();
}
// and rotating the log (which implies flushing)
checkPoint(db);
// and creating another node after it
try (Transaction tx = db.beginTx()) {
db.createNode(C);
tx.success();
}
// THEN
assertTrue(fs.fileExists(alphaStoreFile()));
assertTrue(fs.fileExists(betaStoreFile()));
final PageCache pageCache = db.getDependencyResolver().resolveDependency(PageCache.class);
try (Lifespan life = new Lifespan()) {
CountsTracker store = life.add(createCountsTracker(pageCache));
// NOTE since the rotation happens before the second transaction is committed we do not see those changes
// in the stats
// a transaction for creating the label and a transaction for the node
assertEquals(BASE_TX_ID + 1 + 1, store.txId());
assertEquals(INITIAL_MINOR_VERSION, store.minorVersion());
// one for all nodes and one for the created "B" label
assertEquals(1 + 1, store.totalEntriesStored());
assertEquals(1 + 1, allRecords(store).size());
}
// on the other hand the tracker should read the correct value by merging data on disk and data in memory
final CountsTracker tracker = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts();
assertEquals(1 + 1, tracker.nodeCount(-1, newDoubleLongRegister()).readSecond());
final LabelTokenHolder holder = db.getDependencyResolver().resolveDependency(LabelTokenHolder.class);
int labelId = holder.getIdByName(C.name());
assertEquals(1, tracker.nodeCount(labelId, newDoubleLongRegister()).readSecond());
db.shutdown();
}
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();
}
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();
}
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();
}
Aggregations