use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class StoreMigrationTest method storeMigrationToolShouldBeAbleToMigrateOldStore.
@Test
public void storeMigrationToolShouldBeAbleToMigrateOldStore() throws IOException {
StoreMigration.main(new String[] { testDir.graphDbDir().getAbsolutePath() });
// after migration we can open store and do something
GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDir.graphDbDir());
try (Transaction transaction = database.beginTx()) {
Node node = database.createNode();
node.setProperty("key", "value");
transaction.success();
} finally {
database.shutdown();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class LucenePartitionedIndexStressTesting method dropAllIndexes.
private void dropAllIndexes() {
try (Transaction transaction = db.beginTx()) {
Schema schema = db.schema();
schema.getConstraints().forEach(ConstraintDefinition::drop);
schema.getIndexes().forEach(IndexDefinition::drop);
transaction.success();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class LucenePartitionedIndexStressTesting method awaitIndexesOnline.
private void awaitIndexesOnline(GraphDatabaseService db) {
try (Transaction ignored = db.beginTx()) {
Schema schema = db.schema();
schema.awaitIndexesOnline(WAIT_DURATION_MINUTES, TimeUnit.MINUTES);
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class ConstraintRecoveryIT method shouldNotHaveAnIndexIfUniqueConstraintCreationOnRecoveryFails.
@Test
public void shouldNotHaveAnIndexIfUniqueConstraintCreationOnRecoveryFails() throws IOException {
// given
final EphemeralFileSystemAbstraction fs = fileSystemRule.get();
fs.mkdir(new File("/tmp"));
File pathToDb = new File("/tmp/bar2");
TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();
dbFactory.setFileSystem(fs);
final EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
final AtomicBoolean monitorCalled = new AtomicBoolean(false);
Monitors monitors = new Monitors();
monitors.addMonitorListener(new IndexingService.MonitorAdapter() {
@Override
public void indexPopulationScanComplete() {
monitorCalled.set(true);
db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getSchemaStore().flush();
storeInNeedOfRecovery[0] = fs.snapshot();
}
});
dbFactory.setMonitors(monitors);
db = (GraphDatabaseAPI) dbFactory.newImpermanentDatabase(pathToDb);
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < 2; i++) {
Node node1 = db.createNode(LABEL);
node1.setProperty("prop", true);
}
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().constraintFor(LABEL).assertPropertyIsUnique("prop").create();
fail("Should have failed with ConstraintViolationException");
tx.success();
} catch (ConstraintViolationException ignored) {
}
db.shutdown();
assertTrue(monitorCalled.get());
// when
dbFactory = new TestGraphDatabaseFactory();
dbFactory.setFileSystem(storeInNeedOfRecovery[0]);
db = (GraphDatabaseAPI) dbFactory.newImpermanentDatabase(pathToDb);
// then
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexesOnline(5000, TimeUnit.MILLISECONDS);
}
try (Transaction tx = db.beginTx()) {
assertEquals(2, Iterables.count(db.getAllNodes()));
}
try (Transaction tx = db.beginTx()) {
assertEquals(0, Iterables.count(Iterables.asList(db.schema().getConstraints())));
}
try (Transaction tx = db.beginTx()) {
assertEquals(0, Iterables.count(Iterables.asList(db.schema().getIndexes())));
}
db.shutdown();
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class IndexingServiceIntegrationTest method testSchemaIndexMatchIndexingService.
@Test
public void testSchemaIndexMatchIndexingService() throws IndexNotFoundKernelException {
try (Transaction transaction = database.beginTx()) {
database.schema().constraintFor(Label.label(CLOTHES_LABEL)).assertPropertyIsUnique(PROPERTY_NAME).create();
database.schema().indexFor(Label.label(WEATHER_LABEL)).on(PROPERTY_NAME).create();
transaction.success();
}
try (Transaction transaction = database.beginTx()) {
database.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
}
IndexingService indexingService = getIndexingService(database);
LabelTokenHolder labelTokenHolder = getLabelTokenHolder(database);
PropertyKeyTokenHolder propertyKeyTokenHolder = getPropertyKeyTokenHolder(database);
int clothedLabelId = labelTokenHolder.getIdByName(CLOTHES_LABEL);
int weatherLabelId = labelTokenHolder.getIdByName(WEATHER_LABEL);
int propertyId = propertyKeyTokenHolder.getIdByName(PROPERTY_NAME);
IndexProxy clothesIndex = indexingService.getIndexProxy(SchemaDescriptorFactory.forLabel(clothedLabelId, propertyId));
IndexProxy weatherIndex = indexingService.getIndexProxy(SchemaDescriptorFactory.forLabel(weatherLabelId, propertyId));
assertEquals(InternalIndexState.ONLINE, clothesIndex.getState());
assertEquals(InternalIndexState.ONLINE, weatherIndex.getState());
}
Aggregations