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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations