Search in sources :

Example 11 with BatchInserter

use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertIndexTest method shouldPopulateIndexWithUniquePointsThatCollideOnSpaceFillingCurve.

@ParameterizedTest
@EnumSource(SchemaIndex.class)
void shouldPopulateIndexWithUniquePointsThatCollideOnSpaceFillingCurve(SchemaIndex schemaIndex) throws Exception {
    configure(schemaIndex);
    BatchInserter inserter = newBatchInserter();
    Pair<PointValue, PointValue> collidingPoints = SpatialIndexValueTestUtil.pointsWithSameValueOnSpaceFillingCurve(configBuilder.build());
    inserter.createNode(MapUtil.map("prop", collidingPoints.first()), LABEL_ONE);
    inserter.createNode(MapUtil.map("prop", collidingPoints.other()), LABEL_ONE);
    inserter.createDeferredConstraint(LABEL_ONE).assertPropertyIsUnique("prop").create();
    inserter.shutdown();
    GraphDatabaseService db = startGraphDatabaseServiceAndAwaitIndexes();
    try (Transaction tx = db.beginTx()) {
        assertSingleCorrectHit(collidingPoints.first(), tx);
        assertSingleCorrectHit(collidingPoints.other(), tx);
        tx.commit();
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PointValue(org.neo4j.values.storable.PointValue) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with BatchInserter

use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertionIT method shouldBeAbleToMakeRepeatedCallsToSetNodeProperty.

@Test
void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception {
    final Object finalValue = 87;
    BatchInserter inserter = BatchInserters.inserter(databaseLayout, fileSystem);
    long nodeId = inserter.createNode(Collections.emptyMap());
    inserter.setNodeProperty(nodeId, "a", "some property value");
    inserter.setNodeProperty(nodeId, "a", 42);
    inserter.setNodeProperty(nodeId, "a", 3.14);
    inserter.setNodeProperty(nodeId, "a", true);
    inserter.setNodeProperty(nodeId, "a", finalValue);
    inserter.shutdown();
    var db = getDatabase();
    try (Transaction tx = db.beginTx()) {
        assertThat(tx.getNodeById(nodeId).getProperty("a")).isEqualTo(finalValue);
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.jupiter.api.Test)

Example 13 with BatchInserter

use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertionIT method shouldNotIndexNodesWithWrongLabel.

@Test
void shouldNotIndexNodesWithWrongLabel() throws Exception {
    try (BatchInserter inserter = BatchInserters.inserter(databaseLayout, fileSystem)) {
        inserter.createNode(map("name", "Bob"), label("User"), label("Admin"));
        inserter.createDeferredSchemaIndex(label("Banana")).on("name").create();
    }
    var db = getDatabase();
    try (Transaction tx = db.beginTx()) {
        assertThat(count(tx.findNodes(label("Banana"), "name", "Bob"))).isEqualTo(0L);
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.jupiter.api.Test)

Example 14 with BatchInserter

use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.

the class GitHub1304Test method givenBatchInserterWhenArrayPropertyUpdated4TimesThenShouldNotFail.

@Test
void givenBatchInserterWhenArrayPropertyUpdated4TimesThenShouldNotFail() throws IOException {
    BatchInserter batchInserter = BatchInserters.inserter(databaseLayout, fileSystem);
    long nodeId = batchInserter.createNode(Collections.emptyMap());
    for (int i = 0; i < 4; i++) {
        batchInserter.setNodeProperty(nodeId, "array", new byte[] { 2, 3, 98, 1, 43, 50, 3, 33, 51, 55, 116, 16, 23, 56, 9, -10, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
    }
    // fails here
    batchInserter.getNodeProperties(nodeId);
    batchInserter.shutdown();
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) Test(org.junit.jupiter.api.Test)

Example 15 with BatchInserter

use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertTest method shouldStartOnAndUpdateDbContainingFulltextIndex.

@Test
void shouldStartOnAndUpdateDbContainingFulltextIndex() throws Exception {
    // given
    // this test cannot run on an impermanent db since there's a test issue causing problems when flipping/closing RAMDirectory Lucene indexes
    int denseNodeThreshold = GraphDatabaseSettings.dense_node_threshold.defaultValue();
    GraphDatabaseService db = instantiateGraphDatabaseService(denseNodeThreshold);
    String key = "key";
    Label label = Label.label("Label");
    String indexName = "ftsNodes";
    try {
        try (Transaction tx = db.beginTx()) {
            db.executeTransactionally(format("CREATE FULLTEXT INDEX %s FOR (n:%s) ON EACH [n.%s]", indexName, label.name(), key));
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
            tx.commit();
        }
    } finally {
        managementService.shutdown();
    }
    // when
    String value = "hey";
    BatchInserter inserter = newBatchInserter(denseNodeThreshold);
    long node = inserter.createNode(Collections.singletonMap(key, value), label);
    // then
    inserter.shutdown();
    GraphDatabaseAPI dbAfterInsert = instantiateGraphDatabaseService(denseNodeThreshold);
    try {
        try (Transaction tx = dbAfterInsert.beginTx()) {
            // Check that the store has this node
            ResourceIterator<Node> nodes = tx.findNodes(label, key, value);
            Node foundNode = Iterators.single(nodes);
            assertEquals(node, foundNode.getId());
            // Check that the fulltext index has this node
            dbAfterInsert.executeTransactionally(format("CALL db.index.fulltext.queryNodes('%s', '%s')", indexName, value), new HashMap<>(), result -> {
                assertTrue(result.hasNext());
                Map<String, Object> hit = result.next();
                Node indexedNode = (Node) hit.get("node");
                assertFalse(result.hasNext());
                return indexedNode;
            });
        }
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) BatchInserter(org.neo4j.batchinsert.BatchInserter) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

BatchInserter (org.neo4j.batchinsert.BatchInserter)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Test (org.junit.jupiter.api.Test)14 Transaction (org.neo4j.graphdb.Transaction)13 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)11 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 Label (org.neo4j.graphdb.Label)6 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)6 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 ArrayList (java.util.ArrayList)4 OptionalLong (java.util.OptionalLong)4 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.IndexSamplingConfig)4 IOException (java.io.IOException)3 String.format (java.lang.String.format)3 Files (java.nio.file.Files)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Arrays (java.util.Arrays)3 Arrays.asList (java.util.Arrays.asList)3 Collections (java.util.Collections)3