use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class IndexConstraintsTest method setup.
@BeforeEach
void setup() {
managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
graphDb = managementService.database(DEFAULT_DATABASE_NAME);
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class IndexSamplingIntegrationTest method shouldSampleNotUniqueIndex.
@ParameterizedTest
@EnumSource(Entity.class)
void shouldSampleNotUniqueIndex(Entity entity) throws Throwable {
GraphDatabaseService db;
DatabaseManagementService managementService = null;
long deletedNodes = 0;
try {
// Given
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
entity.createIndex(tx, schemaName, TOKEN, property);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexOnline(schemaName, 1, TimeUnit.MINUTES);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < entities; i++) {
entity.createEntity(tx, TOKEN, property, names[i % names.length]);
}
tx.commit();
}
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < (entities / 10); i++) {
entity.deleteFirstFound(tx, TOKEN, property, names[i % names.length]);
deletedNodes++;
}
tx.commit();
}
} finally {
if (managementService != null) {
managementService.shutdown();
}
}
// When
triggerIndexResamplingOnNextStartup();
// Then
// lucene will consider also the delete nodes, native won't
var indexSample = fetchIndexSamplingValues();
assertThat(indexSample.uniqueValues()).as("Unique values").isEqualTo(names.length);
assertThat(indexSample.sampleSize()).as("Sample size").isGreaterThanOrEqualTo(entities - deletedNodes).isLessThanOrEqualTo(entities);
// but regardless, the deleted nodes should not be considered in the index size value
assertThat(indexSample.updates()).as("Updates").isEqualTo(0);
assertThat(indexSample.indexSize()).as("Index size").isEqualTo(entities - deletedNodes);
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class DatabaseStartupTest method dumpSystemDiagnosticLoggingOnStartup.
@Test
void dumpSystemDiagnosticLoggingOnStartup() {
AssertableLogProvider logProvider = new AssertableLogProvider();
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setInternalLogProvider(logProvider).setConfig(GraphDatabaseInternalSettings.dump_diagnostics, true).build();
managementService.database(DEFAULT_DATABASE_NAME);
try {
assertThat(logProvider).containsMessages("System diagnostics", "System memory information", "JVM memory information", "Operating system information", "JVM information", "Java classpath", "Library path", "System properties", "(IANA) TimeZone database version", "Network information", "DBMS config");
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class DatabaseStartupTest method startDatabaseWithoutStoreFilesAndWithTransactionLogFilesFailure.
@Test
void startDatabaseWithoutStoreFilesAndWithTransactionLogFilesFailure() throws IOException {
// Create a store
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
DatabaseLayout databaseLayout = db.databaseLayout();
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
managementService.shutdown();
fs.deleteRecursively(databaseLayout.databaseDirectory());
// Try to start
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
try {
db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
assertFalse(db.isAvailable(10));
DatabaseStateService dbStateService = db.getDependencyResolver().resolveDependency(DatabaseStateService.class);
Optional<Throwable> cause = dbStateService.causeOfFailure(db.databaseId());
assertTrue(cause.isPresent());
assertThat(cause.get()).hasStackTraceContaining("Fail to start '" + db.databaseId() + "' since transaction logs were found, while database ");
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class CommunitySystemDatabaseIT method setUp.
@BeforeEach
void setUp() {
managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).noOpSystemGraphInitializer().build();
database = managementService.database(DEFAULT_DATABASE_NAME);
databaseManager = getDatabaseManager(database);
defaultDb = getDatabaseByName(databaseManager, databaseManager.databaseIdRepository().getByName(DEFAULT_DATABASE_NAME).get());
systemDb = getDatabaseByName(databaseManager, NAMED_SYSTEM_DATABASE_ID);
}
Aggregations