Search in sources :

Example 16 with ByteArrayDataOutput

use of org.apache.lucene.store.ByteArrayDataOutput in project crate by crate.

the class TranslogDeletionPolicyTests method createReadersAndWriter.

private Tuple<List<TranslogReader>, TranslogWriter> createReadersAndWriter(final long now) throws IOException {
    final Path tempDir = createTempDir();
    Files.createFile(tempDir.resolve(Translog.CHECKPOINT_FILE_NAME));
    TranslogWriter writer = null;
    List<TranslogReader> readers = new ArrayList<>();
    final int numberOfReaders = randomIntBetween(0, 10);
    final String translogUUID = UUIDs.randomBase64UUID(random());
    for (long gen = 1; gen <= numberOfReaders + 1; gen++) {
        if (writer != null) {
            final TranslogReader reader = Mockito.spy(writer.closeIntoReader());
            Mockito.doReturn(writer.getLastModifiedTime()).when(reader).getLastModifiedTime();
            readers.add(reader);
        }
        writer = TranslogWriter.create(new ShardId("index", "uuid", 0), translogUUID, gen, tempDir.resolve(Translog.getFilename(gen)), FileChannel::open, TranslogConfig.DEFAULT_BUFFER_SIZE, 1L, 1L, () -> 1L, () -> 1L, randomNonNegativeLong(), new TragicExceptionHolder(), seqNo -> {
        });
        writer = Mockito.spy(writer);
        Mockito.doReturn(now - (numberOfReaders - gen + 1) * 1000).when(writer).getLastModifiedTime();
        byte[] bytes = new byte[4];
        ByteArrayDataOutput out = new ByteArrayDataOutput(bytes);
        for (int ops = randomIntBetween(0, 20); ops > 0; ops--) {
            out.reset(bytes);
            out.writeInt(ops);
            writer.add(ReleasableBytesReference.wrap(new BytesArray(bytes)), ops);
        }
    }
    return new Tuple<>(readers, writer);
}
Also used : Path(java.nio.file.Path) ShardId(org.elasticsearch.index.shard.ShardId) Tuple(io.crate.common.collections.Tuple) Files(java.nio.file.Files) ByteArrayDataOutput(org.apache.lucene.store.ByteArrayDataOutput) IOUtils(io.crate.common.io.IOUtils) UUIDs(org.elasticsearch.common.UUIDs) IOException(java.io.IOException) Test(org.junit.Test) Math.min(java.lang.Math.min) ArrayList(java.util.ArrayList) BytesArray(org.elasticsearch.common.bytes.BytesArray) Mockito(org.mockito.Mockito) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ReleasableBytesReference(org.elasticsearch.common.bytes.ReleasableBytesReference) ESTestCase(org.elasticsearch.test.ESTestCase) FileChannel(java.nio.channels.FileChannel) Path(java.nio.file.Path) Releasable(org.elasticsearch.common.lease.Releasable) BytesArray(org.elasticsearch.common.bytes.BytesArray) ArrayList(java.util.ArrayList) ShardId(org.elasticsearch.index.shard.ShardId) ByteArrayDataOutput(org.apache.lucene.store.ByteArrayDataOutput) Tuple(io.crate.common.collections.Tuple)

Aggregations

ByteArrayDataOutput (org.apache.lucene.store.ByteArrayDataOutput)16 ByteArrayDataInput (org.apache.lucene.store.ByteArrayDataInput)8 BytesRef (org.apache.lucene.util.BytesRef)5 Random (java.util.Random)4 OfflineSorter (org.apache.lucene.util.OfflineSorter)4 HashSet (java.util.HashSet)3 IntPoint (org.apache.lucene.document.IntPoint)3 IndexOutput (org.apache.lucene.store.IndexOutput)3 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)3 BytesArray (org.elasticsearch.common.bytes.BytesArray)3 ByteBuffer (java.nio.ByteBuffer)2 TokenStreamToAutomaton (org.apache.lucene.analysis.TokenStreamToAutomaton)2 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)2 IntsRef (org.apache.lucene.util.IntsRef)2 IntsRefBuilder (org.apache.lucene.util.IntsRefBuilder)2 LimitedFiniteStringsIterator (org.apache.lucene.util.automaton.LimitedFiniteStringsIterator)2 Builder (org.apache.lucene.util.fst.Builder)2 PairOutputs (org.apache.lucene.util.fst.PairOutputs)2 Pair (org.apache.lucene.util.fst.PairOutputs.Pair)2 Tuple (io.crate.common.collections.Tuple)1