use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertionIT method shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock.
@Test
void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception {
BatchInserter inserter = BatchInserters.inserter(databaseLayout, fileSystem);
long nodeId = inserter.createNode(Collections.emptyMap());
final Object finalValue1 = 87;
final Object finalValue2 = 3.14;
inserter.setNodeProperty(nodeId, "a", "some property value");
inserter.setNodeProperty(nodeId, "a", 42);
inserter.setNodeProperty(nodeId, "b", finalValue2);
inserter.setNodeProperty(nodeId, "a", finalValue2);
inserter.setNodeProperty(nodeId, "a", true);
inserter.setNodeProperty(nodeId, "a", finalValue1);
inserter.shutdown();
var db = getDatabase();
try (Transaction tx = db.beginTx()) {
assertThat(tx.getNodeById(nodeId).getProperty("a")).isEqualTo(finalValue1);
assertThat(tx.getNodeById(nodeId).getProperty("b")).isEqualTo(finalValue2);
}
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class FileSystemClosingBatchInserterTest method closeFileSystemOnShutdown.
@Test
void closeFileSystemOnShutdown() throws Exception {
BatchInserter batchInserter = mock(BatchInserter.class);
FileSystemAbstraction fileSystem = mock(FileSystemAbstraction.class);
FileSystemClosingBatchInserter inserter = new FileSystemClosingBatchInserter(batchInserter, fileSystem);
inserter.shutdown();
InOrder verificationOrder = inOrder(batchInserter, fileSystem);
verificationOrder.verify(batchInserter).shutdown();
verificationOrder.verify(fileSystem).close();
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.
@ParameterizedTest
@MethodSource("params")
void shouldCreateConsistentUniquenessConstraint(int denseNodeThreshold) throws Exception {
// given
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
// when
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
// then
GraphDatabaseAPI graphdb = switchToEmbeddedGraphDatabaseService(inserter, denseNodeThreshold);
try {
NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
SchemaStore store = neoStores.getSchemaStore();
TokenHolders tokenHolders = graphdb.getDependencyResolver().resolveDependency(TokenHolders.class);
SchemaRuleAccess schemaRuleAccess = SchemaRuleAccess.getSchemaRuleAccess(store, tokenHolders, () -> KernelVersion.LATEST);
List<Long> inUse = new ArrayList<>();
SchemaRecord record = store.newRecord();
for (long i = 1, high = store.getHighestPossibleIdInUse(NULL); i <= high; i++) {
store.getRecord(i, record, RecordLoad.FORCE, NULL);
if (record.inUse()) {
inUse.add(i);
}
}
assertEquals(2, inUse.size(), "records in use");
SchemaRule rule0 = schemaRuleAccess.loadSingleSchemaRule(inUse.get(0), NULL);
SchemaRule rule1 = schemaRuleAccess.loadSingleSchemaRule(inUse.get(1), NULL);
IndexDescriptor indexRule;
ConstraintDescriptor constraint;
if (rule0 instanceof IndexDescriptor) {
indexRule = (IndexDescriptor) rule0;
constraint = (ConstraintDescriptor) rule1;
} else {
constraint = (ConstraintDescriptor) rule0;
indexRule = (IndexDescriptor) rule1;
}
OptionalLong owningConstraintId = indexRule.getOwningConstraintId();
assertTrue(owningConstraintId.isPresent(), "index should have owning constraint");
assertEquals(constraint.getId(), owningConstraintId.getAsLong(), "index should reference constraint");
assertEquals(indexRule.getId(), constraint.asIndexBackedConstraint().ownedIndexId(), "constraint should reference index");
} finally {
managementService.shutdown();
}
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateDeferredUniquenessConstraintInEmptyDatabase.
@ParameterizedTest
@MethodSource("params")
void shouldCreateDeferredUniquenessConstraintInEmptyDatabase(int denseNodeThreshold) throws Exception {
// GIVEN
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
// WHEN
ConstraintDefinition definition = inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
// THEN
assertEquals("Hacker", definition.getLabel().name());
assertEquals(ConstraintType.UNIQUENESS, definition.getConstraintType());
assertEquals(asSet("handle"), Iterables.asSet(definition.getPropertyKeys()));
inserter.shutdown();
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldRepopulatePreexistingIndexed.
@ParameterizedTest
@MethodSource("params")
void shouldRepopulatePreexistingIndexed(int denseNodeThreshold) throws Throwable {
// GIVEN
long jakewins = dbWithIndexAndSingleIndexedNode(denseNodeThreshold);
IndexPopulator populator = mock(IndexPopulator.class);
IndexProvider provider = mock(IndexProvider.class);
IndexAccessor accessor = mock(IndexAccessor.class);
when(provider.getProviderDescriptor()).thenReturn(DESCRIPTOR);
when(provider.completeConfiguration(any(IndexDescriptor.class))).then(inv -> inv.getArgument(0));
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);
BatchInserter inserter = newBatchInserterWithIndexProvider(singleInstanceIndexProviderFactory(KEY, provider), provider.getProviderDescriptor(), denseNodeThreshold);
long boggle = inserter.createNode(map("handle", "b0ggl3"), 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(jakewins, internalIndex.schema(), Values.of("Jakewins"))) && c.contains(add(boggle, internalIndex.schema(), Values.of("b0ggl3")))), any(CursorContext.class));
verify(populator).verifyDeferredConstraints(any(NodePropertyAccessor.class));
verify(populator).close(eq(true), any());
verify(provider).stop();
verify(provider).shutdown();
}
Aggregations