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();
}
}
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);
}
}
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();
}
}
Aggregations