Search in sources :

Example 21 with BatchInserter

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

the class BatchInsertIndexTest method shouldThrowWhenPopulatingWithNonUniquePoints.

@ParameterizedTest
@EnumSource(SchemaIndex.class)
void shouldThrowWhenPopulatingWithNonUniquePoints(SchemaIndex schemaIndex) throws Exception {
    configure(schemaIndex);
    BatchInserter inserter = newBatchInserter();
    PointValue point = Values.pointValue(CoordinateReferenceSystem.WGS84, 0.0, 0.0);
    inserter.createNode(MapUtil.map("prop", point), LABEL_ONE);
    inserter.createNode(MapUtil.map("prop", point), LABEL_ONE);
    inserter.createDeferredConstraint(LABEL_ONE).assertPropertyIsUnique("prop").create();
    inserter.shutdown();
    GraphDatabaseService db = startGraphDatabaseService();
    try (Transaction tx = db.beginTx()) {
        assertThrows(IllegalStateException.class, () -> tx.schema().awaitIndexesOnline(10, TimeUnit.SECONDS));
    }
    try (Transaction tx = db.beginTx()) {
        var schema = tx.schema();
        Iterator<IndexDefinition> indexes = schema.getIndexes().iterator();
        assertTrue(indexes.hasNext());
        IndexDefinition index = indexes.next();
        Schema.IndexState indexState = schema.getIndexState(index);
        assertEquals(Schema.IndexState.FAILED, indexState);
        assertFalse(indexes.hasNext());
        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) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) PointValue(org.neo4j.values.storable.PointValue) Schema(org.neo4j.graphdb.schema.Schema) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with BatchInserter

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

the class BatchInsertTokenIndexesTest method shouldPopulateTokenIndexesOnShutdown.

@Test
void shouldPopulateTokenIndexesOnShutdown() throws Exception {
    // create empty database with SSTI enabled
    try {
        GraphDatabaseService db = instantiateGraphDatabaseService();
        // verify there are some indexes present
        try (var tx = db.beginTx()) {
            var indexes = tx.schema().getIndexes();
            assertThat(indexes).hasSize(2);
            tx.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
        }
    } finally {
        managementService.shutdown();
    }
    // insert some nodes and rels
    BatchInserter inserter = BatchInserters.inserter(databaseLayout, fs, configuration());
    long node1 = inserter.createNode(null, Labels.FIRST);
    long node2 = inserter.createNode(null, Labels.SECOND);
    long node3 = inserter.createNode(null, Labels.THIRD);
    long node4 = inserter.createNode(null, Labels.FIRST, Labels.SECOND);
    long node5 = inserter.createNode(null, Labels.FIRST, Labels.THIRD);
    long rel1 = inserter.createRelationship(node1, node2, RelTypes.REL_TYPE1, emptyMap());
    long rel2 = inserter.createRelationship(node2, node3, RelTypes.REL_TYPE2, emptyMap());
    long rel3 = inserter.createRelationship(node3, node4, RelTypes.REL_TYPE3, emptyMap());
    long rel4 = inserter.createRelationship(node3, node4, RelTypes.REL_TYPE1, emptyMap());
    long rel5 = inserter.createRelationship(node3, node4, RelTypes.REL_TYPE3, emptyMap());
    inserter.shutdown();
    // verify token indexes contain inserted entities
    try (var accesor = tokenIndexAccessor(EntityType.NODE);
        var reader = accesor.newTokenReader()) {
        assertTokenIndexContains(reader, 0, node1, node4, node5);
        assertTokenIndexContains(reader, 1, node2, node4);
        assertTokenIndexContains(reader, 2, node3, node5);
    }
    try (var accesor = tokenIndexAccessor(EntityType.RELATIONSHIP);
        var reader = accesor.newTokenReader()) {
        assertTokenIndexContains(reader, 0, rel1, rel4);
        assertTokenIndexContains(reader, 1, rel2);
        assertTokenIndexContains(reader, 2, rel3, rel5);
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserter(org.neo4j.batchinsert.BatchInserter) Test(org.junit.jupiter.api.Test)

Example 23 with BatchInserter

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

the class PropertyKeyTest method lazyLoadWithinWriteTransaction.

@Test
void lazyLoadWithinWriteTransaction() throws IOException {
    BatchInserter inserter = BatchInserters.inserter(databaseLayout, fs);
    int count = 3000;
    long nodeId = inserter.createNode(mapWithManyProperties(count));
    inserter.shutdown();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setFileSystem(fs).impermanent().build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    // When
    try (Transaction tx = db.beginTx()) {
        tx.createNode();
        Node node = tx.getNodeById(nodeId);
        // Then
        assertEquals(count, Iterables.count(node.getPropertyKeys()));
        tx.commit();
    } finally {
        managementService.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) 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