Search in sources :

Example 86 with GraphDatabaseAPI

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

the class NeoWebServerJAXRSIT method createSimpleDatabase.

private static int createSimpleDatabase(final GraphDatabaseAPI graph) {
    final var numberOfNodes = 10;
    new Transactor(graph, tx -> {
        for (var i = 0; i < numberOfNodes; i++) {
            tx.createNode();
        }
        for (var node1 : tx.getAllNodes()) {
            for (var node2 : tx.getAllNodes()) {
                if (node1.equals(node2)) {
                    continue;
                }
                node1.createRelationshipTo(node2, RelationshipType.withName("REL"));
            }
        }
    }).execute();
    return numberOfNodes;
}
Also used : ExclusiveWebContainerTestBase(org.neo4j.test.server.ExclusiveWebContainerTestBase) BodyHandlers.discarding(java.net.http.HttpResponse.BodyHandlers.discarding) DummyThirdPartyWebService(org.dummy.web.service.DummyThirdPartyWebService) HttpClient.newBuilder(java.net.http.HttpClient.newBuilder) NORMAL(java.net.http.HttpClient.Redirect.NORMAL) Test(org.junit.Test) CommunityWebContainerBuilder(org.neo4j.server.helpers.CommunityWebContainerBuilder) HttpRequest(java.net.http.HttpRequest) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestWebContainer(org.neo4j.server.helpers.TestWebContainer) WebContainerHelper(org.neo4j.server.helpers.WebContainerHelper) FunctionalTestHelper(org.neo4j.server.helpers.FunctionalTestHelper) After(org.junit.After) HttpClient(java.net.http.HttpClient) RelationshipType(org.neo4j.graphdb.RelationshipType) URI(java.net.URI) Transactor(org.neo4j.server.helpers.Transactor) BodyHandlers.ofString(java.net.http.HttpResponse.BodyHandlers.ofString) Assert.assertEquals(org.junit.Assert.assertEquals) Transactor(org.neo4j.server.helpers.Transactor)

Example 87 with GraphDatabaseAPI

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

the class UniqueIndexSeekIT method uniqueIndexSeekDoNotLeakIndexReaders.

@ParameterizedTest
@MethodSource("indexProviderFactories")
void uniqueIndexSeekDoNotLeakIndexReaders(AbstractIndexProviderFactory providerFactory) throws KernelException {
    TrackingIndexExtensionFactory indexExtensionFactory = new TrackingIndexExtensionFactory(providerFactory);
    GraphDatabaseAPI database = createDatabase(indexExtensionFactory, providerFactory.descriptor());
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    Config config = dependencyResolver.resolveDependency(Config.class);
    try {
        Label label = label("spaceship");
        String nameProperty = "name";
        createUniqueConstraint(database, label, nameProperty);
        generateRandomData(database, label, nameProperty);
        assertNotNull(indexExtensionFactory.getIndexProvider(config.get(default_database)));
        assertThat(numberOfClosedReaders()).isGreaterThan(0L);
        assertThat(numberOfOpenReaders()).isGreaterThan(0L);
        assertThat(numberOfClosedReaders()).isCloseTo(numberOfOpenReaders(), within(1L));
        lockNodeUsingUniqueIndexSeek(database, nameProperty);
        assertThat(numberOfClosedReaders()).isCloseTo(numberOfOpenReaders(), within(1L));
    } finally {
        managementService.shutdown();
    }
}
Also used : TrackingIndexExtensionFactory(org.neo4j.kernel.impl.index.schema.tracking.TrackingIndexExtensionFactory) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Config(org.neo4j.configuration.Config) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.common.DependencyResolver) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 88 with GraphDatabaseAPI

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

the class DbmsSupportController method startDatabase.

public void startDatabase(String databaseName) {
    if (!dbms.listDatabases().contains(databaseName)) {
        dbms.createDatabase(databaseName);
    }
    var db = (GraphDatabaseAPI) dbms.database(databaseName);
    var dependencyResolver = db.getDependencyResolver();
    injectDependencies(dependencyResolver);
    // Also inject DbmsController into the test.
    Dependencies deps = new Dependencies();
    deps.satisfyDependencies(asDbmsController());
    injectDependencies(deps);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Dependencies(org.neo4j.collection.Dependencies)

Example 89 with GraphDatabaseAPI

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

the class TestDatabaseManagementServiceBuilderTest method databaseStartsWithSystemAndDefaultDatabase.

@Test
void databaseStartsWithSystemAndDefaultDatabase() {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    try {
        checkAvailableDatabases(database);
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 90 with GraphDatabaseAPI

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

the class Neo4jWithSocket method ensureDatabase.

public void ensureDatabase(Consumer<Map<Setting<?>, Object>> overrideSettingsFunction) {
    if (gdb != null) {
        return;
    }
    Map<Setting<?>, Object> settings = configure(overrideSettingsFunction);
    Path storeDir = workingDirectory.resolve("storeDir");
    installSelfSignedCertificateIfEncryptionEnabled(settings);
    graphDatabaseFactory.setFileSystem(fileSystemProvider.get());
    managementService = graphDatabaseFactory.setDatabaseRootDirectory(storeDir).impermanent().setConfig(settings).build();
    gdb = managementService.database(DEFAULT_DATABASE_NAME);
    connectorRegister = ((GraphDatabaseAPI) gdb).getDependencyResolver().resolveDependency(ConnectorPortRegister.class);
}
Also used : Path(java.nio.file.Path) ConnectorPortRegister(org.neo4j.configuration.connectors.ConnectorPortRegister) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Setting(org.neo4j.graphdb.config.Setting)

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