use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class DynamicIndexStoreViewIT method populateDbWithConcurrentUpdates.
@Test
public void populateDbWithConcurrentUpdates() throws Exception {
GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
try {
int counter = 1;
for (int j = 0; j < 100; j++) {
try (Transaction transaction = database.beginTx()) {
for (int i = 0; i < 5; i++) {
Node node = database.createNode(Label.label("label" + counter));
node.setProperty("property", ThreadLocalRandom.current().nextInt());
}
transaction.success();
}
counter++;
}
int populatorCount = 5;
ExecutorService executor = Executors.newFixedThreadPool(populatorCount);
CountDownLatch startSignal = new CountDownLatch(1);
AtomicBoolean endSignal = new AtomicBoolean();
for (int i = 0; i < populatorCount; i++) {
executor.submit(new Populator(database, counter, startSignal, endSignal));
}
try {
try (Transaction transaction = database.beginTx()) {
database.schema().indexFor(Label.label("label10")).on("property").create();
transaction.success();
}
startSignal.countDown();
try (Transaction transaction = database.beginTx()) {
database.schema().awaitIndexesOnline(populatorCount, TimeUnit.MINUTES);
transaction.success();
}
} finally {
endSignal.set(true);
executor.shutdown();
// Basically we don't care to await their completion because they've done their job
}
} finally {
database.shutdown();
ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
Config config = Config.defaults();
config = config.with(stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m"));
consistencyCheckService.runFullConsistencyCheck(testDirectory.graphDbDir(), config, ProgressMonitorFactory.NONE, FormattedLogProvider.toOutputStream(System.out), false);
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class TestRecoveryMultipleDataSources method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
exit(1);
}
File storeDir = new File(args[0]);
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode().createRelationshipTo(db.createNode(), MyRelTypes.TEST);
tx.success();
}
((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
try (Transaction tx = db.beginTx()) {
db.index().forNodes("index").add(db.createNode(), storeDir.getAbsolutePath(), db.createNode());
tx.success();
}
exit(0);
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.
@Test
public void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
// given
// create a store
File storeDir = testDirectory.graphDbDir();
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
db.shutdown();
// mess up the version in the metadatastore
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"));
}
// when
try {
new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
fail("It should have failed.");
} catch (RuntimeException ex) {
// then
assertTrue(ex.getCause() instanceof LifecycleException);
assertTrue(ex.getCause().getCause() instanceof UpgradeNotAllowedByConfigurationException);
assertEquals("Failed to start Neo4j with an older data store version. To enable automatic upgrade, " + "please set configuration parameter \"dbms.allow_format_migration=true\"", ex.getCause().getCause().getMessage());
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class MultipleIndexPopulationStressIT method populateDbAndIndexes.
private void populateDbAndIndexes(int nodeCount, boolean multiThreaded) throws InterruptedException {
final GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory.graphDbDir()).setConfig(GraphDatabaseSettings.multi_threaded_schema_index_population_enabled, multiThreaded + "").newGraphDatabase();
try {
createIndexes(db);
final AtomicBoolean end = new AtomicBoolean();
ExecutorService executor = cleanup.add(Executors.newCachedThreadPool());
for (int i = 0; i < 10; i++) {
executor.submit(() -> {
Randoms random = new Randoms();
while (!end.get()) {
changeRandomNode(db, nodeCount, random);
}
});
}
while (!indexesAreOnline(db)) {
Thread.sleep(100);
}
end.set(true);
executor.shutdown();
executor.awaitTermination(10, SECONDS);
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class FreePortIT method initialize.
public GraphDatabaseService initialize() throws IOException {
GraphDatabaseService db;
db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(temporaryFolder.newFolder()).setConfig(ShellSettings.remote_shell_enabled, "true").setConfig(ShellSettings.remote_shell_host, HOST).setConfig(ShellSettings.remote_shell_port, Integer.toString(PORT)).newGraphDatabase();
return db;
}
Aggregations