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