use of org.elasticsearch.index.mapper.MapperService in project crate by crate.
the class InternalEngineTests method testLuceneSnapshotRefreshesOnlyOnce.
@Test
public void testLuceneSnapshotRefreshesOnlyOnce() throws Exception {
final MapperService mapperService = createMapperService("test");
final long maxSeqNo = randomLongBetween(10, 50);
final AtomicLong refreshCounter = new AtomicLong();
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(IndexMetadata.builder(defaultSettings.getIndexMetadata()).settings(Settings.builder().put(defaultSettings.getSettings()).put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)).build());
try (Store store = createStore();
InternalEngine engine = createEngine(config(indexSettings, store, createTempDir(), newMergePolicy(), null, new ReferenceManager.RefreshListener() {
@Override
public void beforeRefresh() {
refreshCounter.incrementAndGet();
}
@Override
public void afterRefresh(boolean didRefresh) {
}
}, () -> SequenceNumbers.NO_OPS_PERFORMED))) {
for (long seqNo = 0; seqNo <= maxSeqNo; seqNo++) {
final ParsedDocument doc = testParsedDocument("id_" + seqNo, null, testDocumentWithTextField("test"), new BytesArray("{}".getBytes(Charset.defaultCharset())), null);
engine.index(replicaIndexForDoc(doc, 1, seqNo, randomBoolean()));
}
final long initialRefreshCount = refreshCounter.get();
final Thread[] snapshotThreads = new Thread[between(1, 3)];
CountDownLatch latch = new CountDownLatch(1);
for (int i = 0; i < snapshotThreads.length; i++) {
final long min = randomLongBetween(0, maxSeqNo - 5);
final long max = randomLongBetween(min, maxSeqNo);
snapshotThreads[i] = new Thread(new AbstractRunnable() {
@Override
public void onFailure(Exception e) {
throw new AssertionError(e);
}
@Override
protected void doRun() throws Exception {
latch.await();
Translog.Snapshot changes = engine.newChangesSnapshot("test", mapperService, min, max, true);
changes.close();
}
});
snapshotThreads[i].start();
}
latch.countDown();
for (Thread thread : snapshotThreads) {
thread.join();
}
assertThat(refreshCounter.get(), equalTo(initialRefreshCount + 1L));
assertThat(engine.lastRefreshedCheckpoint(), equalTo(maxSeqNo));
}
}
Aggregations