Search in sources :

Example 21 with LongSupplier

use of java.util.function.LongSupplier in project elasticsearch by elastic.

the class InternalEngineTests method testOutOfOrderSequenceNumbersWithVersionConflict.

public void testOutOfOrderSequenceNumbersWithVersionConflict() throws IOException {
    final List<Engine.Operation> operations = new ArrayList<>();
    final int numberOfOperations = randomIntBetween(16, 32);
    final Document document = testDocumentWithTextField();
    final AtomicLong sequenceNumber = new AtomicLong();
    final Engine.Operation.Origin origin = randomFrom(LOCAL_TRANSLOG_RECOVERY, PEER_RECOVERY, PRIMARY, REPLICA);
    final LongSupplier sequenceNumberSupplier = origin == PRIMARY ? () -> SequenceNumbersService.UNASSIGNED_SEQ_NO : sequenceNumber::getAndIncrement;
    document.add(new Field(SourceFieldMapper.NAME, BytesReference.toBytes(B_1), SourceFieldMapper.Defaults.FIELD_TYPE));
    final ParsedDocument doc = testParsedDocument("1", "test", null, document, B_1, null);
    final Term uid = newUid(doc);
    for (int i = 0; i < numberOfOperations; i++) {
        if (randomBoolean()) {
            final Engine.Index index = new Engine.Index(uid, doc, sequenceNumberSupplier.getAsLong(), 1, i, VersionType.EXTERNAL, origin, System.nanoTime(), IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
            operations.add(index);
        } else {
            final Engine.Delete delete = new Engine.Delete("test", "1", uid, sequenceNumberSupplier.getAsLong(), 1, i, VersionType.EXTERNAL, origin, System.nanoTime());
            operations.add(delete);
        }
    }
    final boolean exists = operations.get(operations.size() - 1) instanceof Engine.Index;
    Randomness.shuffle(operations);
    for (final Engine.Operation operation : operations) {
        if (operation instanceof Engine.Index) {
            engine.index((Engine.Index) operation);
        } else {
            engine.delete((Engine.Delete) operation);
        }
    }
    final long expectedLocalCheckpoint;
    if (origin == PRIMARY) {
        // we can only advance as far as the number of operations that did not conflict
        int count = 0;
        // each time the version increments as we walk the list, that counts as a successful operation
        long version = -1;
        for (int i = 0; i < numberOfOperations; i++) {
            if (operations.get(i).version() >= version) {
                count++;
                version = operations.get(i).version();
            }
        }
        // sequence numbers start at zero, so the expected local checkpoint is the number of successful operations minus one
        expectedLocalCheckpoint = count - 1;
    } else {
        expectedLocalCheckpoint = numberOfOperations - 1;
    }
    assertThat(engine.seqNoService().getLocalCheckpoint(), equalTo(expectedLocalCheckpoint));
    try (Engine.GetResult result = engine.get(new Engine.Get(true, uid))) {
        assertThat(result.exists(), equalTo(exists));
    }
}
Also used : ArrayList(java.util.ArrayList) Index(org.elasticsearch.index.Index) Term(org.apache.lucene.index.Term) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) Document(org.elasticsearch.index.mapper.ParseContext.Document) LongPoint(org.apache.lucene.document.LongPoint) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) TextField(org.apache.lucene.document.TextField) IndexableField(org.apache.lucene.index.IndexableField) StoredField(org.apache.lucene.document.StoredField) Field(org.apache.lucene.document.Field) AtomicLong(java.util.concurrent.atomic.AtomicLong) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) LongSupplier(java.util.function.LongSupplier)

Example 22 with LongSupplier

use of java.util.function.LongSupplier in project elasticsearch by elastic.

the class DateMathParserTests method testOnlyCallsNowIfNecessary.

public void testOnlyCallsNowIfNecessary() {
    final AtomicBoolean called = new AtomicBoolean();
    final LongSupplier now = () -> {
        called.set(true);
        return 42L;
    };
    parser.parse("2014-11-18T14:27:32", now, false, null);
    assertFalse(called.get());
    parser.parse("now/d", now, false, null);
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongSupplier(java.util.function.LongSupplier)

Example 23 with LongSupplier

use of java.util.function.LongSupplier in project intellij-community by JetBrains.

the class Main method test.

private static void test(List<String> list) {
    long count = // and filter!
    list.stream().filter(s -> !s.isEmpty()).co < caret > unt();
    if (count > 10) {
        LongSupplier sup = () -> count * 2;
        long result = sup.get();
        System.out.println(result);
    }
}
Also used : List(java.util.List) LongSupplier(java.util.function.LongSupplier) LongSupplier(java.util.function.LongSupplier)

Example 24 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 25 with LongSupplier

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

the class BaseNormsFormatTestCase method testSparseLongRange.

public void testSparseLongRange() throws Exception {
    assumeTrue("Requires sparse norms support", codecSupportsSparsity());
    int iterations = atLeast(1);
    final Random r = random();
    for (int i = 0; i < iterations; i++) {
        doTestNormsVersusDocValues(random().nextDouble(), new LongSupplier() {

            @Override
            public long getAsLong() {
                return TestUtil.nextLong(r, Long.MIN_VALUE, Long.MAX_VALUE);
            }
        });
    }
}
Also used : Random(java.util.Random) LongSupplier(java.util.function.LongSupplier)

Aggregations

LongSupplier (java.util.function.LongSupplier)31 Random (java.util.Random)21 StoredField (org.apache.lucene.document.StoredField)3 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 Document (org.apache.lucene.document.Document)2 Field (org.apache.lucene.document.Field)2 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)2 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)2 DirectoryReader (org.apache.lucene.index.DirectoryReader)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 IndexableField (org.apache.lucene.index.IndexableField)2 LeafReader (org.apache.lucene.index.LeafReader)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)2 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)2 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)2 Directory (org.apache.lucene.store.Directory)2 Test (org.junit.Test)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1