Search in sources :

Example 46 with LongSupplier

use of java.util.function.LongSupplier in project lucene-solr by apache.

the class TestLucene70DocValuesFormat method doTestSparseNumericBlocksOfVariousBitsPerValue.

private void doTestSparseNumericBlocksOfVariousBitsPerValue(double density) throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    conf.setMaxBufferedDocs(atLeast(Lucene70DocValuesFormat.NUMERIC_BLOCK_SIZE));
    conf.setRAMBufferSizeMB(-1);
    conf.setMergePolicy(newLogMergePolicy(random().nextBoolean()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    Field storedField = newStringField("stored", "", Field.Store.YES);
    Field dvField = new NumericDocValuesField("dv", 0);
    doc.add(storedField);
    doc.add(dvField);
    final int numDocs = atLeast(Lucene70DocValuesFormat.NUMERIC_BLOCK_SIZE * 3);
    final LongSupplier longs = blocksOfVariousBPV();
    for (int i = 0; i < numDocs; i++) {
        if (random().nextDouble() > density) {
            writer.addDocument(new Document());
            continue;
        }
        long value = longs.getAsLong();
        storedField.setStringValue(Long.toString(value));
        dvField.setLongValue(value);
        writer.addDocument(doc);
    }
    writer.forceMerge(1);
    writer.close();
    // compare
    DirectoryReader ir = DirectoryReader.open(dir);
    TestUtil.checkReader(ir);
    for (LeafReaderContext context : ir.leaves()) {
        LeafReader r = context.reader();
        NumericDocValues docValues = DocValues.getNumeric(r, "dv");
        docValues.nextDoc();
        for (int i = 0; i < r.maxDoc(); i++) {
            String storedValue = r.document(i).get("stored");
            if (storedValue == null) {
                assertTrue(docValues.docID() > i);
            } else {
                assertEquals(i, docValues.docID());
                assertEquals(Long.parseLong(storedValue), docValues.longValue());
                docValues.nextDoc();
            }
        }
        assertEquals(DocIdSetIterator.NO_MORE_DOCS, docValues.docID());
    }
    ir.close();
    dir.close();
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) NumericDocValues(org.apache.lucene.index.NumericDocValues) LeafReader(org.apache.lucene.index.LeafReader) DirectoryReader(org.apache.lucene.index.DirectoryReader) Document(org.apache.lucene.document.Document) IndexableField(org.apache.lucene.index.IndexableField) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) StoredField(org.apache.lucene.document.StoredField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) BinaryDocValuesField(org.apache.lucene.document.BinaryDocValuesField) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) StringField(org.apache.lucene.document.StringField) Field(org.apache.lucene.document.Field) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LongSupplier(java.util.function.LongSupplier) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 47 with LongSupplier

use of java.util.function.LongSupplier in project lucene-solr by apache.

the class TestLucene70DocValuesFormat method doTestSortedNumericBlocksOfVariousBitsPerValue.

