use of org.neo4j.kernel.internal.GraphDatabaseAPI 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.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class CheckPointerIntegrationTest method checkPointInTxLog.
private static List<CheckpointInfo> checkPointInTxLog(GraphDatabaseService db) throws IOException {
DependencyResolver dependencyResolver = ((GraphDatabaseAPI) db).getDependencyResolver();
LogFiles logFiles = dependencyResolver.resolveDependency(LogFiles.class);
return logFiles.getCheckpointFile().reachableCheckpoints();
}
use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class CheckPointerIntegrationTest method tracePageCacheAccessOnCheckpoint.
@Test
void tracePageCacheAccessOnCheckpoint() throws Exception {
var managementService = builder.setConfig(check_point_interval_time, ofMillis(0)).setConfig(check_point_interval_tx, 1).setConfig(logical_log_rotation_threshold, gibiBytes(1)).build();
try {
GraphDatabaseAPI databaseAPI = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
var cacheTracer = databaseAPI.getDependencyResolver().resolveDependency(PageCacheTracer.class);
long initialFlushes = cacheTracer.flushes();
long initialBytesWritten = cacheTracer.bytesWritten();
long initialPins = cacheTracer.pins();
getCheckPointer(databaseAPI).forceCheckPoint(new SimpleTriggerInfo("tracing"));
assertThat(cacheTracer.flushes()).isGreaterThan(initialFlushes);
assertThat(cacheTracer.bytesWritten()).isGreaterThan(initialBytesWritten);
assertThat(cacheTracer.pins()).isGreaterThan(initialPins);
} finally {
managementService.shutdown();
}
}
use of org.neo4j.kernel.internal.GraphDatabaseAPI 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.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.
the class ImportCommandTest method shouldIgnoreWhitespaceInAndAroundBooleanArrays.
@Test
void shouldIgnoreWhitespaceInAndAroundBooleanArrays() throws Exception {
// GIVEN
// Faster to do all successful in one import than in N separate tests
String[] values = new String[] { "true", " true", "true ", " true ", " false ", "false ", " false", "false ", " false" };
String expected = joinStringArray(values);
Path data = writeArrayCsv(new String[] { "b:boolean[]" }, values);
Path dbConfig = prepareDefaultConfigFile();
// WHEN
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--quote", "'", "--nodes", data.toAbsolutePath().toString());
// THEN
int nodeCount = 0;
GraphDatabaseAPI databaseApi = getDatabaseApi();
try (Transaction tx = databaseApi.beginTx()) {
for (Node node : tx.getAllNodes()) {
nodeCount++;
assertEquals(1, node.getAllProperties().size());
for (String key : node.getPropertyKeys()) {
Object things = node.getProperty(key);
String result = Arrays.toString((boolean[]) things);
assertEquals(expected, result);
}
}
tx.commit();
}
assertEquals(1, nodeCount);
}
Aggregations