use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method sampleIncludedUpdates.
@Test
void sampleIncludedUpdates() {
LabelSchemaDescriptor schemaDescriptor = forLabel(1, 1);
populator = newPopulator();
List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, schemaDescriptor, "foo"), add(2, schemaDescriptor, "bar"), add(3, schemaDescriptor, "baz"), add(4, schemaDescriptor, "qux"));
updates.forEach(populator::includeSample);
IndexSample sample = populator.sample(NULL);
assertEquals(new IndexSample(4, 4, 4), sample);
}
use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.
the class NonUniqueDatabaseIndexSamplerTest method nonUniqueIndexSampling.
@Test
void nonUniqueIndexSampling() throws Exception {
Terms aTerms = getTerms("a", 1);
Terms idTerms = getTerms("id", 2);
Terms bTerms = getTerms("b", 3);
Map<String, Terms> fieldTermsMap = MapUtil.genericMap("0string", aTerms, "id", idTerms, "0array", bTerms);
IndexReaderStub indexReader = new IndexReaderStub(new SamplingFields(fieldTermsMap));
indexReader.setElements(new String[4]);
when(indexSearcher.getIndexReader()).thenReturn(indexReader);
assertEquals(new IndexSample(4, 2, 4), createSampler().sampleIndex(NULL));
}
use of org.neo4j.kernel.api.index.IndexSample 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();
}
use of org.neo4j.kernel.api.index.IndexSample 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.kernel.api.index.IndexSample in project neo4j by neo4j.
the class NonUniqueDatabaseIndexPopulatorTest method sampleIncludedUpdatesWithDuplicates.
@Test
void sampleIncludedUpdatesWithDuplicates() {
populator = newPopulator();
List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, labelSchemaDescriptor, "foo"), add(2, labelSchemaDescriptor, "bar"), add(3, labelSchemaDescriptor, "foo"));
populator.add(updates, NULL);
IndexSample sample = populator.sample(NULL);
assertEquals(new IndexSample(3, 2, 3), sample);
}
Aggregations