Search in sources :

Example 91 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.

@ParameterizedTest
@MethodSource("params")
void shouldCreateConsistentUniquenessConstraint(int denseNodeThreshold) throws Exception {
    // given
    BatchInserter inserter = newBatchInserter(denseNodeThreshold);
    // when
    inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
    // then
    GraphDatabaseAPI graphdb = switchToEmbeddedGraphDatabaseService(inserter, denseNodeThreshold);
    try {
        NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
        SchemaStore store = neoStores.getSchemaStore();
        TokenHolders tokenHolders = graphdb.getDependencyResolver().resolveDependency(TokenHolders.class);
        SchemaRuleAccess schemaRuleAccess = SchemaRuleAccess.getSchemaRuleAccess(store, tokenHolders, () -> KernelVersion.LATEST);
        List<Long> inUse = new ArrayList<>();
        SchemaRecord record = store.newRecord();
        for (long i = 1, high = store.getHighestPossibleIdInUse(NULL); i <= high; i++) {
            store.getRecord(i, record, RecordLoad.FORCE, NULL);
            if (record.inUse()) {
                inUse.add(i);
            }
        }
        assertEquals(2, inUse.size(), "records in use");
        SchemaRule rule0 = schemaRuleAccess.loadSingleSchemaRule(inUse.get(0), NULL);
        SchemaRule rule1 = schemaRuleAccess.loadSingleSchemaRule(inUse.get(1), NULL);
        IndexDescriptor indexRule;
        ConstraintDescriptor constraint;
        if (rule0 instanceof IndexDescriptor) {
            indexRule = (IndexDescriptor) rule0;
            constraint = (ConstraintDescriptor) rule1;
        } else {
            constraint = (ConstraintDescriptor) rule0;
            indexRule = (IndexDescriptor) rule1;
        }
        OptionalLong owningConstraintId = indexRule.getOwningConstraintId();
        assertTrue(owningConstraintId.isPresent(), "index should have owning constraint");
        assertEquals(constraint.getId(), owningConstraintId.getAsLong(), "index should reference constraint");
        assertEquals(indexRule.getId(), constraint.asIndexBackedConstraint().ownedIndexId(), "constraint should reference index");
    } finally {
        managementService.shutdown();
    }
}
Also used : SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) SchemaRuleAccess(org.neo4j.internal.recordstorage.SchemaRuleAccess) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.internal.schema.SchemaRule) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) BatchInserter(org.neo4j.batchinsert.BatchInserter) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) OptionalLong(java.util.OptionalLong) OptionalLong(java.util.OptionalLong) TokenHolders(org.neo4j.token.TokenHolders) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 92 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class BatchInsertTest method instantiateGraphDatabaseService.

private GraphDatabaseAPI instantiateGraphDatabaseService(int denseNodeThreshold) {
    TestDatabaseManagementServiceBuilder factory = new TestDatabaseManagementServiceBuilder(databaseLayout);
    factory.setFileSystem(fs);
    managementService = factory.impermanent().setConfig(configuration(denseNodeThreshold)).build();
    return (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI)

Example 93 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class BoltKeepAliveSchedulingIT method installSleepProcedure.

private static void installSleepProcedure(GraphDatabaseService db) throws ProcedureException {
    GraphDatabaseAPI dbApi = (GraphDatabaseAPI) db;
    dbApi.getDependencyResolver().resolveDependency(GlobalProcedures.class).register(new CallableProcedure.BasicProcedure(procedureSignature("boltissue", "sleep").out(ProcedureSignature.VOID).build()) {

        @Override
        public RawIterator<AnyValue[], ProcedureException> apply(Context context, AnyValue[] objects, ResourceTracker resourceTracker) throws ProcedureException {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new ProcedureException(Status.General.UnknownError, e, "Interrupted");
            }
            return RawIterator.empty();
        }
    });
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) RawIterator(org.neo4j.collection.RawIterator) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures)

Example 94 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class BatchInsertTokenIndexesTest method instantiateGraphDatabaseService.

private GraphDatabaseAPI instantiateGraphDatabaseService() {
    TestDatabaseManagementServiceBuilder factory = new TestDatabaseManagementServiceBuilder(databaseLayout);
    factory.setFileSystem(fs);
    managementService = factory.setConfig(configuration()).build();
    return (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI)

Example 95 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class DatabaseUpgradeTransactionIT method setDbmsRuntime.

private void setDbmsRuntime(DbmsRuntimeVersion runtimeVersion) {
    GraphDatabaseAPI system = (GraphDatabaseAPI) dbms.database(GraphDatabaseSettings.SYSTEM_DATABASE_NAME);
    try (var tx = system.beginTx()) {
        tx.findNodes(VERSION_LABEL).stream().forEach(dbmsRuntimeNode -> dbmsRuntimeNode.setProperty(DBMS_RUNTIME_COMPONENT, runtimeVersion.getVersion()));
        tx.commit();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI)

Aggregations

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)262 Test (org.junit.Test)91 Test (org.junit.jupiter.api.Test)88 Transaction (org.neo4j.graphdb.Transaction)87 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)61 Node (org.neo4j.graphdb.Node)38 Path (java.nio.file.Path)30 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)26 File (java.io.File)25 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)24 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)19 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)18 DependencyResolver (org.neo4j.graphdb.DependencyResolver)17 Label (org.neo4j.graphdb.Label)15 PageCache (org.neo4j.io.pagecache.PageCache)15 Config (org.neo4j.kernel.configuration.Config)15 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)14 IOException (java.io.IOException)11