use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateDeferredSchemaIndexesInEmptyDatabase.
@ParameterizedTest
@MethodSource("params")
void shouldCreateDeferredSchemaIndexesInEmptyDatabase(int denseNodeThreshold) throws Exception {
// GIVEN
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
// WHEN
IndexDefinition definition = inserter.createDeferredSchemaIndex(label("Hacker")).on("handle").create();
// THEN
assertEquals("Hacker", single(definition.getLabels()).name());
assertEquals(asCollection(iterator("handle")), Iterables.asCollection(definition.getPropertyKeys()));
inserter.shutdown();
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldRunIndexPopulationJobAtShutdown.
@ParameterizedTest
@MethodSource("params")
void shouldRunIndexPopulationJobAtShutdown(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.createDeferredSchemaIndex(label("Hacker")).on("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, internalIndex.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 messagesLogGetsClosed.
@Test
void messagesLogGetsClosed() throws IOException {
Config config = Config.newBuilder().set(preallocate_logical_logs, false).set(neo4j_home, testDirectory.homePath()).build();
BatchInserter inserter = BatchInserters.inserter(databaseLayout, fs, config);
inserter.shutdown();
Files.delete(databaseLayout.getNeo4jLayout().homeDirectory().resolve(INTERNAL_LOG_FILE));
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldBuildCorrectCountsStoreOnIncrementalImport.
@Test
void shouldBuildCorrectCountsStoreOnIncrementalImport() throws Exception {
// given
Label label = Label.label("Person");
int denseNodeThreshold = dense_node_threshold.defaultValue();
for (int r = 0; r < 3; r++) {
// when
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
try {
for (int i = 0; i < 100; i++) {
inserter.createNode(null, label);
}
} finally {
inserter.shutdown();
}
// then
try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fs, RecoveryCleanupWorkCollector.immediate(), new CountsBuilder() {
@Override
public void initialize(CountsAccessor.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
throw new UnsupportedOperationException("Should not be required");
}
@Override
public long lastCommittedTxId() {
return TransactionIdStore.BASE_TX_ID;
}
}, readOnly(), PageCacheTracer.NULL, GBPTreeCountsStore.NO_MONITOR, databaseLayout.getDatabaseName(), 1000)) {
countsStore.start(NULL, INSTANCE);
assertEquals((r + 1) * 100, countsStore.nodeCount(0, NULL));
}
}
}
use of org.neo4j.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method dbWithIndexAndSingleIndexedNode.
private long dbWithIndexAndSingleIndexedNode(int denseNodeThreshold) throws Exception {
IndexPopulator populator = mock(IndexPopulator.class);
IndexProvider provider = mock(IndexProvider.class);
when(provider.getProviderDescriptor()).thenReturn(DESCRIPTOR);
when(provider.getPopulator(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class))).thenReturn(populator);
when(provider.completeConfiguration(any(IndexDescriptor.class))).then(inv -> inv.getArgument(0));
BatchInserter inserter = newBatchInserterWithIndexProvider(singleInstanceIndexProviderFactory(KEY, provider), provider.getProviderDescriptor(), denseNodeThreshold);
inserter.createDeferredSchemaIndex(label("Hacker")).on("handle").create();
long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
inserter.shutdown();
return nodeId;
}
Aggregations