use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class ConcurrentUpdateIT method populateDbWithConcurrentUpdates.
@Test
void populateDbWithConcurrentUpdates() throws Exception {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseService database = managementService.database(DEFAULT_DATABASE_NAME);
try {
RandomValues randomValues = RandomValues.create();
int counter = 1;
for (int j = 0; j < 100; j++) {
try (Transaction transaction = database.beginTx()) {
for (int i = 0; i < 5; i++) {
Node node = transaction.createNode(Label.label("label" + counter));
node.setProperty("property", randomValues.nextValue().asObject());
}
transaction.commit();
}
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()) {
transaction.schema().indexFor(Label.label("label10")).on("property").create();
transaction.commit();
}
startSignal.countDown();
try (Transaction transaction = database.beginTx()) {
transaction.schema().awaitIndexesOnline(populatorCount, TimeUnit.MINUTES);
transaction.commit();
}
} finally {
endSignal.set(true);
executor.shutdown();
// Basically we don't care to await their completion because they've done their job
}
} finally {
managementService.shutdown();
ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
Config config = Config.defaults(GraphDatabaseSettings.pagecache_memory, "8m");
consistencyCheckService.runFullConsistencyCheck(databaseLayout, config, ProgressMonitorFactory.NONE, new Log4jLogProvider(System.out), false);
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class IndexPopulationIT method setUp.
@BeforeEach
void setUp() {
logProvider = new AssertableLogProvider(true);
managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setInternalLogProvider(logProvider).build();
database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
executorService = Executors.newCachedThreadPool();
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class IndexPopulationIT method shutdownDatabaseDuringIndexPopulations.
@Test
void shutdownDatabaseDuringIndexPopulations() {
AssertableLogProvider assertableLogProvider = new AssertableLogProvider(true);
Path storeDir = directory.directory("shutdownDbTest");
Label testLabel = Label.label("testLabel");
String propertyName = "testProperty";
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setInternalLogProvider(assertableLogProvider).build();
GraphDatabaseService shutDownDb = managementService.database(DEFAULT_DATABASE_NAME);
prePopulateDatabase(shutDownDb, testLabel, propertyName);
try (Transaction transaction = shutDownDb.beginTx()) {
transaction.schema().indexFor(testLabel).on(propertyName).create();
transaction.commit();
}
managementService.shutdown();
assertThat(assertableLogProvider).forClass(IndexPopulationJob.class).forLevel(ERROR).doesNotHaveAnyLogs();
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class MultipleIndexPopulationStressIT method populateDbAndIndexes.
private void populateDbAndIndexes(long nodeCount, long relCount) throws InterruptedException {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).build();
final GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try {
try (var tx = db.beginTx();
var softly = new AutoCloseableSoftAssertions()) {
softly.assertThat(tx.getAllNodes().stream().count()).as("Number of nodes").isEqualTo(nodeCount);
softly.assertThat(tx.getAllRelationships().stream().count()).as("Number of relationships").isEqualTo(relCount);
}
createIndexes(db);
final AtomicBoolean end = new AtomicBoolean();
executor = Executors.newCachedThreadPool();
for (int i = 0; i < 10; i++) {
executor.submit(() -> {
ChangeRandomEntities changeRandomEntities = new ChangeRandomEntities(db, RandomValues.create(), nodeCount, relCount);
while (!end.get()) {
changeRandomEntities.node();
changeRandomEntities.relationship();
}
});
}
while (!indexesAreOnline(db)) {
Thread.sleep(100);
}
end.set(true);
executor.shutdown();
executor.awaitTermination(10, SECONDS);
executor = null;
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class MultipleIndexPopulationStressIT method dropIndexes.
private void dropIndexes() {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setConfig(GraphDatabaseSettings.pagecache_memory, "8m").build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.schema().getIndexes().forEach(IndexDefinition::drop);
tx.commit();
} finally {
managementService.shutdown();
}
expectingNLI = false;
expectingRTI = false;
}
Aggregations