use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method setSingleProperty.
@ParameterizedTest
@MethodSource("params")
void setSingleProperty(int denseNodeThreshold) throws Exception {
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
long nodeById = inserter.createNode(null);
String value = "Something";
String key = "name";
inserter.setNodeProperty(nodeById, key, value);
GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(inserter, denseNodeThreshold);
try (var tx = db.beginTx()) {
var node = tx.getNodeById(nodeById);
assertThat(node.getProperty(key)).isEqualTo(value);
}
managementService.shutdown();
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldRunConstraintPopulationJobAtShutdown.
@ParameterizedTest
@MethodSource("params")
void shouldRunConstraintPopulationJobAtShutdown(int denseNodeThreshold) throws Throwable {
// GIVEN
IndexPopulator populator = mock(IndexPopulator.class);
IndexProvider provider = mock(IndexProvider.class);
IndexAccessor accessor = mock(IndexAccessor.class);
when(provider.getProviderDescriptor()).thenReturn(DESCRIPTOR);
when(provider.getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class))).thenReturn(populator);
when(populator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
when(provider.getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(accessor);
when(provider.completeConfiguration(any(IndexDescriptor.class))).then(inv -> inv.getArgument(0));
BatchInserter inserter = newBatchInserterWithIndexProvider(singleInstanceIndexProviderFactory(KEY, provider), provider.getProviderDescriptor(), denseNodeThreshold);
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
// WHEN
inserter.shutdown();
// THEN
verify(provider).init();
verify(provider).start();
verify(provider).getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
verify(populator).create();
verify(populator).add(argThat(c -> c.contains(add(nodeId, internalUniqueIndex.schema(), Values.of("Jakewins")))), any(CursorContext.class));
verify(populator).verifyDeferredConstraints(any(NodePropertyAccessor.class));
verify(populator).close(eq(true), any());
verify(provider).stop();
verify(provider).shutdown();
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldIncrementDegreesOnUpdatingDenseNode.
@Test
void shouldIncrementDegreesOnUpdatingDenseNode() throws Exception {
// given
int denseNodeThreshold = 10;
BatchInserter inserter = newBatchInserter(configurationBuilder().set(dense_node_threshold, 10).set(GraphDatabaseInternalSettings.batch_inserter_batch_size, 2).build());
long denseNode = inserter.createNode(null);
// when
for (int i = 0; i < denseNodeThreshold * 2; i++) {
inserter.createRelationship(denseNode, inserter.createNode(null), relTypeArray[0], null);
}
// then
GraphDatabaseAPI db = switchToEmbeddedGraphDatabaseService(inserter, denseNodeThreshold);
try (Transaction tx = db.beginTx()) {
assertThat(tx.getNodeById(denseNode).getDegree(relTypeArray[0], Direction.OUTGOING)).isEqualTo(denseNodeThreshold * 2);
}
managementService.shutdown();
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfViolated.
@ParameterizedTest
@MethodSource("params")
void uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfViolated(int denseNodeThreshold) throws Exception {
// Given
Label label = label("Foo");
String property = "Bar";
String value = "Baz";
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
// When
inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
inserter.createNode(Collections.singletonMap(property, value), label);
inserter.createNode(Collections.singletonMap(property, value), label);
// Then
GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(inserter, denseNodeThreshold);
try (Transaction tx = db.beginTx()) {
var schema = tx.schema();
IndexDefinition index = schema.getIndexes(label).iterator().next();
String indexFailure = schema.getIndexFailure(index);
assertThat(indexFailure).contains("IndexEntryConflictException");
assertThat(indexFailure).contains(value);
tx.commit();
} finally {
managementService.shutdown();
}
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertIndexTest method batchInserterShouldUseConfiguredIndexProvider.
@ParameterizedTest
@EnumSource(SchemaIndex.class)
void batchInserterShouldUseConfiguredIndexProvider(SchemaIndex schemaIndex) throws Exception {
configure(schemaIndex);
BatchInserter inserter = newBatchInserter();
inserter.createDeferredSchemaIndex(LABEL_ONE).on("key").create();
inserter.shutdown();
GraphDatabaseService db = startGraphDatabaseServiceAndAwaitIndexes();
try (Transaction tx = db.beginTx()) {
KernelTransaction kernelTransaction = ((InternalTransaction) tx).kernelTransaction();
TokenRead tokenRead = kernelTransaction.tokenRead();
SchemaRead schemaRead = kernelTransaction.schemaRead();
int labelId = tokenRead.nodeLabel(LABEL_ONE.name());
int propertyId = tokenRead.propertyKey("key");
IndexDescriptor index = single(schemaRead.index(SchemaDescriptor.forLabel(labelId, propertyId)));
assertTrue(schemaIndex.providerName().contains(index.getIndexProvider().getKey()), unexpectedIndexProviderMessage(index));
assertTrue(schemaIndex.providerName().contains(index.getIndexProvider().getVersion()), unexpectedIndexProviderMessage(index));
tx.commit();
}
}
Aggregations