Search in sources :

Example 31 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class UniqueConstraintCompatibility method setUp.

/*
     * There are a quite a number of permutations to consider, when it comes to unique
     * constraints.
     *
     * We have two supported providers:
     *  - InMemoryIndexProvider
     *  - LuceneIndexProvider
     *
     * An index can be in a number of states, two of which are interesting:
     *  - ONLINE: the index is in active duty
     *  - POPULATING: the index is in the process of being created and filled with data
     *
     * Further more, indexes that are POPULATING have two ways of ingesting data:
     *  - Through add()'ing existing data
     *  - Through NodePropertyUpdates sent to a "populating updater"
     *
     * Then, when we add data to an index, two outcomes are possible, depending on the
     * data:
     *  - The index does not contain an equivalent value, and the entity id is added to
     *    the index.
     *  - The index already contains an equivalent value, and the addition is rejected.
     *
     * And when it comes to observing these outcomes, there are a whole bunch of
     * interesting transaction states that are worth exploring:
     *  - Adding a label to a node
     *  - Removing a label from a node
     *  - Combinations of adding and removing a label, ultimately adding it
     *  - Combinations of adding and removing a label, ultimately removing it
     *  - Adding a property
     *  - Removing a property
     *  - Changing an existing property
     *  - Combinations of adding and removing a property, ultimately adding it
     *  - Combinations of adding and removing a property, ultimately removing it
     *  - Likewise combinations of adding, removing and changing a property
     *
     * To make matters worse, we index a number of different types, some of which may or
     * may not collide in the index because of coercion. We need to make sure that the
     * indexes deal with these values correctly. And we also have the ways in which these
     * operations can be performed in any number of transactions, for instance, if all
     * the conflicting nodes were added in the same transaction or not.
     *
     * All in all, we have many cases to test for!
     *
     * Still, it is possible to boil things down a little bit, because there are fewer
     * outcomes than there are scenarios that lead to those outcomes. With a bit of
     * luck, we can abstract over the scenarios that lead to those outcomes, and then
     * only write a test per outcome. These are the outcomes I see:
     *  - Populating an index succeeds
     *  - Populating an index fails because of the existing data
     *  - Populating an index fails because of updates to data
     *  - Adding to an online index succeeds
     *  - Adding to an online index fails because of existing data
     *  - Adding to an online index fails because of data in the same transaction
     *
     * There's a lot of work to be done here.
     */
@Before
public void setUp() {
    managementService = new TestDatabaseManagementServiceBuilder(graphDbDir).setExtensions(asList(new PredefinedIndexProviderFactory(indexProvider), new TokenIndexProviderFactory())).noOpSystemGraphInitializer().impermanent().setConfig(default_schema_provider, indexProvider.getProviderDescriptor().name()).build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) TokenIndexProviderFactory(org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory) Before(org.junit.Before)

Example 32 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class SystemTimeZoneLoggingIT method checkStartLogLine.

private void checkStartLogLine(int hoursShift, String timeZoneSuffix) throws IOException {
    TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.ofHours(hoursShift)));
    Path storeDir = testDirectory.homePath(String.valueOf(hoursShift));
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setConfig(GraphDatabaseSettings.db_timezone, LogTimeZone.SYSTEM).build();
    managementService.database(DEFAULT_DATABASE_NAME);
    managementService.shutdown();
    Path debugLog = Paths.get("logs", "debug.log");
    String debugLogLine = getLogLine(storeDir, debugLog);
    assertTrue(debugLogLine.contains(timeZoneSuffix), debugLogLine);
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 33 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class ConsistencyCheckWithCorruptGBPTreeIT method dbmsAction.

/**
 * Open dbms with schemaIndex as default index provider on provided file system abstraction and apply dbSetup to DEFAULT_DATABASE.
 */
private void dbmsAction(Path neo4jHome, FileSystemAbstraction fs, GraphDatabaseSettings.SchemaIndex schemaIndex, Consumer<GraphDatabaseService> dbSetup, Consumer<DatabaseManagementServiceBuilder> dbConfiguration) {
    TestDatabaseManagementServiceBuilder builder = new TestDatabaseManagementServiceBuilder(neo4jHome).setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs));
    dbConfiguration.accept(builder);
    final DatabaseManagementService dbms = builder.setConfig(GraphDatabaseSettings.default_schema_provider, schemaIndex.providerName()).build();
    try {
        final GraphDatabaseService db = dbms.database(DEFAULT_DATABASE_NAME);
        dbSetup.accept(db);
    } finally {
        dbms.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) UncloseableDelegatingFileSystemAbstraction(org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 34 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class GraphStoreFixture method startDatabaseAndExtractComponents.

private void startDatabaseAndExtractComponents() {
    managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setFileSystem(testDirectory.getFileSystem()).setConfig(GraphDatabaseSettings.record_format, formatName).setConfig(GraphDatabaseInternalSettings.label_block_size, 60).setConfig(GraphDatabaseInternalSettings.consistency_check_on_apply, false).setConfig(getConfig()).build();
    database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    commitProcess = new InternalTransactionCommitProcess(dependencyResolver.resolveDependency(TransactionAppender.class), dependencyResolver.resolveDependency(StorageEngine.class));
    transactionIdStore = database.getDependencyResolver().resolveDependency(TransactionIdStore.class);
    storageEngine = dependencyResolver.resolveDependency(RecordStorageEngine.class);
    neoStores = storageEngine.testAccessNeoStores();
    indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    directStoreAccess = new DirectStoreAccess(neoStores, dependencyResolver.resolveDependency(IndexProviderMap.class), dependencyResolver.resolveDependency(TokenHolders.class), dependencyResolver.resolveDependency(IndexStatisticsStore.class), dependencyResolver.resolveDependency(IdGeneratorFactory.class));
    countsStore = storageEngine.countsAccessor();
    groupDegreesStore = storageEngine.relationshipGroupDegreesStore();
    pageCache = dependencyResolver.resolveDependency(PageCache.class);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) PageCache(org.neo4j.io.pagecache.PageCache) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 35 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class TestExceptionTypeOnInvalidIds method createDatabase.

@BeforeEach
void createDatabase() {
    Path writableLayout = testDirectory.homePath("writable");
    writableService = new TestDatabaseManagementServiceBuilder(writableLayout).build();
    writableDb = writableService.database(DEFAULT_DATABASE_NAME);
    Path readOnlyLayout = testDirectory.homePath("readOnly");
    TestDatabaseManagementServiceBuilder readOnlyBuilder = new TestDatabaseManagementServiceBuilder(readOnlyLayout);
    // Create database
    readOnlyBuilder.build().shutdown();
    readOnlyService = readOnlyBuilder.setConfig(read_only_database_default, true).build();
    readOnlyDb = readOnlyService.database(DEFAULT_DATABASE_NAME);
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)135 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)74 Test (org.junit.jupiter.api.Test)48 Transaction (org.neo4j.graphdb.Transaction)42 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)38 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)30 Path (java.nio.file.Path)23 BeforeEach (org.junit.jupiter.api.BeforeEach)18 Node (org.neo4j.graphdb.Node)18 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)13 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)11 PageCache (org.neo4j.io.pagecache.PageCache)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)8 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 TokenIndexProviderFactory (org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Dependencies (org.neo4j.collection.Dependencies)6 Config (org.neo4j.configuration.Config)6 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)6