private void doTestSortedNumericBlocksOfVariousBitsPerValue(LongSupplier counts) throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    conf.setMaxBufferedDocs(atLeast(Lucene70DocValuesFormat.NUMERIC_BLOCK_SIZE));
    conf.setRAMBufferSizeMB(-1);
    conf.setMergePolicy(newLogMergePolicy(random().nextBoolean()));
    IndexWriter writer = new IndexWriter(dir, conf);
    final int numDocs = atLeast(Lucene70DocValuesFormat.NUMERIC_BLOCK_SIZE * 3);
    final LongSupplier values = blocksOfVariousBPV();
    for (int i = 0; i < numDocs; i++) {
        Document doc = new Document();
        int valueCount = (int) counts.getAsLong();
        long[] valueArray = new long[valueCount];
        for (int j = 0; j < valueCount; j++) {
            long value = values.getAsLong();
            valueArray[j] = value;
            doc.add(new SortedNumericDocValuesField("dv", value));
        }
        Arrays.sort(valueArray);
        for (int j = 0; j < valueCount; j++) {
            doc.add(new StoredField("stored", Long.toString(valueArray[j])));
        }
        writer.addDocument(doc);
        if (random().nextInt(31) == 0) {
            writer.commit();
        }
    }
    writer.forceMerge(1);
    writer.close();
    // compare
    DirectoryReader ir = DirectoryReader.open(dir);
    TestUtil.checkReader(ir);
    for (LeafReaderContext context : ir.leaves()) {
        LeafReader r = context.reader();
        SortedNumericDocValues docValues = DocValues.getSortedNumeric(r, "dv");
        for (int i = 0; i < r.maxDoc(); i++) {
            if (i > docValues.docID()) {
                docValues.nextDoc();
            }
            String[] expected = r.document(i).getValues("stored");
            if (i < docValues.docID()) {
                assertEquals(0, expected.length);
            } else {
                String[] actual = new String[docValues.docValueCount()];
                for (int j = 0; j < actual.length; j++) {
                    actual[j] = Long.toString(docValues.nextValue());
                }
                assertArrayEquals(expected, actual);
            }
        }
    }
    ir.close();
    dir.close();
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) LeafReader(org.apache.lucene.index.LeafReader) DirectoryReader(org.apache.lucene.index.DirectoryReader) Document(org.apache.lucene.document.Document) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) StoredField(org.apache.lucene.document.StoredField) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LongSupplier(java.util.function.LongSupplier) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 48 with LongSupplier

use of java.util.function.LongSupplier in project lucene-solr by apache.

the class BaseDocValuesFormatTestCase method doTestGCDCompression.

private void doTestGCDCompression(double density) throws Exception {
    int numIterations = atLeast(1);
    for (int i = 0; i < numIterations; i++) {
        final long min = -(((long) random().nextInt(1 << 30)) << 32);
        final long mul = random().nextInt() & 0xFFFFFFFFL;
        final LongSupplier longs = () -> {
            return min + mul * random().nextInt(1 << 20);
        };
        doTestNumericsVsStoredFields(density, longs);
    }
}
Also used : LongSupplier(java.util.function.LongSupplier)

Example 49 with LongSupplier

use of java.util.function.LongSupplier in project atlasdb by palantir.

the class AbstractBackgroundSweeperIntegrationTest method setup.

@Before
public void setup() {
    TimestampService tsService = new InMemoryTimestampService();
    kvs = SweepStatsKeyValueService.create(getKeyValueService(), tsService, () -> AtlasDbConstants.DEFAULT_SWEEP_WRITE_THRESHOLD, () -> AtlasDbConstants.DEFAULT_SWEEP_WRITE_SIZE_THRESHOLD);
    SweepStrategyManager ssm = SweepStrategyManagers.createDefault(kvs);
    txService = TransactionServices.createTransactionService(kvs);
    txManager = SweepTestUtils.setupTxManager(kvs, tsService, ssm, txService);
    LongSupplier tsSupplier = sweepTimestamp::get;
    PersistentLockManager persistentLockManager = new PersistentLockManager(SweepTestUtils.getPersistentLockService(kvs), AtlasDbConstants.DEFAULT_SWEEP_PERSISTENT_LOCK_WAIT_MILLIS);
    CellsSweeper cellsSweeper = new CellsSweeper(txManager, kvs, persistentLockManager, ImmutableList.of());
    SweepTaskRunner sweepRunner = new SweepTaskRunner(kvs, tsSupplier, tsSupplier, txService, ssm, cellsSweeper);
    SweepMetricsManager sweepMetricsManager = new SweepMetricsManager();
    specificTableSweeper = SpecificTableSweeper.create(txManager, kvs, sweepRunner, SweepTableFactory.of(), new NoOpBackgroundSweeperPerformanceLogger(), sweepMetricsManager, false);
    sweepBatchConfigSource = AdjustableSweepBatchConfigSource.create(() -> sweepBatchConfig);
    backgroundSweeper = BackgroundSweeperImpl.create(sweepBatchConfigSource, // sweepEnabled
    () -> true, // sweepPauseMillis
    () -> 10L, persistentLockManager, specificTableSweeper);
}
Also used : SweepStrategyManager(com.palantir.atlasdb.transaction.impl.SweepStrategyManager) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) LongSupplier(java.util.function.LongSupplier) SweepMetricsManager(com.palantir.atlasdb.sweep.metrics.SweepMetricsManager) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) TimestampService(com.palantir.timestamp.TimestampService) Before(org.junit.Before)

