use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class CheckPointerIntegrationTest method shouldCheckPointBasedOnTime.
@Test
void shouldCheckPointBasedOnTime() throws Throwable {
// given
long millis = 200;
DatabaseManagementService managementService = builder.setConfig(check_point_interval_time, ofMillis(millis)).setConfig(check_point_interval_tx, 10000).setConfig(logical_log_rotation_threshold, gibiBytes(1)).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
// when
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
// The scheduled job checking whether or not checkpoints are needed runs more frequently
// now that we've set the time interval so low, so we can simply wait for it here
long endTime = currentTimeMillis() + SECONDS.toMillis(30);
while (checkPointInTxLog(db).isEmpty()) {
Thread.sleep(millis);
assertTrue(currentTimeMillis() < endTime, "Took too long to produce a checkpoint");
}
managementService.shutdown();
managementService = builder.build();
try {
// then - 2 check points have been written in the log
List<CheckpointInfo> checkPoints = checkPointsInTxLog(managementService.database(DEFAULT_DATABASE_NAME));
assertTrue(checkPoints.size() >= 2, "Expected at least two (at least one for time interval and one for shutdown), was " + checkPoints.toString());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class CheckPointerIntegrationTest method shouldNotCheckPointWhenThereAreNoCommits.
@Test
void shouldNotCheckPointWhenThereAreNoCommits() throws Throwable {
// given
DatabaseManagementService managementService = builder.setConfig(check_point_interval_time, Duration.ofSeconds(1)).setConfig(check_point_interval_tx, 10000).setConfig(logical_log_rotation_threshold, gibiBytes(1)).build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
GraphDatabaseAPI databaseAPI = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
getCheckPointer(databaseAPI).forceCheckPoint(new SimpleTriggerInfo("given"));
var checkPointsBefore = checkPointInTxLog(db).size();
// when
// nothing happens
triggerCheckPointAttempt(db);
assertThat(checkPointInTxLog(db)).hasSize(checkPointsBefore);
managementService.shutdown();
managementService = builder.build();
try {
// then - 1 check point has been written in the log
var checkPoints = checkPointsInTxLog(managementService.database(DEFAULT_DATABASE_NAME));
assertEquals(checkPointsBefore + 1, checkPoints.size());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class TransactionMonitorTest method shouldCountTerminatedTransactions.
@ParameterizedTest(name = "{0}")
@MethodSource("parameters")
void shouldCountTerminatedTransactions(String name, ThrowingConsumer<Transaction, Exception> txConsumer, boolean isWriteTx) throws Exception {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
TransactionCounters counts = db.getDependencyResolver().resolveDependency(TransactionCounters.class);
TransactionCountersChecker checker = new TransactionCountersChecker(counts);
try (Transaction tx = db.beginTx()) {
txConsumer.accept(tx);
tx.terminate();
}
checker.verifyTerminated(isWriteTx, counts);
} finally {
managementService.shutdown();
}
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class ReuseStorageSpaceIT method shouldPrioritizeFreelistWhenConcurrentlyAllocating.
@Test
void shouldPrioritizeFreelistWhenConcurrentlyAllocating() throws Exception {
DatabaseManagementService dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).setConfig(GraphDatabaseInternalSettings.force_small_id_cache, true).build();
try {
// given
GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
int numNodes = 40_000;
MutableLongSet nodeIds = createNodes(db, numNodes);
try (Transaction tx = db.beginTx()) {
nodeIds.forEach(nodeId -> tx.getNodeById(nodeId).delete());
tx.commit();
}
db.getDependencyResolver().resolveDependency(IdController.class).maintenance();
// First create 40,000 nodes, then delete them, ensure ID maintenance has run and allocate concurrently
int numThreads = 4;
Collection<Callable<MutableLongSet>> allocators = new ArrayList<>();
for (int i = 0; i < numThreads; i++) {
allocators.add(() -> createNodes(db, numNodes / numThreads));
}
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
List<Future<MutableLongSet>> results = executor.invokeAll(allocators);
MutableLongSet reallocatedNodeIds = LongSets.mutable.withInitialCapacity(numNodes);
for (Future<MutableLongSet> result : results) {
reallocatedNodeIds.addAll(result.get());
}
assertThat(reallocatedNodeIds).as(diff(nodeIds, reallocatedNodeIds)).isEqualTo(nodeIds);
} finally {
dbms.shutdown();
}
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class HttpTransactionManagerTest method shouldGetEmptyTransactionFacadeOfDatabaseData.
@Test
void shouldGetEmptyTransactionFacadeOfDatabaseData() {
DatabaseManagementService managementService = mock(DatabaseManagementService.class);
var memoryPool = mock(MemoryPool.class);
var manager = newTransactionManager(managementService, memoryPool);
var graphDatabaseFacade = manager.getGraphDatabaseAPI("data");
assertFalse(graphDatabaseFacade.isPresent());
verify(managementService).database("data");
}
Aggregations