Search in sources :

Example 61 with TestDatabaseManagementServiceBuilder

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

the class JavaExecutionEngineDocTest method setUp.

@Before
public void setUp() throws IOException {
    managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = this.db.beginTx()) {
        tx.schema().indexFor(Label.label("Person")).on("name").withName("My index").create();
        tx.commit();
    }
    try (Transaction tx = this.db.beginTx()) {
        Node michaelaNode = tx.createNode(Label.label("Person"));
        Node bobNode = tx.createNode(Label.label("Person"));
        Node johanNode = tx.createNode(Label.label("Person"));
        bobNode.setProperty("name", "Bob");
        johanNode.setProperty("name", "Johan");
        michaelaNode.setProperty("name", "Michaela");
        michaelaNodeId = michaelaNode.getId();
        bobNodeId = bobNode.getId();
        johanNodeId = johanNode.getId();
        tx.commit();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Before(org.junit.Before)

Example 62 with TestDatabaseManagementServiceBuilder

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

the class IndexConfigMigrationIT method shouldHaveCorrectDataAndIndexConfiguration.

@Test
void shouldHaveCorrectDataAndIndexConfiguration() throws IOException, IndexNotFoundKernelException {
    Path databaseDir = databaseLayout.databaseDirectory();
    unzip(getClass(), ZIP_FILE_3_5, databaseDir);
    // when
    DatabaseManagementServiceBuilder builder = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setConfig(GraphDatabaseSettings.allow_upgrade, true);
    DatabaseManagementService dbms = builder.build();
    try {
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        Set<CoordinateReferenceSystem> allCRS = Iterables.asSet(all());
        try (Transaction tx = db.beginTx()) {
            validateIndexes(tx);
            for (Node node : tx.getAllNodes()) {
                hasLabels(node, label1, label2, label3, label4);
                Object property = node.getProperty(propKey);
                if (property instanceof PointValue) {
                    allCRS.remove(((PointValue) property).getCoordinateReferenceSystem());
                }
            }
            assertTrue(allCRS.isEmpty(), "Expected all CRS to be represented in store, but missing " + allCRS);
            assertIndexConfiguration(db, tx);
            assertFulltextIndexConfiguration(db, tx);
            tx.commit();
        }
    } finally {
        dbms.shutdown();
    }
    // Assert old index files has been removed
    Path baseSchemaIndexFolder = IndexDirectoryStructure.baseSchemaIndexFolder(databaseDir);
    Set<Path> retiredIndexProviderDirectories = Set.of(baseSchemaIndexFolder.resolve("lucene"), baseSchemaIndexFolder.resolve("lucene-1.0"), baseSchemaIndexFolder.resolve("lucene_native-1.0"), baseSchemaIndexFolder.resolve("lucene_native-2.0"));
    try (Stream<Path> list = Files.list(baseSchemaIndexFolder)) {
        list.forEach(indexProviderDirectory -> assertFalse(retiredIndexProviderDirectories.contains(indexProviderDirectory), "Expected old index provider directories to be deleted during migration but store still had directory " + indexProviderDirectory));
    }
}
Also used : Path(java.nio.file.Path) PointValue(org.neo4j.values.storable.PointValue) Node(org.neo4j.graphdb.Node) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 63 with TestDatabaseManagementServiceBuilder

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

the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method create3_5Database.

@Disabled("Here as reference for how 3.5 db was created")
@Test
void create3_5Database() throws Exception {
    Path storeDir = tempStoreDirectory();
    DatabaseManagementServiceBuilder builder = new TestDatabaseManagementServiceBuilder(storeDir);
    createIndexDataAndShutdown(builder, "lucene-1.0", Provider.LUCENE_10.label);
    createIndexDataAndShutdown(builder, "lucene+native-1.0", Provider.FUSION_10.label);
    createIndexDataAndShutdown(builder, "lucene+native-2.0", Provider.FUSION_20.label);
    createIndexDataAndShutdown(builder, GraphDatabaseSettings.SchemaIndex.NATIVE_BTREE10.providerName(), Provider.BTREE_10.label, db -> {
        try (Transaction tx = db.beginTx()) {
            tx.execute("CALL db.index.fulltext.createNodeIndex('fts1', ['Fts1'], ['prop1'] )").close();
            tx.execute("CALL db.index.fulltext.createNodeIndex('fts2', ['Fts2', 'Fts3'], ['prop1', 'prop2'] )").close();
            tx.execute("CALL db.index.fulltext.createNodeIndex('fts3', ['Fts4'], ['prop1'], {eventually_consistent: 'true'} )").close();
            tx.execute("CALL db.index.fulltext.createRelationshipIndex('fts4', ['FtsRel1', 'FtsRel2'], ['prop1', 'prop2'], " + "{eventually_consistent: 'true'} )").close();
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            tx.schema().awaitIndexesOnline(10, TimeUnit.MINUTES);
            Node node = tx.createNode(Label.label("Fts1"), Label.label("Fts2"), Label.label("Fts3"), Label.label("Fts4"));
            node.setProperty("prop1", "abc");
            node.setProperty("prop2", "abc");
            node.createRelationshipTo(node, RelationshipType.withName("FtsRel1")).setProperty("prop1", "abc");
            node.createRelationshipTo(node, RelationshipType.withName("FtsRel2")).setProperty("prop2", "abc");
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            tx.execute("call db.index.fulltext.awaitEventuallyConsistentIndexRefresh").close();
            tx.commit();
        }
    });
    Path zipFile = storeDir.resolveSibling(storeDir.getFileName().toString() + ".zip");
    ZipUtils.zip(new DefaultFileSystemAbstraction(), storeDir, zipFile);
    System.out.println("Db created in " + zipFile.toAbsolutePath());
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 64 with TestDatabaseManagementServiceBuilder

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

the class DefaultDatabaseManagerIT method setUp.

@BeforeEach
void setUp() {
    managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setConfig(GraphDatabaseSettings.logical_log_rotation_threshold, kibiBytes(128)).build();
    database = managementService.database(DEFAULT_DATABASE_NAME);
    databaseManager = ((GraphDatabaseAPI) database).getDependencyResolver().resolveDependency(DatabaseManager.class);
    defaultNamedDatabaseId = databaseManager.databaseIdRepository().getByName(DEFAULT_DATABASE_NAME).orElseThrow();
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 65 with TestDatabaseManagementServiceBuilder

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

the class IndexSamplingIntegrationTest method fetchIndexSamplingValues.

private IndexSample fetchIndexSamplingValues() throws IndexNotFoundKernelException, TransactionFailureException {
    DatabaseManagementService managementService = null;
    try {
        // Then
        managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
        GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
        GraphDatabaseAPI api = (GraphDatabaseAPI) db;
        Kernel kernel = api.getDependencyResolver().resolveDependency(Kernel.class);
        try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, AUTH_DISABLED)) {
            return tx.schemaRead().indexSample(indexId(tx));
        }
    } finally {
        if (managementService != null) {
            managementService.shutdown();
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Kernel(org.neo4j.kernel.api.Kernel)

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