Example 50 with LongSupplier

use of java.util.function.LongSupplier in project neo4j by neo4j.

the class IdContextFactoryBuilderTest method createContextWithCustomIdGeneratorFactoryWhenProvided.

@Test
void createContextWithCustomIdGeneratorFactoryWhenProvided() throws IOException {
    IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
    Config config = defaults();
    IdContextFactory contextFactory = IdContextFactoryBuilder.of(fs, jobScheduler, config, PageCacheTracer.NULL).withIdGenerationFactoryProvider(any -> idGeneratorFactory).build();
    DatabaseIdContext idContext = contextFactory.createIdContext(databaseIdRepository.getByName("database").get());
    IdGeneratorFactory bufferedGeneratorFactory = idContext.getIdGeneratorFactory();
    assertThat(idContext.getIdController()).isInstanceOf(BufferedIdController.class);
    assertThat(bufferedGeneratorFactory).isInstanceOf(BufferingIdGeneratorFactory.class);
    ((BufferingIdGeneratorFactory) bufferedGeneratorFactory).initialize(() -> mock(KernelTransactionsSnapshot.class));
    Path file = testDirectory.file("a");
    IdType idType = IdType.NODE;
    LongSupplier highIdSupplier = () -> 0;
    int maxId = 100;
    idGeneratorFactory.open(pageCache, file, idType, highIdSupplier, maxId, writable(), config, NULL, immutable.empty());
    verify(idGeneratorFactory).open(pageCache, file, idType, highIdSupplier, maxId, writable(), config, NULL, immutable.empty());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) LongSupplier(java.util.function.LongSupplier) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) Config.defaults(org.neo4j.configuration.Config.defaults) DatabaseIdFactory.from(org.neo4j.kernel.database.DatabaseIdFactory.from) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Function(java.util.function.Function) BufferedIdController(org.neo4j.internal.id.BufferedIdController) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) Inject(org.neo4j.test.extension.Inject) IdGenerator(org.neo4j.internal.id.IdGenerator) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) Path(java.nio.file.Path) DatabaseIdRepository(org.neo4j.kernel.database.DatabaseIdRepository) PageCache(org.neo4j.io.pagecache.PageCache) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) UUID(java.util.UUID) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) IdType(org.neo4j.internal.id.IdType) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) KernelTransactionsSnapshot(org.neo4j.kernel.impl.api.KernelTransactionsSnapshot) Mockito.mock(org.mockito.Mockito.mock) Path(java.nio.file.Path) Config(org.neo4j.configuration.Config) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) LongSupplier(java.util.function.LongSupplier) KernelTransactionsSnapshot(org.neo4j.kernel.impl.api.KernelTransactionsSnapshot) IdType(org.neo4j.internal.id.IdType) Test(org.junit.jupiter.api.Test)

Aggregations

LongSupplier (java.util.function.LongSupplier)59 Random (java.util.Random)21 Test (org.junit.Test)9 IOException (java.io.IOException)7 Path (java.nio.file.Path)7 ArrayList (java.util.ArrayList)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)5 BytesArray (org.elasticsearch.common.bytes.BytesArray)5 Tuple (io.crate.common.collections.Tuple)4 Streams (io.crate.common.io.Streams)4 TimeValue (io.crate.common.unit.TimeValue)4 List (java.util.List)4 Predicate (java.util.function.Predicate)4 Supplier (java.util.function.Supplier)4 StoredField (org.apache.lucene.document.StoredField)4 Version (org.elasticsearch.Version)4 NoopCircuitBreaker (org.elasticsearch.common.breaker.NoopCircuitBreaker)4 BytesReference (org.elasticsearch.common.bytes.BytesReference)4