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);
}
Aggregations